# Is't possible to find depth of a 2D image with opencv...?

Hi friends,

I'm new to opencv.

---->I was stuck while tracking object from a 2D images. ---->Is't possible to find depth of a 2D image(images taken from camara *.jpg file) with opencv or not .....?

  Can you post the code.

edit retag close merge delete

Sort by ยป oldest newest most voted

A 2D image contains - hence the name - only 2-dimensional information. You can't get 3-dimensional (depth) information from that.

• If, for example you know there is a face in the image, you roughly know what a face looks like in 3d, so you can extract 3-dimensional information by analysing shadows, head pose etc...

• Another way to get an object's 3d model from a 2d image is to project some known structure (e.g. a grid) onto the object and to use the grid's deformation to compute the surface.

• in case of a video you can use successive images to detect corresponding points and compute 3-dimensional information from that.

more

oh, ofc. i took it as 'color depth'

( 2013-02-27 03:19:28 -0600 )edit

Since you are tracking objects, you should have succesive frames containing 2D information. Best way to go then is to apply the stereo principle and create a 3D point cloud based on the two successive images like Ben suggested.

Use some feature descriptor like SIFT or SURF combined with RANSAC to find corresponding featuere points in both images. Then use this information to recreate the actual 3D point cloud, giving you information of the depth.

It's actually the same principle as the human perception, using left and right eye image.

( 2013-02-27 04:44:42 -0600 )edit
Mat img = imread("my.jpeg");
cout << img.rows << " " << img.cols << " " << img.channels() << " " << img.type() << endl;


so, img.channels() holds the depth, img.type() the type of one channel(uchar, int, float, etc)

more

Official site

GitHub

Wiki

Documentation