简体   繁体   中英

How do I get the distance from an object to another object with a camera?

My FRC (robotics) team is having issues with image processing, and tomorrow is our last testing day before competition. The camera is facing downward and tilted in the x direction. We are trying to calculate the distance that an object is to a fixed point on the same surface. We only need to calculate the x distance (in inches).

Here's a diagram. The object could be anywhere on the line with the fixed point.

Here is the view from the camera

The tape measure represents the line in the diagram. I know it's low res and not the best picture, I took it just before I left today. The tape measure is where the object could be. And we only care about it's x position.

Other info if needed:

  • Camera: Pixy
  • Focal length: 28mm (1.1024")
  • Sensor size: 0.25"
  • Height of camera from surface (the ground in our case): 8"

We always know the x position (in pixels) of the object, we just need to calculate the distance (in inches) that the object is from the fixed point.

If you have any other questions please ask. Thanks.

You are on the right track with your image of the tape measure. All you need to do is manually (from that image), determine the inches (from zero) for each x-position (pixel). Create a lookup table that you can use in the code.

When you determine the x-position of the object and the x-position of the fixed point, look up the inches for each of these x-positions and subtract to get the distance between the object and the fixed point.

This approach is super simple, but also depends on proper calibration of the system. In particular, the operational setup (height, angle, camera optics, etc.) has to exactly match the setup when the test image was taken that was used to create the lookup table.

A standard technique is to calibrate the system by taking and processing a calibration image whenever the operational setup might have changed. For example, you could place a grid patter (eg, with one inch squares) in the field of view. The idea is that you code a calibration analysis that will determine the proper lookup table values based on the standard image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM