to detect small foreign objects

Discussion related to "under the hood" OpenMV topics.
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

to detect small foreign objects

Postby bennyedward » Tue Dec 05, 2017 3:06 am

My application is to detect small foreign objects (please see attached photo) such as cloth fibers that stick between (shiny) transparent film and white synthetic paper surface.
Can you suggest how to use OpenMV Cam for this application?
Is there any recommended microscope lens for use with OpenMV Cam?
Thank you.
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Tue Dec 05, 2017 3:27 am

Hi, there's no photo attached.

Anyway, you'll want to use the img.find_blobs() method to detect things like this. You'd use the inverse=True argument and search for everything that isn't the color of the paper you're looking at.

As for a microscope lens... the telephoto lens offer 4x zoom. Do you need more than that? Here's an 8x zoom lens.

https://www.aliexpress.com/store/produc ... 99886.html

Just google for M12 lenses and whatever zoom you need.
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Tue Dec 05, 2017 4:24 am

Very sorry forgot to attach a photo. Kindly refer to the attachment in this post.
Thank you very much for your advice.
Attachments
IMG-20171205-WA0006.jpg
IMG-20171205-WA0006.jpg (102.99 KiB) Viewed 5331 times
IMG-20171205-WA0003.jpg
IMG-20171205-WA0003.jpg (66.29 KiB) Viewed 5331 times
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Tue Dec 05, 2017 11:10 am

Hi, can you run the hello world demo with VGA resolution and tell me what the camera sees? That object is easy to detect... So, you just need a good about of zoom.

I just bought one of those lenses and if it works out and I can find a source I may stock it. 8x zoom is cool. I'll call it the microscope lens.
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Fri Dec 08, 2017 3:00 am

Hi,
This is what the camera sees from a distance of less than 10 millimeters and from an angle of about 45 degrees.
1st object is human eyelashes (3.5 millimeter length) & 2nd object is cloth fiber (1 millimeter length).
Attachments
sample12_2017124_line18_cam_nodigzoom_nomacro_lighting_190_255.PNG
sample12_2017124_line18_cam_nodigzoom_nomacro_lighting_190_255.PNG (42.27 KiB) Viewed 5308 times
sample23_2017124_line6_cam_nodigzoom_nomacro_lighting_198_255.PNG
sample23_2017124_line6_cam_nodigzoom_nomacro_lighting_198_255.PNG (40.14 KiB) Viewed 5308 times
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Fri Dec 08, 2017 3:01 am

Sorry.
1st object is cloth fiber (1 millimeter length) & 2nd object is human eyelashes (3.5 millimeter length)
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Sat Dec 09, 2017 2:40 pm

Hi, sorry for not getting back to you quickly.

For your application you really need adaptive thresholding. We don't have that right now but it's on my giant to do list.

Anyway, in the mean time you can get around the issue with the giant blob on the bottom by filtering out blobs which have a high pixel count.

So, call the find_blobs() method on the image using the color thresholds you figured out. Then, filter out all blobs with more than 500 pixels and less than 100 pixels. This should just tell you about blobs that are effectively dirt.

Also, you may wish to make the lighting flatter. Finally, use histeq() to pump the contrast up the image to make setting the color thresholds easier.
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Sat Dec 09, 2017 8:22 pm

Hi,
Thanks for your guidance and strong support.
Please advice further, where should define two pixels values, i.e. 500 and 100 in the instruction below?

image.find_blobs(thresholds[, roi=Auto, x_stride=2, y_stride=1, invert=False, area_threshold=10, pixels_threshold=10, merge=False, margin=0, threshold_cb=None, merge_cb=None])
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Sat Dec 09, 2017 8:37 pm

You have to do it on the returned objects:

Code: Select all

blobs = img.find_blobs(...)
out_blobs = []
    for b in out_blobs:
        if((100 <= b.pixels()) and (b.pixels() < 500)):
            out_blobs.append(b) 
See the documentation on the blob object for more information.
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Sat Dec 09, 2017 8:39 pm

Is it by calling "image.find_blobs" twice with separate thresholds? The first is for the 500 pixels and the second is for the 100 pixels?
Sorry to bother you with this kind of question.
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Sat Dec 09, 2017 8:41 pm

Thank you for your latest answer
Please ignore my last question, as it has been answered.
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Sat Dec 09, 2017 8:44 pm

There's a typo in my code:

Code: Select all

blobs = img.find_blobs(...)
out_blobs = []
    for b in blobs:
        if((100 <= b.pixels()) and (b.pixels() < 500)):
            out_blobs.append(b) 
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Tue Dec 12, 2017 5:03 am

Hi,
Attached is the result of camera detection of 4 objects.
The camera can detect 1.5 mm dirt (fb1), with and without additional lighting.
But it can not detect 1 mm cloth fiber (fb2) and 3.5 mm human eyelashes (fb3).
Can you suggest another method to detect fb2 and fb3?
How to reduce the influence of environmental lighting on detection?
Thanks.
Attachments
fb3.jpg
fb3.jpg (223.6 KiB) Viewed 5226 times
fb2.jpg
fb2.jpg (224.1 KiB) Viewed 5226 times
fb1.jpg
fb1.jpg (199.09 KiB) Viewed 5226 times
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Tue Dec 12, 2017 7:17 am

Sorry, previous post is the detection result of 3 objects, not 4.
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Tue Dec 12, 2017 11:59 am

Hi, you really need to improve the lighting in the scene. I can see the cameras shadow in the image...

If you're serious about this application you need to mount the camera to a jig where it's stable, then add flood lights around it that evenly illuminate the scene.

An evenly illuminated scene should not have the shadow ring you see around the edge of the image. Nor the cameras shadow in the image. You have to fix these things because the camera is effectively just looking for dark spots which shadows will look like.

If you look at professional computer vision systems like a pick and place machine you'll notice they use giant high powered flood lights to remove all shadows. This is want you need to do. Note that the lighting should not cast more shadows, so, it needs to be diffused.
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Tue Dec 12, 2017 11:17 pm

Hi,
Thank you very much for your suggestion.
I will try to improve the lighting as you suggest.
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Wed Dec 27, 2017 4:41 pm

Hi, the next version of the firmware will feature adaptive thresholding to deal with the issue you're having. This will pick out the hair and just that very easily without any effort or additional lighting control.

Let me know if you need the feature now and I can make a firmware image available to you.
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Thu Dec 28, 2017 5:09 am

Hi,
Thank you very much for the good news and for providing the required features for our application.
Yes, I need the feature now and please make a firmware image available to me.
Thank you.
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Thu Dec 28, 2017 1:41 pm

Hi, I've attached the firmware and an example script. The new method solves your problems for the first set of images you presented to me. As for the second set... no method will clean that much noise up in the image. Adaptive threshold just solves the problem of making light shadows not an issue.
Attachments
mean_adaptive_threshold_filter.zip
(1.04 MiB) Downloaded 43 times
Nyamekye,
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Thu Dec 28, 2017 10:15 pm

Hi,

1) The algorithm decides to make the output pixel white or not based on this logic:

pixel_area_average(x,y) - offset < pixel_value(x,y)

Where the area average is the average of all pixels around that pixel. Basically, if the average minus the offset is less than the value of the pixel then the output is a 1. So, changing the offset value just adjusts how the output is generated.

In general, the algorithm tends to mark areas where there's a sudden change. The offset value allows you to control exactly how much of a sudden change you threshold.

2) It looks like you deleted your question while I was writing...
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Thu Dec 28, 2017 10:22 pm

Very sorry ...
Please kindly continue to teach.
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Thu Dec 28, 2017 10:26 pm

Can you post what else you were asking?
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Thu Dec 28, 2017 10:30 pm

Hi,
Below is my question:
1) What is the effect if the offset value is increased or decreased?
By using this new method:
1) Does the object color/grayscale threshold value still have to be defined?
2) Does img.mean() has a returned object, so draw_rectangle() can be used on found object?
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Thu Dec 28, 2017 11:01 pm

Hi,

1) Was answered above.

2) No more work on that is needed.

3) Do:

img.find_blobs([(90, 100, -128, 127, -128, 127)])

For a RGB565 image and:

img.find_blobs([(250, 255)])

For a grayscale image.

After the automatic thresholding is run pixels will only be 0 to max values. So, the thresholds to be used with find_blobs are now constants.
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Fri Dec 29, 2017 5:11 am

Hi,
Thank you for your advice.
I have tried the attached script and I receive "OSError: Image format is not supported" message when set the frame size to VGA.
Does img.mean() not work in VGA mode?
Attachments
fb.PNG
fb.PNG (71.16 KiB) Viewed 5078 times
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Fri Dec 29, 2017 1:33 pm

You can do VGA in grayscale. But, not in RGB565. This is because for RGB565 (for VGA) mode we actually switch to operating in bayer pattern mode and jpeg compress the images to get video output. We have to do this because we don't have the RAM for a full VGA RGB565 image. Anyway, VGA for RGB565 is just for taking jpeg compressed images and nothing else.
Nyamekye,
bennyedward
Posts: 17
Joined: Tue Dec 05, 2017 2:52 am

Re: to detect small foreign objects

Postby bennyedward » Fri Dec 29, 2017 6:55 pm

Hi,
Thanks again for your guidance.
mannybranden7
Posts: 7
Joined: Mon Dec 11, 2017 10:25 pm

Re: to detect small foreign objects

Postby mannybranden7 » Wed Mar 07, 2018 6:47 pm

Regarding the thresholds constant, what exactly does each value in the threshold variable do?

Im trying to do the same thing but I dont understand what each value is representing?

Ex: thresholds = (70, 100, -128, 127, -128, 127)

I saw this example code below, which makes sense. Which finds extremely bright areas. But why use more than 2 values?
# The below grayscale threshold is set to only find extremely bright white areas.
thresholds = (245, 255)
User avatar
kwagyeman
Posts: 2462
Joined: Sun May 24, 2015 2:10 pm

Re: to detect small foreign objects

Postby kwagyeman » Thu Mar 08, 2018 2:21 am

Hi, those values correspond to thresholds on the LAB color settings:

L, A, and B define the LAB color space. L is the lighting, and A/B define the color. The thresholds are then (LMin, LMax, AMin, AMax. BMin, BMax). L goes from 0-100, A/B go from -128 to 127.

Grayscale just has 0-255 which maps roughly to the 0-100 for L.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 5 guests