How to use OpenMV to process range measurement?

视频教程10 - 测距以及测量物体大小:https://singtown.com/learn/50001/
  • Way of the first kind: you is capable of using apriltag to process 3 dimension location. Refer to our course for the specific implement. AprilTag remark track http://book.openmv.cc/image/apriltag.html

  • Way of the second kind: OpenMV adopt monocular camera. You need to choose reference substance if you are desirous to make range measurement come true so that you can take advantage of the proportion of reference substance to calculate distance.

In this section, we will share the second kind of way. Let’s talk about How to calculate the distance between camera and ping pong ball through the size of ping pong ball in the camera.

What is known to all of us is the fact that the further ping pong ball is away from camera, the smaller size the ping pong ball in the camera will be. Thus, here comes the question: what’s the relation on earth? (emphasis: the mathematic geometry question here only involves the part of high school in trigonometric function. If you have no desire seeing this, you can just jump to the conclusion).

To simplify the question , let’s have a look at this picture:

We can learn from the geometrical relationship on the left camera:

That’s why here is formula(1)

We can know from the geometrical relationship on the right real circumstances:

Substitute formula (1),we can get conclusion formula:

This is the final relationship we would like to know. What’s this mean on earth? On the left side of equal sign, LM is length, Bpix is pixel the sphere take up in the camera while on the right side of equal sign,Rm refers to real radius of sphere, Apix refers to fixed pixel, a is the half of visual angle. Therefore, what the formula really want to show us:

Actual length is inversely proportional to pixel in the camera.

Simplify it, it will be:

Distance equals a constant divides pixel of diameter.

All right, we have already known the relationship, what’s more, it’s so easy. The specific operational steps are: measuring the value of this constant is first step, I firmly believe there is no need we repeat how to measure this again, that is let the sphere is 10 centimeter away from camera first printing the pixel value of diameter in the camera, then multiply them ,you will get the value of k.

After that, distance equals this constant divides pixel point in the camera. It is so easy.

I stick code of OpenMV here:

# Measure the distance
#
# This example shows off how to measure the distance through the size in imgage
# This example in particular looks for yellow pingpong ball.

import sensor, image, time

# For color tracking to work really well you should ideally be in a very, very,
# very, controlled enviroment where the lighting is constant...
yellow_threshold   = ( 56,   83,    5,   57,   63,   80)
# You may need to tweak the above settings for tracking green things...
# Select an area in the Framebuffer to copy the color settings.

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # use RGB565.
sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
sensor.skip_frames(10) # Let new settings take affect.
sensor.set_auto_whitebal(False) # turn this off.
clock = time.clock() # Tracks FPS.

K=5000#the value should be measured

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    blobs = img.find_blobs([yellow_threshold])
    if len(blobs) == 1:
        # Draw a rect around the blob.
        b = blobs[0]
        img.draw_rectangle(b[0:4]) # rect
        img.draw_cross(b[5], b[6]) # cx, cy
        Lm = (b[2]+b[3])/2
        length = K/Lm
        print(length)

    #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
    # connected to your computer. The FPS should increase once disconnected.

The result is like this, afterwards, print distance through serial.

results matching ""

    No results matching ""