3

Is it possible to find the distance between the detected qr bar code (square) and the camera, if the size of the actual bar code and the (x,y) of all the corners of the bar code detected by the camera are known?

I want the method to work even if the camera is at an angle from the barcode.

I tried using a simple equation like f=d*z/D , where f is the local length of the camera, D is the size of the object, d is the width of the detected object in pixels, and z is the distance between the camera and the barcode. First, I calculate the focal length by using data from a known distance and then get the z values accordingly.

While the above method works pretty well but it has a lot of error if the camera is at an angle.

Is there is a better method to do this ?

Also, I can use only one camera, using two cameras is not an option.

  • What do you consider the distance of camera and barcode? The distance between camera image plane center and barcode center? – Niko Jan 10 '13 at 22:08
  • Yeah, barcode center and image plane center. – Ravdeep Johar Jan 10 '13 at 22:28
  • Another thing to note is that my camera is mounted on a robot and barcode would be placed on the wall. – Ravdeep Johar Jan 10 '13 at 22:30
  • Can't you correct the distortion ? – mmgp Jan 10 '13 at 22:37
  • I'm not sure how I would go about correcting distortion. – Ravdeep Johar Jan 10 '13 at 22:48
  • I'm not so sure either :) But since the object is known, you could estimate which side(s) is(are) more distorted, and the perspective transform would be adjusted to map to a rectangle sized according to the not-so-much distorted sides. For clarity, can you share an image that works for you, and one at the same distance that doesn't ? – mmgp Jan 10 '13 at 22:52
  • The paper "Distance and Angle Measurement of Distant Objects on an Oblique Plane Based on Pixel Variation of CCD Image" (http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=05488218) is a more evolved version of what I was saying. That solves your problem, have you seen it ? – mmgp Jan 10 '13 at 23:20

2 Answers2

0

Use your current formula (which you state works well) against the longest side and its opposite, then average the results.

Alternatively, just average the lengths of the longest side and its opposite. The relationships are all linear so you should end up with the same answer.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • `(infinity + x) / 2` doesn't seem like a good result. The infinity comes from a very angled image with width close to 0 pixels at one of the sides. – mmgp Jan 10 '13 at 22:36
0

First you have to know the camera angle. If you can not read that parameter from a device you could estimate that parameter by using other measures.

For example you know that a bar-code is rectangular. So by detecting it you could obtain four angles and from that estimate a homografy matrix. By knowing the homography matrix you could simplify your problem by just multiplying the coordinates with a homography inverse.

Homography matrix is wiedly used in camera calibration when a known pattern is presented such as chessboard.

dajuric
  • 2,373
  • 2
  • 20
  • 43