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

General discussion about topics related to OpenMV.
TravisNguyen10
Posts: 3
Joined: Tue Apr 02, 2019 12:35 pm

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

Postby TravisNguyen10 » Tue Apr 02, 2019 12:44 pm

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
User avatar
iabdalkader
Posts: 920
Joined: Sun May 24, 2015 3:53 pm

Re: [Basic] Outputting Edge Detection Image to be Put in to Line Detection

Postby iabdalkader » Tue Apr 02, 2019 1:06 pm

See the edge detection example: examples/09-Feature-Detection/edges.py
TravisNguyen10
Posts: 3
Joined: Tue Apr 02, 2019 12:35 pm

Re: [Basic] Outputting Edge Detection Image to be Put in to Line Detection

Postby TravisNguyen10 » Tue Apr 02, 2019 1:40 pm

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.
User avatar
iabdalkader
Posts: 920
Joined: Sun May 24, 2015 3:53 pm

Re: [Basic] Outputting Edge Detection Image to be Put in to Line Detection

Postby iabdalkader » Tue Apr 02, 2019 1:59 pm

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.
TravisNguyen10
Posts: 3
Joined: Tue Apr 02, 2019 12:35 pm

Re: [Basic] Outputting Edge Detection Image to be Put in to Line Detection

Postby TravisNguyen10 » Tue Apr 02, 2019 2:24 pm

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
User avatar
iabdalkader
Posts: 920
Joined: Sun May 24, 2015 3:53 pm

Re: [Basic] Outputting Edge Detection Image to be Put in to Line Detection

Postby iabdalkader » Tue Apr 02, 2019 2:47 pm

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...).
User avatar
kwagyeman
Posts: 3209
Joined: Sun May 24, 2015 2:10 pm

Re: [Basic] Outputting Edge Detection Image to be Put in to Line Detection

Postby kwagyeman » Tue Apr 02, 2019 10:10 pm

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.
Nyamekye,
User avatar
kwagyeman
Posts: 3209
Joined: Sun May 24, 2015 2:10 pm

Re: [Basic] Outputting Edge Detection Image to be Put in to Line Detection

Postby kwagyeman » Tue Apr 02, 2019 10:15 pm

Do something like:

Code: Select all

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.
Nyamekye,

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 215 guests