[英]Depth map - stereo image in Android with OpenCV
I would like to ask, how I can create depth map (disparity map) using two images from LEFT and RIGHT camera and JAVACV/OPENCV library? 我想问一下,如何使用左和右摄像机的两个图像以及JAVACV / OPENCV库创建深度图(视差图)?
I use OpenCV (+JavaCV wrapper) in Android. 我在Android中使用OpenCV(+ JavaCV包装器)。 I found these code in the Internet - this is proper code?
我在互联网上找到了这些代码-这是正确的代码吗? How can I calibrate cameras?
如何校准相机?
private Mat createDisparityMap(Mat rectLeft, Mat rectRight){
// Converts the images to a proper type for stereoMatching
Mat left = new Mat();
Mat right = new Mat();
Imgproc.cvtColor(rectLeft, left, Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(rectRight, right, Imgproc.COLOR_BGR2GRAY);
// Create a new image using the size and type of the left image
Mat disparity = new Mat(left.size(), left.type());
int numDisparity = (int)(left.size().width/8);
opencv_calib3d.StereoSGBM stereoAlgo = new opencv_calib3d.StereoSGBM(
0, // min DIsparities
numDisparity, // numDisparities
11, // SADWindowSize
2*11*11, // 8*number_of_image_channels*SADWindowSize*SADWindowSize // p1
5*11*11, // 8*number_of_image_channels*SADWindowSize*SADWindowSize // p2
-1, // disp12MaxDiff
63, // prefilterCap
10, // uniqueness ratio
0, // sreckleWindowSize
32, // spreckle Range
false); // full DP
// create the DisparityMap - SLOW: O(Width*height*numDisparity)
stereoAlgo.compute(left, right, disparity);
Core.normalize(disparity, disparity, 0, 256, Core.NORM_MINMAX);
return disparity;
}
Try this (more comptable with android OpenCV SDK): 尝试以下操作(与Android OpenCV SDK兼容):
private Mat createDisparityMap(Mat rectLeft, Mat rectRight){
// Converts the images to a proper type for stereoMatching
Mat left = new Mat();
Mat right = new Mat();
Imgproc.cvtColor(rectLeft, left, Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(rectRight, right, Imgproc.COLOR_BGR2GRAY);
// Create a new image using the size and type of the left image
Mat disparity = new Mat(left.size(), left.type());
int numDisparity = (int)(left.size().width/8);
StereoSGBM stereoAlgo = StereoSGBM.create(
0, // min DIsparities
numDisparity, // numDisparities
11, // SADWindowSize
2*11*11, // 8*number_of_image_channels*SADWindowSize*SADWindowSize // p1
5*11*11, // 8*number_of_image_channels*SADWindowSize*SADWindowSize // p2
-1, // disp12MaxDiff
63, // prefilterCap
10, // uniqueness ratio
0, // sreckleWindowSize
32, // spreckle Range
0); // full DP
// create the DisparityMap - SLOW: O(Width*height*numDisparity)
stereoAlgo.compute(left, right, disparity);
Core.normalize(disparity, disparity, 0, 256, Core.NORM_MINMAX);
return disparity;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.