# \[Basic\] Outputting Edge Detection Image to be Put in to Line Detection

**URL:** <https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192>\
**Category:** OpenMV Boards\
**Created:** [April 2, 2019, 4:44pm UTC](https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192 "2019-04-02T16:44:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![TravisNguyen10](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@TravisNguyen10](https://forums.openmv.io/u/TravisNguyen10)\
**Post date:** [April 2, 2019, 4:44pm UTC](https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192/1 "2019-04-02T16:44:45Z")

</div>

Preface: I am a MechE Major and have very little Python Experience but coded in MatLab and C++ a decent amount

I’m working on a project to determine when a wishbone coupon breaks from fatigue and wanted to use the OpenMV for its integrated Edge Detection Libraries. A problem that I’m facing is I don’t know how to get the image outputted on the video feed and manipulate the image.

Thanks,  
Travis

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [April 2, 2019, 5:06pm UTC](https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192/2 "2019-04-02T17:06:48Z")

</div>

See the edge detection example: examples/09-Feature-Detection/edges.py

---

<div class="post-metadata">

**Author:** ![TravisNguyen10](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@TravisNguyen10](https://forums.openmv.io/u/TravisNguyen10)\
**Post date:** [April 2, 2019, 5:40pm UTC](https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192/3 "2019-04-02T17:40:21Z")

</div>

Yeah I’m using that example I just don’t know what the outputs of the functions are or how to grab the image so I can make a code look at each individual pixel.

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [April 2, 2019, 5:59pm UTC](https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192/4 "2019-04-02T17:59:40Z")

</div>

This function finds edges in the image. You can also use find\_lines, rects, circles etc… What do you mean by grab an image ? img = sensor.snapshot() img is the image object.

---

<div class="post-metadata">

**Author:** ![TravisNguyen10](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@TravisNguyen10](https://forums.openmv.io/u/TravisNguyen10)\
**Post date:** [April 2, 2019, 6:24pm UTC](https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192/5 "2019-04-02T18:24:57Z")

</div>

So I used the find edges function and it gets an image in black and white. What I want to do with the image is to analyze the pixels and look at the surrounding pixels white to determine if there’s breakage. What I don’t know what to do how to interact with the processed image so that we can look at the individual pixels. Would having a sensor.snapshot() function have the post-processed image?

Here is what I thought should work with the edge detection image be used in conjunction with the find lines function but the image didn’t have any segment lines in it.

while(True):  
clock.tick()  
img = sensor.snapshot()  
pros\_img=img.find\_edges(image.EDGE\_CANNY, threshold=(50, 80))  
for l in img.find\_lines(threshold = 1000, theta\_margin = 25, rho\_margin = 25):  
if (min\_degree \<= l.theta()) and (l.theta() \<= max\_degree):  
img.draw\_line(l.line(), color = (255, 0, 0))

# print(l)

Appreciate the Help

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [April 2, 2019, 6:47pm UTC](https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192/6 "2019-04-02T18:47:02Z")

</div>

You should call find\_lines directly on the image (please see the find\_lines.py example). And if you want to access pixels you can access the image like an array (img[0] etc…).

---

<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:** [April 3, 2019, 2:10am UTC](https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192/7 "2019-04-03T02:10:37Z")

</div>

Hi, use find\_blobs() on the edge image. Find\_blobs() connects all pixels of a particular color with each other. This if there isn’t a breakage you will get one big blob. If there is a break you will get multiple blobs.

Set the color threshold to white to find all the white pixels connected with find blobs.

Your code to solve this problem will be about 5 lines.

Let me know if you still need help.

---

<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:** [April 3, 2019, 2:15am UTC](https://forums.openmv.io/t/basic-outputting-edge-detection-image-to-be-put-in-to-line-detection/1192/8 "2019-04-03T02:15:41Z")

</div>

Do something like:

```python
img = sensor.snapshot()
img.find_edges(...)
blobs = img.find_blobs([(200, 255)], area_threshold=0, pixels_threshold=0)
print(blobs)
if blobs > 1:
    print("Error")
elif blobs == 1:
    print("All connected")
else:
   print("No blobs")

```

Again, find blobs creates blobs by connecting all pixels of one color together. Note, on the OpenMV Cam never think about doing anything pixel wise. Look through our library to try to find what methods do what you want. Trying to do pixel wise stuff in python in terribly slow. Our algorithms are written in C to be fast however.
