OpenCV_StereoBM.java
import org.opencv.calib3d.StereoBM;
import org.opencv.core.Core;
import org.opencv.core.Core.MinMaxLocResult;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
public class OpenCV_StereoBM {
static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
public static void main(String[] args) {
Mat imgLeft = Imgcodecs.imread("D:\\projects\\Java\\OpenCV_Samples\\resource\\imgs\\scene_l.bmp",Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
Mat imgRight = Imgcodecs.imread("D:\\projects\\Java\\OpenCV_Samples\\resource\\imgs\\scene_r.bmp",Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
//Fonder la différence auto-correctrice
Mat imgDisparity16S = new Mat( imgLeft.rows(), imgLeft.cols(), CvType.CV_16S );
Mat imgDisparity8U = new Mat( imgLeft.rows(), imgLeft.cols(), CvType.CV_8UC1 );
//Préparation Stereo BM Structure du bâtiment Demande
int RangeOfDisparity = 16*5; //Gamme de disparité
int BlockWindowSize = 21; //fenêtre de bloc Grand et petit,Suki
//Image de contraste calculée
StereoBM sbm = StereoBM.create( RangeOfDisparity, BlockWindowSize );
sbm.compute( imgLeft, imgRight, imgDisparity16S );
//檢查 Extrême 值
Core.MinMaxLocResult minMaxVal=new Core.MinMaxLocResult();
double minVal; double maxVal;
minMaxVal=Core.minMaxLoc( imgDisparity16S);
minVal= minMaxVal.minVal;
maxVal=minMaxVal.maxVal;
System.out.println("Min value="+minVal+", Max value="+maxVal);
//CV utilisé_8UC1 Image formelle
imgDisparity16S.convertTo( imgDisparity8U, CvType.CV_8UC1, 255/(maxVal - minVal));
Imgcodecs.imwrite("D:\\projects\\Java\\OpenCV_Samples\\resource\\imgs\\SBM_sample.png ", imgDisparity16S);
}
}
Recommended Posts