Part size measurement. Hardware questions.

I am very sorry for the beginner’s questions. But I’m a beginner.
I want to make a part measurement using OpenMV. I’m currently experimenting with the program but it seems I need good backlighting.
Does anyone have experience in this field?
I have two questions:
Should I have a diffused white light source or do I need a light pulse source?
The second question is is it enough to have a standard sensor or is it better to buy a Global Shutter sensor?

Hi, can you show me a picture of what the issue is?

I can’t tell what you are struggling with.

There is picture from real machine where is mounted original camera:


Camera is marked with number 1
Point 2 is where part comes out in mid air and point 3 is where white background can be placed.
This is wire processing machine for springs forming.
My original camera is broken and old as me :smiley: and I want to try make a new one based on OpenMV.

Thanks, but, I was asking more about how you’d use the OpenMV Cam in this situation? What is the camera looking at and what does the picture look like?

I hope to write a program to make a screenshot and find a rectangle in it. The screen shot is created when Pin1 has a low logic level.
Then I get the length of this rectangle, which also gives information about the length of the part. I will then send this resulting number to the PLC which manages the part sorting.
If there is enough time for the program, I will entrust the management of the sorter to OpenMV using the digital output.
The original camera will be replaced by OpenMV and the component will be surrounded by a diffused light source. Now I make the camera case so it can be fixed.
I can only show the video: MEGA of the camera body making stage. I can draw a sketch of the idea.

Please start with the find_line_segments() algorithm. It will give you line segments for the edge of the box which you can use to measure the length. There’s also the find_rect() method.

What do You mean with edge of ‘box’?
My object for measurements are spring


Somehow I should get a rightmost edge of that spring. That kind of springs comes out of machine and I trying to measure each of them.
Box in attached video are enclosure for camera.

You were talking about finding rectangles. So, I thought you were looking at a box.

Just use find_line_segments(). Then it will return a list of line segments. See the example under feature detection examples to get started.

  1. To make the algorithm run faster constrain the ROI of the code to just to the area in the image where you expect the spring to be. You can find the ROI in the image by selecting the area in the IDE frame buffer. Pass that ROI to the method like “roi=(x,y,w,h)” as one of the arguments to the method.

  2. Given the list of the line segments, find the min left and max right line segment:

min_x = min(line_segments, key=lambda x: min(x.x1(), x.x2()))
max_x = max(line_segments, key=lambda x: max(x.x1(), x.x2()))

The lambda method finds the min/max of each line itself and then the min/max of the list of lines.

The max_x-min_x is the length of the spring.

Thank You, Nyamekye for giving idea.

Note, in the upcoming firmware we increased the speed of find_line_segments to 20 fps or so.