Ask Your Question

How to compute distance to car ahead using camera. [closed]

asked 2013-05-26 21:09:36 -0500

cellurl gravatar image


I am building a car app. It must use the Android camera and tell how far the car ahead is.

I don't even know if opencv is appropriate for this. Some have suggested Android NDK...

Thanks for discussion! jim

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by cellurl
close date 2018-02-08 12:20:24.449104



Start reading some articles on the topic. Car detection, collision avoidance, lane detection are some directions to read. You'll have a much better idea on where to start then.

sammy gravatar imagesammy ( 2013-05-27 02:12:04 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2013-05-27 04:58:34 -0500

rAum gravatar image

Of course OpenCV i appropriate for this but it's hard problem. Don't worry, there are solutions based on mono cam (for example mobileeye or I've seen some android apps).

There are plenty of ways to do this and you can experiment a lot, so good starting point is to read papers, I recommend work of Marcos Nieto ( ), good stuff there.

Basically you need to locate and recognize car ahead of you, and then you could try to estimate distance by bounding box size / perimeter / ... . You probably need to classify car to size categories and some machine learning may be involved.

Another way is to use bird-eye projection (just a simple perspective transform) on lane, but in this case may be hard (it will need calibration).

edit flag offensive delete link more


I have contacted iOnRoad, Mobieye, Allvision. None of them will add a beacon. This is your opportunity to build something useful.

cellurl gravatar imagecellurl ( 2014-01-06 10:42:58 -0500 )edit

answered 2013-05-27 02:23:19 -0500

bjoernz gravatar image

OpenCV can definitely be used to solve this problem, but first you need to be able to formulate an algorithm to estimate the depth from a single camera. Humans have two eyes for a reason :-)

Unfortunately I cannot help you in that department, but I will refer you to this Wikipedia page. You may also look for android augmented reality sdk.

Hopefully this will point you in the right direction to find solutions that are sufficient for your application.

To clarify:

  • OpenCV is an image processing (computer vision) library, that is used through the Android NDK.
  • Android NDK stands for Android Native Development Kit, which allows you to mix machine code and Dalvik byte code.
edit flag offensive delete link more


I only need to know approximate distance such as 10m, 100m, 1000m

cellurl gravatar imagecellurl ( 2014-01-06 10:44:06 -0500 )edit

Question Tools

1 follower


Asked: 2013-05-26 21:09:36 -0500

Seen: 2,549 times

Last updated: May 27 '13