-1

I have a camera with these specs:

  • full resolution 1280x1024
  • pixel size 0.0048mm
  • focal length 8 mm

I need to detect a ball in this image. It is 4 meters away and its radius is 0.0373 meter.

How to convert the radius to from meter to pixel in this case?

the reason is that I need to use cv2.HoughCircles() and need to have the value for this function.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
S.EB
  • 1,966
  • 4
  • 29
  • 54
  • 2
    That will depend on the lens and the distance of the ball from the camera. – Dan Mašek Jan 31 '23 at 09:18
  • 1
    @DanMašek The camera is tilted 10 degree upwards towards the sky. It is sitting on the ground 4 meters away from where the ball starts and its Focal length FL 8mm – S.EB Jan 31 '23 at 09:41
  • I've copied the relevant info from your comment into the question. -- say, you know about the pinhole camera model. what kept you from calculating this yourself? – Christoph Rackwitz Jan 31 '23 at 11:28
  • related: https://stackoverflow.com/questions/75293722/undesired-results-obtained-from-cv2-houghcircles-for-ball-detection – Christoph Rackwitz Jan 31 '23 at 11:30
  • opencv has a "projectPoints" function. Create a ball center at center = (cx, cy, cz) (e.g. with 4 m distance to the camera which is (0,0,0)) and generate points on the sphere/ball aorund that center: https://stackoverflow.com/a/50086913/2393191 then use projectPoints on those projected points to get image coordinates, where you search for minimum/maximum x/y – Micka Jan 31 '23 at 12:13
  • Please share a sample image, and a reproducible code sample. – Rotem Jan 31 '23 at 21:57
  • @Micka Thanks for your comment, how to apply it using projectPoints() based on the link you provided?`projectPoints()` function have some parameters as input. – S.EB Feb 01 '23 at 11:26
  • @Rotem this is my question here https://stackoverflow.com/q/75310059/6494707 with code and images, – S.EB Feb 01 '23 at 14:46
  • The actual radius is very close to 15.5 pixels. I think you should accept the answer of Christoph Rackwitz even if ball is not detected (the question above is about geometry, and `cv2.HoughCircles` is irrelevant in the context of the question). – Rotem Feb 01 '23 at 16:41

1 Answers1

4

Pinhole camera model.

  • Focal length (mm): 8 mm
  • Sensor pixel pitch: 4.8 µm/px
  • Focal length (px): 8 mm / (4.8 µm/px) = 1667 px =: f

Object:

  • Width: 0.0373 m
  • Distance: 4 m

Projection of object (px): (0.0373 m / 4 m) * f = 15.5 px

So that ball will appear to be 15.5 pixels in size.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • Thank you very much for your help. Once I ran this code, `circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, dp=1, minDist=50, param1=127, param2=30, minRadius = math.floor(projection_obj), maxRadius= math.ceil(maxradius))` , where `maxradius = projection_obj+projection_obj*0.1`, it returns `None` means it has not found any circles. Should I change any other specific parameters? Thanks again – S.EB Jan 31 '23 at 16:01