Ask Your Question
0

distance to object from stereo pair

asked 2017-05-30 17:50:18 -0600

lounice gravatar image

Dear all,

I have a pair of stereo images provided by a stereo sensor (the Zed camera). I do not have access to the camera (no camera parameter was provided). I am asked to measure the distance to a distinct object in the images using the stereo pair. I have never performed 3D reconstruction from stereo pairs, however I do not think we can infer actual distances to an object from a stereo pair without having the parameters of the cameras. I guess I can only provide a depth map.

My questions are : 1. Is it possible to have the distance to an object in the scene from a stereo pair without having the camera parameters ?

  1. If we have the camera parameters, what are the steps to follow in order to measure the distance to an object in the scene (or at least have a depth map with the correct distances in meters for instance)

Thank you for your help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-05-31 01:26:03 -0600

LBerger gravatar image

updated 2017-06-05 03:03:19 -0600

1 " Is it possible to have the distance to an object in the scene from a stereo pair without having the camera parameters ?" No it is not possible to have the distance in standard unit but it possible to have a distance in unknown unit (scaling) see sfm module

2 if you know intrisic and extrinsic parameters of stereovision system (stereo_calib.cpp ) there is no problem example stereo_match.cpp

If you want to save only some 3D points in stereo_match.cpp example you have to modify these lines :

    Mat xyz;
    reprojectImageTo3D(disp, xyz, Q, true);
    saveXYZ(point_cloud_filename.c_str(), xyz);

If your object is red use inrange to create a mask. Create a new disparity map with all values equal to 0 and copy all disparity values in mask

Mat dispRedZone(disparity.rows,disparity.cols,disparity.type,Scalar(0));
Mat dispFloat;
disp.convertTo(disFloat, CV_32F, 1 / 16.);
disFloat.copyTo(dispRedZone,mask);
Mat xyz;

reprojectImageTo3D(dispRedZone, xyz, Q, true); // true means : here we quietly assume that at least one pixel in the disparity map is not defined. and we set the corresponding Z's to some fixed big value. ref https://github.com/opencv/opencv/blob/master/modules/calib3d/src/calibration.cpp#L2790-L2791
saveXYZ(point_cloud_filename.c_str(), xyz);

All points with a disparity equal to minimum disparity are sent to Z=10000. Negative disparity means

I hope it will help you

edit flag offensive delete link more

Comments

Thanks for your reply. I have implemented the stereo_match example with my data (camera parameters and stereo pair). I managed to get 3D points cloud (therefore I didn't check if they are consistent since I do not have viz). My question is how to measure the distance to a particular object in the scene ? In color images, this object can easily be recognized since it has a distinct color, however, I don't know how to find it in the 3D point cloud or in the disparity image so that I can measure a distance to it. Is there a way to map one of the views on the cloud in order to isolate the 3D points belonging to this object ? Should I filter the object at the very beginning in the stereo pair and reconstruct the 3D model of this object alone ? (I would lose most of the ...(more)

lounice gravatar imagelounice ( 2017-06-02 16:24:54 -0600 )edit

You have some code to write. I complete my answer

LBerger gravatar imageLBerger ( 2017-06-03 02:19:20 -0600 )edit

Hi LBerger.

thanks a lot. I'll try that. My only concern is about the mask. I guess I'll have to compute it from the left image ? The disparity doesn't seem to fit any of the images of the stereo pair...

Thanks !

lounice gravatar imagelounice ( 2017-06-03 13:09:56 -0600 )edit

disparity is relative to left image : v=disparity(x,y) means that left(x,y)=right(x+v/16,y).

LBerger gravatar imageLBerger ( 2017-06-04 02:18:38 -0600 )edit
1

Thank you.

lounice gravatar imagelounice ( 2017-06-04 11:43:05 -0600 )edit

Hi LBerger, I have applied your solution but I have inconsistent results. Regarding disp2 : Mat disp2(disparity.rows,disparity.cols,disparity.type,Scalar(10000)); since the disparity image in OpenCV is of type CV_16S its values span from -255 to +255, therefore the value 10000 is out of range. I obtain different z values (positive and negative values) from xyz depending on the value of ndisparities. Why ??? Also, I don't know why I am obtaining always -inf and +inf for the minimum and maximum values of x and y respectively. reprojectImageTo3D results are really weird (for instance, I get the same z for two different stereo pairs)... Thanks for your help.

lounice gravatar imagelounice ( 2017-06-04 21:00:56 -0600 )edit

CV_16S = -32768 to 32767 disparity equal to 1000 mean a real disaprity of 1000/16=62.5 When you have -inf or +inf in x or y it means that's there is no disparity (negative disparity ) value available for this pixel.

LBerger gravatar imageLBerger ( 2017-06-05 03:08:04 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-05-30 17:50:18 -0600

Seen: 1,741 times

Last updated: Jun 05 '17