Would it be possible to perform the canny edge detection just inside a roi?

General discussion about topics related to OpenMV.
TurboCaca
Posts: 3
Joined: Thu May 31, 2018 12:52 pm

Would it be possible to perform the canny edge detection just inside a roi?

Postby TurboCaca » Fri Jun 01, 2018 1:38 am

I'm starting to play with the OpenMV (thanks for that great project, I'm super newbie in Python, MicroPython and also in Machine Vision).

I have noticed that if I try to run the canny edge detection example with VGA resolution the IDE shows the following message:
MemoryError: FB Alloc Collision
Is it possible to bypass this by performing the canny edge detection just in a part of the image?

Thanks
User avatar
kwagyeman
Posts: 3050
Joined: Sun May 24, 2015 2:10 pm

Re: Would it be possible to perform the canny edge detection just inside a roi?

Postby kwagyeman » Fri Jun 01, 2018 1:45 am

Technically, there's no limit for this. However, we don't have a method yet to resize/crop a part of an image (one isn't there because we've been feature creeping to basically have full blown OpenCV on the camera). Anyway, please create a feature request for this on github to make sure it makes it into the firmware.

That said, you can use sensor.set_windowing((x, y, w, h)) to set a cropped part of the VGA image. This gives you just one smaller image and will let you use the method. If that works for you... i.e. you just wanted a lot of detail then just do that. Otherwise, if you need to canny the full image it's not possible given our limited RAM.
Nyamekye,
User avatar
iabdalkader
Posts: 840
Joined: Sun May 24, 2015 3:53 pm

Re: Would it be possible to perform the canny edge detection just inside a roi?

Postby iabdalkader » Thu Jun 21, 2018 2:30 pm

Hi, there's a bug in Canny edge ROI, the code allocates the gradient array for the whole image (regardless of ROI). It's now fixed and I confirmed it works on OMV3, 4 and will be included in the next release.
TurboCaca
Posts: 3
Joined: Thu May 31, 2018 12:52 pm

Re: Would it be possible to perform the canny edge detection just inside a roi?

Postby TurboCaca » Tue Mar 19, 2019 12:26 pm

The thing is that I'm not sure if Canny Edge would be the best solution for my project.

As the OpenMV doesn't need a computer or an Arduino to control a relay, I wanted to use it to control the production of a machine.

I have recorded two little videos of the machine working (one with good pieces after a process and one with a bad one):
Image
In this example I'm using the IR leds, but they shine too much, I guess that I'll have to use an external IR light source)


This one would be an example of a malformed spring after the process. I want to activate a relay when the camera gets something different to an empty hole or a hole with deformed springs:
Image

I've tried with the circle detection, but I guess that my searching area is too big and it crashes if I want to use QVGA resolution.

I don't know if comparing the image with a pattern would be effective, as there are holes without springs (and it's ok).

Any recommendation would be truly appreciated.
User avatar
kwagyeman
Posts: 3050
Joined: Sun May 24, 2015 2:10 pm

Re: Would it be possible to perform the canny edge detection just inside a roi?

Postby kwagyeman » Tue Mar 19, 2019 12:39 pm

This is a great example where the problem can be easily solved. Is there a particular area under which you want to do the detection? If so, capture the picture when everything is perfectly aligned and then use template matching to compare against an empty hole. If the hole is not empty... I.e. a template is not found to match... then you you activate the relay.

You just need to align the machine to the area you want to detect and then save a cropped part of the image where the spring is. Then, execute the find_template method on that same cropped area.
Nyamekye,
User avatar
kwagyeman
Posts: 3050
Joined: Sun May 24, 2015 2:10 pm

Re: Would it be possible to perform the canny edge detection just inside a roi?

Postby kwagyeman » Tue Mar 19, 2019 12:39 pm

Also, turn your exposure up to get rid of the highlights.
Nyamekye,
TurboCaca
Posts: 3
Joined: Thu May 31, 2018 12:52 pm

Re: Would it be possible to perform the canny edge detection just inside a roi?

Postby TurboCaca » Wed Mar 20, 2019 12:58 am

kwagyeman wrote:
Tue Mar 19, 2019 12:39 pm
This is a great example where the problem can be easily solved. Is there a particular area under which you want to do the detection? If so, capture the picture when everything is perfectly aligned and then use template matching to compare against an empty hole. If the hole is not empty... I.e. a template is not found to match... then you you activate the relay.

You just need to align the machine to the area you want to detect and then save a cropped part of the image where the spring is. Then, execute the find_template method on that same cropped area.
Thanks for the answer.

I just need to check one hole at time, so my ROI could be something like this (or even smaller):
Image

I'm doubting about the triggering. I'll have to test if I can use the find_circle feature to determinate if there's a whole hole in a certain region, take the picture of that area and then compare it against a template.
kwagyeman wrote:
Tue Mar 19, 2019 12:39 pm
Also, turn your exposure up to get rid of the highlights.
Oh, I didn't noticed that there was an exposure setting. Cheers!

Greets from Barcelona
User avatar
kwagyeman
Posts: 3050
Joined: Sun May 24, 2015 2:10 pm

Re: Would it be possible to perform the canny edge detection just inside a roi?

Postby kwagyeman » Wed Mar 20, 2019 1:06 am

Only the new global shutter camera on the H7 can trigger. It's designed for what you are doing however versus the OV7725 camera which is the default (and only camera on the M7).

Anyway, think of the camera as a sensor... so, if you control where the pixels you care about are it's quite easy to make it reliable and good at detecting stuff.
Nyamekye,

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 5 guests