Author Topic: computer vision translate real world object size to image pixel size  (Read 960 times)

0 Members and 1 Guest are viewing this topic.

Offline willydlwTopic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
My goal is to mount a web camera on a ground vehicle robot and have it recognize lanes and drive in between the lanes. In order to look for the appropriate size lines(lanes) in an image, I am trying to learn how to convert the size of a real world object to image pixel size.

If I mount a usb camera so that its height above the ground is a known fixed vertical distance from the ground, and the angle between the center of the camera lens is fixed, how do I relate the size of a real world object to the number of pixels in the image.

Example: My camera is two feet above the floor. If I define the y axis as pointing upward from the floor, my camera is on the y axis at real world coordinates (x = 0, y = 2 feet, z = 0). It has an angle of 15 degrees below the horizontal xz plane, meaning my camera is pointed downwards toward the floor.

I take an image of some bright green tape on the floor. The tape is 3 feet long and 2 inches wide. How do I translate an object of 3 feet long and 2 inches wide to pixel dimensions? How do I calculate how many pixels represent 3 feet in my image? I am trying to recognize lines of the approximate size.

Thank you in advance for your help.

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 214
  • Helpful? 11
Re: computer vision translate real world object size to image pixel size
« Reply #1 on: April 30, 2013, 12:03:54 PM »
Take a picture of a yardstick lying on the ground.
I get paid to play with robots - can't beat that with a stick.


Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,278
  • Helpful? 79
Re: computer vision translate real world object size to image pixel size
« Reply #2 on: April 30, 2013, 01:08:54 PM »
The problem is that to solve that, you need three coordinates: X, Y, and depth. Unfortunately, the camera only gives you two.

If you can assume that the floor ahead of you is flat, then you can assume the depth of a particular pixel, and from that, you may be able to calculate the actual size, but this is an assumption that only works with very well calibrated/mounted cameras in research-ey, indoors environments.

What you can do is calculate the angle from the iris to the pixel. If you know the horizontal field of view, you can divide that by the width in pixels; same thing for vertical. For very narrow fields of view, it may be sufficient to do a linear relation; for wider fields of view, you need to skew the pixel angle based on the tangent of the ray from the object to the iris. Note that the angle is not the same thing as size, as it expands as it moves away from the camera! (Hence, why depth is needed.)

In general, I highly recommend studying actual optics (like, for cameras,) followed by 3D graphics projection math, before coming back to computer vision.

Offline Duane Degn

  • Jr. Member
  • **
  • Posts: 40
  • Helpful? 0
Back in the days of film cameras, we could figure out how far away something was in photograph by measuring the image size (on the negative). In order for this to work you also had to know the focal length of the lens and the size of the object.

IIRC the relationship was:

(image size) / (focal length) = (object size) / (distance from camera)

If you knew three of the values you could compute the forth this way.

Depending on the lens used, you may be limited on how much of the image area this would work. A fish eye lens would cause distortions which would throw off the calculation.

Since we no longer deal with negatives, you'd want to know the size of the pixel on the sensor and the focal length. Or you could make it easier on yourself on do what jkerns and jwatte suggest. You should have a pretty linear relationship between size and distance over much of the image of the camera so if you took a picture of a yard stick and measured the distance to the yard stick, you'd be off to a good start.

Offline idee17

  • Full Member
  • ***
  • Posts: 71
  • Helpful? 1
I think you could mount two cameras side by side then judge by the parallax effect to determine distance.
There are 10 types of people in the world: those who understand binary, and those who don't.


Get Your Ad Here