# to detect small foreign objects

**URL:** <https://forums.openmv.io/t/to-detect-small-foreign-objects/512>\
**Category:** OpenMV Boards\
**Created:** [December 5, 2017, 8:06am UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512 "2017-12-05T08:06:39Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![bennyedward](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@bennyedward](https://forums.openmv.io/u/bennyedward)\
**Post date:** [December 29, 2017, 3:22am UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/21 "2017-12-29T03:22:32Z")

</div>

Very sorry …  
Please kindly continue to teach.

---

<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:** [December 29, 2017, 3:26am UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/22 "2017-12-29T03:26:56Z")

</div>

Can you post what else you were asking?

---

<div class="post-metadata">

**Author:** ![bennyedward](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@bennyedward](https://forums.openmv.io/u/bennyedward)\
**Post date:** [December 29, 2017, 3:30am UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/23 "2017-12-29T03:30:06Z")

</div>

Hi,  
Below is my question:

1. What is the effect if the offset value is increased or decreased?  
By using this new method:
2. Does the object color/grayscale threshold value still have to be defined?
3. Does img.mean() has a returned object, so draw\_rectangle() can be used on found object?

---

<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:** [December 29, 2017, 4:01am UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/24 "2017-12-29T04:01:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bennyedward](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@bennyedward](https://forums.openmv.io/u/bennyedward)\
**Post date:** [December 29, 2017, 10:11am UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/25 "2017-12-29T10:11:37Z")

</div>

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?

 ![fb.PNG](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/e06dfbd7279db4e147e5999a6e5707cc4b10e233.png)

---

<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:** [December 29, 2017, 6:33pm UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/26 "2017-12-29T18:33:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bennyedward](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@bennyedward](https://forums.openmv.io/u/bennyedward)\
**Post date:** [December 29, 2017, 11:55pm UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/27 "2017-12-29T23:55:05Z")

</div>

Hi,  
Thanks again for your guidance.

---

<div class="post-metadata">

**Author:** ![mannybranden7](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@mannybranden7](https://forums.openmv.io/u/mannybranden7)\
**Post date:** [March 7, 2018, 11:47pm UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/28 "2018-03-07T23:47:40Z")

</div>

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)

---

<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:** [March 8, 2018, 7:21am UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/29 "2018-03-08T07:21:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bianchi](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bianchi](https://forums.openmv.io/u/bianchi)\
**Post date:** [June 18, 2020, 2:19pm UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/30 "2020-06-18T14:19:11Z")

</div>

What lense do you use for this small object ?  
Can I use this lense ?

> **[11.3US $ |15.3mm Lens M12 Digital Video Magnifying Lens Microscope Lens...](https://www.aliexpress.com/item/2251832693146202.html?spm=a2g0o.cart.0.0.2e0f3c000hB9OX&mp=1&gatewayAdapt=4itemAdapt)**
>
> Smarter Shopping, Better Living! Aliexpress.com

---

<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:** [June 18, 2020, 7:16pm UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/31 "2020-06-18T19:16:55Z")

</div>

Buy it and try it out. I don’t know. It’s not a magnification lens however.

---

<div class="post-metadata">

**Author:** ![bianchi](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bianchi](https://forums.openmv.io/u/bianchi)\
**Post date:** [June 19, 2020, 1:58pm UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/32 "2020-06-19T13:58:57Z")

</div>

can you suggest which magnification lense I should use ?  
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:** [June 19, 2020, 2:53pm UTC](https://forums.openmv.io/t/to-detect-small-foreign-objects/512/33 "2020-06-19T14:53:00Z")

</div>

Sorry, I don’t have any information on which ones to use.

[Previous page](https://forums.openmv.io/t/to-detect-small-foreign-objects/512.md?page=1)
