# Detecting and navigating in a matrix

**URL:** <https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887>\
**Category:** OpenMV Boards\
**Created:** [August 18, 2020, 6:55pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887 "2020-08-18T18:55:26Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Angel](https://forums.openmv.io/u/Angel)\
**Post date:** [August 18, 2020, 6:55pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/1 "2020-08-18T18:55:26Z")

</div>

Hello!  
I’m building a robot to move in a well defined matrix by following perpendicular lines.  
I can navigate very reliable over one line using **get\_regression** , but I also need to detect when a perpendicular line is coming to localize and turn the robot on the correct line. I’ve attached a picture of this.  
Can anyone tell me what would the most efficient way to detect these two lines?

I’m thinking of mixing **get\_regression** for the navigation and **find\_lines** for the perpendicular lines, but **find\_lines** seems slow and not as robust as **get\_regression**.

Thanks!!!

 ![matrix move.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/92bb225c98cbab11ae34c4a16a226b0e9a4cb31e.jpeg)

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 18, 2020, 7:42pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/2 "2020-08-18T19:42:11Z")

</div>

Use find\_line\_segments and search only a small window in the front of the robot.

---

<div class="post-metadata">

**Author:** ![Angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Angel](https://forums.openmv.io/u/Angel)\
**Post date:** [August 18, 2020, 9:48pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/3 "2020-08-18T21:48:43Z")

</div>

Hey, thanks for the reply and the idea! I just tried it and it stills seems to slow down the processing by almost half.  
I’m running about 73 fps at 80x60 and once I do find\_line segments it goes down to 37, but my biggest concern is that it’s not as stable as get\_regression.  
Am I doing anything wrong here?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 18, 2020, 10:46pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/4 "2020-08-18T22:46:08Z")

</div>

No, that’s to be expected. You can also just use get\_regression again with a different roi that’s horizontal.

---

<div class="post-metadata">

**Author:** ![Angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Angel](https://forums.openmv.io/u/Angel)\
**Post date:** [August 19, 2020, 8:17am UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/5 "2020-08-19T08:17:25Z")

</div>

Oh, I didn’t know I could run it again!  
Sorry, I’m very new to OpenMV!  
It is, indeed, much faster and definitely more robust, but unfortunately it gets too affected by the main vertical line, so I’m starting to think I’m just not following the right strategy.  
I guess I should have sent an image of what the camera feed looks like, so here I’m showing both lines with their ROIs.  
Any advice on a new strategy or idea on how to improve that detection?  
Again, Thank you soooo much for your help here! this is truly an amazing product!  
 ![second get_regression.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/f7771867973e5892c9ae4b61d790c3362c3a8bde.jpeg)

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 19, 2020, 4:46pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/6 "2020-08-19T16:46:04Z")

</div>

Use the roation\_corr() method with the bird-eye-view example to project the image as a top down transform. This will make the lines appear to be straighter.

Second, use the robust argument for the robust version of the linear regression. It’s slower but then that issue will go away.

---

<div class="post-metadata">

**Author:** ![Angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Angel](https://forums.openmv.io/u/Angel)\
**Post date:** [August 24, 2020, 11:49am UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/7 "2020-08-24T11:49:06Z")

</div>

Hey,  
Thanks for the advise on the rotation\_corr. unfortunately the camera is too close to the floor, so the correction creates too much black space. But your advise got me to play with lense\_corr and I got a much better looking image.

So I’ve been making some progress and improved the process quite a bit. I am basically just adjusting the ROI dynamically so my vertical line does not get tilted by incoming horizontal lines. That helped a lot, but I’m trying to follow what you said and do a new get\_regression on a more horizontal ROI and but it seems to be fairly biased to finding vertical lines only.  
Here is what I’m doing:

```python
GRAYSCALE_THRESHOLD = (200, 255)
MAG_THRESHOLD = 12
MAG_THRESHOLD_HORIZONTAL = 6

while True:
    clock.tick()
    print_string = ""

    img = sensor.snapshot().invert()	#I gotta find white lines over black, but I only have a white table with black lines now, so this trick helps
    img = img.lens_corr(strength = 1.5, zoom = 1.0)
    img.binary([GRAYSCALE_THRESHOLD])
    
    #Look for main vertical line
    line = img.get_regression([(255, 255)], roi=previousROIvertical, robust=True)

    if line and (line.magnitude() >= MAG_THRESHOLD):
        #Compute ROI for next frame
        if line.x1() < line.x2():
            previousROIvertical = (line.x1()-int(marginROI/2), 0, marginROI+line.x2()-line.x1(), 60)
        else:
            previousROIvertical = (line.x2()-int(marginROI/2), 0, marginROI+line.x1()-line.x2(), 60)

        #Draw ROI
        img.draw_rectangle(previousROIvertical, color=80)
        img.draw_line(line.line(), color=127)

        print_string = "Line Ok: %d - line t: %d, r: %d" % (line.magnitude(), line.theta(), line.rho())

    elif line and (line.magnitude() < MAG_THRESHOLD):
        print_string = "Not a good line: %d" % (line.magnitude())
        previousROIvertical = (0,0,80,60)	#Reset ROI so we start looking in the whole area

    else:
        print_string = "Line Lost"
        previousROIvertical = (0,0,80,60) #Reset ROI so we start looking in the whole area

    #Look for horizontal lines at the top (0,0,80,20)
    lineH = img.get_regression([(255, 255)], roi=(0,0,80,20), robust=True)
    img.draw_rectangle((0,0,80,20), color=80)	#Draw ROI for horizontal line

    if lineH and (lineH.magnitude() >= MAG_THRESHOLD_HORIZONTAL):
        img.draw_line(lineH.line(), color=127)
        print_string = print_string + " | LineH Ok: %d - line t: %d, r: %d" % (lineH.magnitude(), lineH.theta(), lineH.rho())

    elif lineH and (lineH.magnitude() < MAG_THRESHOLD_HORIZONTAL):
        img.draw_line(lineH.line(), color=127)
        print_string = print_string + " | Not a good lineH: %d " % (lineH.magnitude())

    print("FPS %f, %s" % (clock.fps(), print_string))

```

Here is an example of what I’m getting.

 ![tilted h line.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/e2ac6be24bab115d81aab30f9a629a12ba944d8b.jpeg)  
I would expect the horizontal line to be follow a lot more the white line but I can’t get it to do it at all.

Maybe my strategy here is wrong and I should be using some other function?  
I have tried using find\_lines and find\_line\_segments but they produce much more unreliable results… or most likely, I haven’t got to set the parameters well enough, I guess.

Any idea how I could improve this detection?

Thanks!

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 24, 2020, 2:40pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/8 "2020-08-24T14:40:50Z")

</div>

Mmm, do this. Zero the roi at the top of the image. I.e draw a black rectangle in the area where you see the center of the vertical line at the top. This will remove that.

You should use the vertical line center to dynamically move the rectangle center.

---

<div class="post-metadata">

**Author:** ![Angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Angel](https://forums.openmv.io/u/Angel)\
**Post date:** [August 24, 2020, 4:38pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/9 "2020-08-24T16:38:42Z")

</div>

hmmm… interesting approach!  
So I’m doing

```python
        img.draw_rectangle((previousROIvertical[0]-3, previousROIvertical[1],previousROIvertical[2]+6, previousROIvertical[3]), color=0, fill=True)

```

Once I’m done with the vertical line, I’m making the rectangle a bit bigger than the ROI so I’m sure I don’t leave any white spots there.

Still, the get\_regression seems to like getting more vertical than horizontal lines.  
Is there anything I may be missing?  
Here are a couple screenshots.  
 ![zeroed v roi.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/71802aa634752e57c6a44c21940538fe9c8189dd.jpeg)  
 ![zeroed v roi2.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/71e2352c572935635ebf8e3ff11eaf4bdeb43145.jpeg)

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 24, 2020, 5:05pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/10 "2020-08-24T17:05:03Z")

</div>

That’s definitely not expected behavior.

Upload a pic of the unmodified image and I’ll fix your code.

---

<div class="post-metadata">

**Author:** ![Angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Angel](https://forums.openmv.io/u/Angel)\
**Post date:** [August 24, 2020, 5:38pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/11 "2020-08-24T17:38:49Z")

</div>

Thanks for your help!!!  
So, here is what I have:

```python
BINARY_VIEW = True
GRAYSCALE_THRESHOLD = (200, 255)
MAG_THRESHOLD = 12
MAG_THRESHOLD_HORIZONTAL = 5

import sensor, image, time, math, pyb

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQQVGA)
sensor.set_vflip(True)
sensor.set_hmirror(True)
sensor.set_auto_gain(True)
sensor.set_auto_exposure(True)
sensor.set_auto_whitebal(True)

sensor.skip_frames(time = 2000)
clock = time.clock()

uart = pyb.UART(3, 115200)

previousROIvertical = (0,0,80,60)
previousROIhorizontal = (0,0,80,60)

marginROI = 10
marginROIhorizontal = 3

while True:
    clock.tick()
    print_string = ""

    img = sensor.snapshot().invert()
    img = img.lens_corr(strength = 1.5, zoom = 1.0)

    if BINARY_VIEW:
        img.binary([GRAYSCALE_THRESHOLD])

    #VERTICAL LINE
    line = img.get_regression([(255, 255)], roi=previousROIvertical, robust=True)
        
    if line and (line.magnitude() >= MAG_THRESHOLD):
        #Compute ROI for next frame
        if line.x1() < line.x2():
            previousROIvertical = (line.x1()-int(marginROI/2), 0, marginROI+line.x2()-line.x1(), 60)
        else:
            previousROIvertical = (line.x2()-int(marginROI/2), 0, marginROI+line.x1()-line.x2(), 60)

        #Draw ROI
        img.draw_rectangle((previousROIvertical[0]-3, previousROIvertical[1],previousROIvertical[2]+6, previousROIvertical[3]), color=0, fill=True) #Zero out the ROI and 3 pixels more on each side of the X axis 
        img.draw_rectangle(previousROIvertical, color=80)
        img.draw_line(line.line(), color=127)

        #Add info
        print_string = "Line Ok: %d - turn %d - line t: %d, r: %d" % (line.magnitude(), output, line.theta(), line.rho())

    elif line and (line.magnitude() < MAG_THRESHOLD):
        print_string = "Not a good line: %d - turn %d" % (line.magnitude(), output)
        previousROIvertical = (0,0,80,60)	#Reset V ROI

    else:
        print_string = "Line Lost - turn %d" % (output)
        previousROIvertical = (0,0,80,60)	#Reset V ROI

    #HORIZONTAL LINE
    lineH = img.get_regression([(255, 255)], roi=previousROIhorizontal, robust=True)

    #Draw the ROI
    img.draw_rectangle(previousROIhorizontal, color=80)

    if lineH and (lineH.magnitude() >= MAG_THRESHOLD_HORIZONTAL):
        #Compute ROI for next frame
        if lineH.y1() < lineH.y2():
            previousROIhorizontal = (0, lineH.y1()-int(marginROIhorizontal/2), 80, lineH.y2()-lineH.y1()+marginROIhorizontal)
        else:
            previousROIhorizontal = (0, lineH.y2()-int(marginROIhorizontal/2), 80, lineH.y1()-lineH.y2()+marginROIhorizontal)
        #Draw ROI
        img.draw_line(lineH.line(), color=127)

        #Add info
        print_string = print_string + " | LineH Ok: %d - line t: %d, r: %d | %s" % (lineH.magnitude(), lineH.theta(), lineH.rho(), lineH.line())

    elif lineH and (lineH.magnitude() < MAG_THRESHOLD_HORIZONTAL):
        print_string = print_string + " | Not a good lineH: %d " % (lineH.magnitude())
        previousROIhorizontal = (0,0,80,60)
    else:
        previousROIhorizontal = (0,0,80,60)

    print("FPS %f, %s" % (clock.fps(), print_string))

```

And here a couple more examples of the before and after images:  
 ![zeroed v roi3_pre.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/e296bf3dc5925167ee555c30f3cab7f0077c1589.jpeg)  
 ![zeroed v roi3_post.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/4ca627f53b3e9a26784b3d25932ca711e74bd3a9.jpeg)  
I really appreciate your help looking into this!

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 24, 2020, 7:06pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/12 "2020-08-24T19:06:36Z")

</div>

Seems like something is wrong with robust linear regression. It gets the answer wrong with the horizontal line.

```python
BINARY_VIEW = True
GRAYSCALE_THRESHOLD = (200, 255)
MAG_THRESHOLD = 12
MAG_THRESHOLD_HORIZONTAL = 5

import sensor, image, time, math, pyb

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQQVGA)
sensor.set_vflip(True)
sensor.set_hmirror(True)
sensor.set_auto_gain(True)
sensor.set_auto_exposure(True)
sensor.set_auto_whitebal(True)

sensor.skip_frames(time = 2000)
clock = time.clock()

uart = pyb.UART(3, 115200)

previousROIvertical = (0,0,80,60)
previousROIhorizontal = (0,0,80,60)

marginROI = 10
marginROIhorizontal = 3

output = 0

while True:
    clock.tick()
    print_string = ""

    img = image.Image("pre.bmp", copy_to_fb=True).invert().to_grayscale()
    img = img.lens_corr(strength = 1.5, zoom = 1.0)

    if BINARY_VIEW:
        img.binary([GRAYSCALE_THRESHOLD])
        
    copy = img.copy()

    #VERTICAL LINE
    line = copy.get_regression([(255, 255)], roi=previousROIvertical, robust=True)
        
    if line and (line.magnitude() >= MAG_THRESHOLD):
        #Compute ROI for next frame
        if line.x1() < line.x2():
            previousROIvertical = (line.x1()-int(marginROI/2), 0, marginROI+line.x2()-line.x1(), 60)
        else:
            previousROIvertical = (line.x2()-int(marginROI/2), 0, marginROI+line.x1()-line.x2(), 60)

        #Draw ROI
        copy.draw_rectangle((previousROIvertical[0]-3, previousROIvertical[1],previousROIvertical[2]+6, previousROIvertical[3]), color=0, fill=True) #Zero out the ROI and 3 pixels more on each side of the X axis 
        img.draw_rectangle(previousROIvertical, color=80)
        img.draw_line(line.line(), color=127)

        #Add info
        print_string = "Line Ok: %d - turn %d - line t: %d, r: %d" % (line.magnitude(), output, line.theta(), line.rho())

    elif line and (line.magnitude() < MAG_THRESHOLD):
        print_string = "Not a good line: %d - turn %d" % (line.magnitude(), output)
        previousROIvertical = (0,0,80,60)	#Reset V ROI

    else:
        print_string = "Line Lost - turn %d" % (output)
        previousROIvertical = (0,0,80,60)	#Reset V ROI

    #HORIZONTAL LINE
    lineH = copy.get_regression([(255, 255)], roi=previousROIhorizontal, robust=False)

    #Draw the ROI
    img.draw_rectangle(previousROIhorizontal, color=80)

    if lineH and (lineH.magnitude() >= MAG_THRESHOLD_HORIZONTAL):
        #Compute ROI for next frame
        if lineH.y1() < lineH.y2():
            previousROIhorizontal = (0, lineH.y1()-int(marginROIhorizontal/2), 80, lineH.y2()-lineH.y1()+marginROIhorizontal)
        else:
            previousROIhorizontal = (0, lineH.y2()-int(marginROIhorizontal/2), 80, lineH.y1()-lineH.y2()+marginROIhorizontal)
        #Draw ROI
        img.draw_line(lineH.line(), color=127)

        #Add info
        print_string = print_string + " | LineH Ok: %d - line t: %d, r: %d | %s" % (lineH.magnitude(), lineH.theta(), lineH.rho(), lineH.line())

    elif lineH and (lineH.magnitude() < MAG_THRESHOLD_HORIZONTAL):
        print_string = print_string + " | Not a good lineH: %d " % (lineH.magnitude())
        previousROIhorizontal = (0,0,80,60)
    else:
        previousROIhorizontal = (0,0,80,60)

    print("FPS %f, %s" % (clock.fps(), print_string))

```

So, I switched to the regular linear regression.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 24, 2020, 7:15pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/13 "2020-08-24T19:15:12Z")

</div>

Robust is not stable for a pure horizontal line…

Must be something here loosing precision.

[https://github.com/openmv/openmv/blob/master/src/omv/img/stats.c#L1070](https://github.com/openmv/openmv/blob/master/src/omv/img/stats.c#L1070)

…

I think it’s something to do with the atan2 as x gets close close to zero.  
[regular.mp4](https://forums.openmv.io/uploads/short-url/nBedVWktgyUqaV9oEHciOWrprXy.mp4) (85.6 KB)  
[robust.mp4](https://forums.openmv.io/uploads/short-url/gGNVQqWIBRgyGzPdEvsXIJ5iJRr.mp4) (63.7 KB)

---

<div class="post-metadata">

**Author:** ![Angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Angel](https://forums.openmv.io/u/Angel)\
**Post date:** [August 24, 2020, 7:43pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/14 "2020-08-24T19:43:55Z")

</div>

Aha!!!  
That’s a great finding!  
Thank you very much for putting the time on this. I hope this can help other people too!  
Any chance that gets fixed in some new release? Please, let me know if there is anything I can do to help here. I’ll be happy to do so!

So, using regular makes it work a lot better, but I’m getting weird results with the magnitude. It seems like I get higher magnitude values when the line is at the top of the image even though it is much smaller than when the line is in the middle with a lot more white pixels.  
Here is an example right before and after finding the lines:  
This is the lense and color corrected image before finding lines.  
 ![h magnitude 23_pre.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/e44bf02c42d935a5a143e8ff388b09142b4a4d84.jpeg)  
So I’m getting a Magnitude value of 23 on this one, which is good!  
 ![h magnitude 23_post.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/6b6613d6dd4ba4dc1b2d4c60b0d483e5783c67c5.jpeg)  
But now when the line is in the middle of the frame with a lot more “substance”  
 ![h magnitude 10_pre.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/a767719c1b2e3e22c601c137170ef763cc66eb2f.jpeg)  
I’m only getting a magnitude of 10 ☹  
 ![h magnitude 10_post.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/45a824bef42a1855f8ec7f28c20226edbbdc7905.jpeg)  
I’d assume this is not really expected, right?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 24, 2020, 7:52pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/15 "2020-08-24T19:52:22Z")

</div>

Magnitude is a different calculation for robust versus non-robust.

For non-robust it’s basically how liney the line is. I.e. it gets higher the more straight and thin the line is.

For robust its the size of the line thinkness basically. Basically, the length of the mx/my vector that gives the line it’s direction. It makes sense for the robust operation. Not for the non-robust one. So… I just picked a measurement that gives some type of quality info for non-robust.

---

<div class="post-metadata">

**Author:** ![Angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Angel](https://forums.openmv.io/u/Angel)\
**Post date:** [August 24, 2020, 8:28pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/16 "2020-08-24T20:28:47Z")

</div>

I see.  
So would there be any easy way to measure the quality of the line in terms of its thickness or area?  
EDIT: Just my two cents here. So after trying the magnitude in different situations, obviously within my restricted experiment, I’d say it’s actually misleading as it provides high numbers in scenes that are not lines at all. Here is an example of just a couple small blobs providing a magnitude of 16 as opposed to some of the previous images with thick lines that were getting about 10.  
 ![misleading magnitude_pre.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/a81bfe77ea9d0f2903174adc1f06936f9dff60b4.jpeg)  
 ![misleading magnitude.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/f62d72ad4c6caeb8c1fbba6f50f04fd2c0fd597a.jpeg)  
I think I still have to find a way to evaluate the line with something as powerful as the magnitude when using Robust=True, so I’m trying to find rectangles for now unless you have a better way to do it 🙂

Again, Thank you sooo much for your help here!

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 24, 2020, 10:11pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/17 "2020-08-24T22:11:42Z")

</div>

Yeah, i didn’t have an algorithm template to work with for designing this. I need to fix the robust linear regression however.

---

<div class="post-metadata">

**Author:** ![Angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Angel](https://forums.openmv.io/u/Angel)\
**Post date:** [August 24, 2020, 11:45pm UTC](https://forums.openmv.io/t/detecting-and-navigating-in-a-matrix/1887/18 "2020-08-24T23:45:57Z")

</div>

No worries! You are doing a lot already helping this many people!  
Please, let me know if there is anything I can do to help!
