Measure distance between two paper bands

OpenMV related project discussion.
frav
Posts: 12
Joined: Fri Mar 30, 2018 6:12 am

Measure distance between two paper bands

Postby frav » Fri Mar 30, 2018 6:33 am

Hello,
I would like to use an OpenMV M7 to measure the gap between two paper bands while they run between two rolls on a production machine (I am attaching a picture took inside the machine).
Francesco
Paper bands.JPG
Paper bands.JPG (78.38 KiB) Viewed 1572 times
Referring to the picture, I image that a camera each gap between two strips will be required.
Since I am a newbie in computer vision I would really appreciate any kind of suggestions about the right techniques and and the more convenient software example to be followed.

Greetings
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Measure distance between two paper bands

Postby kwagyeman » Fri Mar 30, 2018 11:12 am

Hi, for this application you'll need a lot of horizontal res but not vertical res. So, set the resolution to VGA. Set the pix format to grayscale. Then set windowing to (640, 80).

Next, use lens_corr() to undo lens distortion. Also, you should use the wide angle lens with your application.

After this... If you mounted the OpenMV Cam right... You should be able to see two slits and then the start of the next piece of paper.

If so, then to get_historgram() on the image followed by get_threshold() on what get histogram returns. This will give you the best color thresholds to segment the image with.

Finally, do find_blobs() using those color thresholds and measure the maximum length of he biggest blob. This will tell you the paper width in pixels.

I can provide code later tonight if you need it.
Nyamekye,
frav
Posts: 12
Joined: Fri Mar 30, 2018 6:12 am

Re: Measure distance between two paper bands

Postby frav » Fri Mar 30, 2018 12:29 pm

Thank you very much for your suggestion.
If you can provide some lines of code it would be very
well appreciated, so will have some base to start.

Bye
Francesco
frav
Posts: 12
Joined: Fri Mar 30, 2018 6:12 am

Re: Measure distance between two paper bands

Postby frav » Fri Mar 30, 2018 3:06 pm

Hi,
by re-reading your message I just realized that we had a misunderstanding: actually I need to measure the gap of a slit between two piece of paper.
Img.jpg
Img.jpg (5.88 KiB) Viewed 1548 times
I think the concept should be the same but, maybe, a littele more difficult to chose the right blob (I cannot pick the widther one...).
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Measure distance between two paper bands

Postby kwagyeman » Fri Mar 30, 2018 3:32 pm

Oh, you just invert what color you are tracking and look for the widest blob still.
Nyamekye,
frav
Posts: 12
Joined: Fri Mar 30, 2018 6:12 am

Re: Measure distance between two paper bands

Postby frav » Sat Mar 31, 2018 10:14 am

Sorry to bother you...
I am trying but I got stuck on this error...
Error.JPG
Error.JPG (89.25 KiB) Viewed 1431 times
Any help would much appreciated!
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Measure distance between two paper bands

Postby kwagyeman » Sat Mar 31, 2018 11:49 am

Hi please update your firmware. It's out of date.
Nyamekye,
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Measure distance between two paper bands

Postby kwagyeman » Sat Mar 31, 2018 12:58 pm

Hi, this code basically does what you want. Feel free to clean it up:

Code: Select all

# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!

import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.VGA)   # Set frame size to QVGA (320x240)
sensor.set_windowing((640, 80))
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()
    threshold = img.get_histogram().get_threshold()
    blobs = img.find_blobs([(0, threshold.value())], invert=False)
    if blobs:
        largest = max(blobs, key = lambda x: x.w())
        img.draw_rectangle(largest.rect())
        print(largest.w())
    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.
Nyamekye,
frav
Posts: 12
Joined: Fri Mar 30, 2018 6:12 am

Re: Measure distance between two paper bands

Postby frav » Sat Mar 31, 2018 1:46 pm

Thank you for the code!

Actually my IDE shows on the bottom right corner "Firmware Version: 2.7.0 - [latest]"
The IDE version is 1.8.1.

I guess it already the newer one....
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Measure distance between two paper bands

Postby kwagyeman » Sat Mar 31, 2018 2:05 pm

I noticed that the autocomplete dictionary seems to have the wrong spelling of that method name. Will fix.
Nyamekye,
frav
Posts: 12
Joined: Fri Mar 30, 2018 6:12 am

Re: Measure distance between two paper bands

Postby frav » Sat Mar 31, 2018 2:22 pm

Yes, same mistake is on the online documentation.

By the way, the line:
threshold = img.get_histogram().get_threshold()

still return the error " 'histogram' object has no attribute 'get_threshold' ".

The same if i try to write threshold in the wrong way.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Measure distance between two paper bands

Postby kwagyeman » Sat Mar 31, 2018 2:56 pm

Mmm, this method seems to not have made it in the v2.7.0 firmware.

Attached is the pre-release v2.8.0 firmware. Use Tools -> Run bootloader to update your camera. Then the above code works.
Attachments
firmware.zip
(1.06 MiB) Downloaded 22 times
Nyamekye,
frav
Posts: 12
Joined: Fri Mar 30, 2018 6:12 am

Re: Measure distance between two paper bands

Postby frav » Tue May 01, 2018 2:28 pm

Hello I made some steps ahead on the project.
I decided to cover the machine width with several CAMs and I cannot predict if the the narrow gap between paper slits will be in front of a camera (maybe some of them will see only a white paper sheet).
I experienced that in this case the CAM is detecting some strange blobs in the image which have no sense for my application.
How could I filter the blobs "quality" in order to make sure that I will only obtain a gap measurement (in case no gap is visible by a CAM I should have no output)?

thanks
F
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Measure distance between two paper bands

Postby kwagyeman » Tue May 01, 2018 2:32 pm

Hi, I don't know what's going on from your description. Can you provide a simplified code snippet and pics of the issue?
Nyamekye,
frav
Posts: 12
Joined: Fri Mar 30, 2018 6:12 am

Re: Measure distance between two paper bands

Postby frav » Tue May 01, 2018 2:59 pm

Ok. I'll send it tomorrow.
For the time being you can image that in white paper the cam is detecting a threshold due to some shadows and it result in a blob detection.
The core of the program I am using is practically the one you suggested a few posts above this.

Bye
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Measure distance between two paper bands

Postby kwagyeman » Tue May 01, 2018 4:21 pm

Ah, okay, so, the issue is because you need to adaptive threshold the image. You can use the mean/median/mode/midpoint methods to adaptively threshold the image. This will take care of shadows. You will then just get a black and white image where hard lines are. See the adaptive threshold example under filters.
Nyamekye,

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests