[JAVA] Bureau: OpenCV StereoSGBM

Goal
Test OpenCV StereoSGBM.

OpenCV_StereoSGBM.java


import org.opencv.calib3d.StereoBM;
import org.opencv.calib3d.StereoSGBM;
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_StereoSGBM {
    static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
    //SGBM(Semi-global block matching), BM(Block matching)
    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-corrigée
        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 ndisparities = 16*5;   //Gamme de disparité
        int SADWindowSize = 21; //fenêtre de bloc Grand et petit,Suki

        //Image de contraste calculée
        StereoSGBM sgbm = StereoSGBM.create( 0,32,10);
        //StereoSGBM sgbm = StereoSGBM.create( 0,16,3);
        sgbm.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\\SGBM_sample.png ", imgDisparity16S);
    }
}
Result
![SGBM_sample.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/276243/f89c10e1-f5f9-8b64-6a34-ad993f4e3789.png)

Recommended Posts

Bureau: OpenCV StereoSGBM
Bureau: seuil OpenCV
Bureau: OpenCV BilateralFilterBlur
Bureau: OpenCV Dilate
Bureau: OpenCV Expand
Bureau: OpenCV Affine
Bureau: OpenCV Emboss
Bureau: OpenCV Ellipse2Poly
Bureau: OpenCV HDR
Bureau: Polylignes OpenCV
Bureau: netteté OpenCV
Bureau: OpenCV Concat
Bureau: OpenCV OpenCV_SalonUseBlurAddWeighted
Bureau: OpenCV Mosaic
Bureau: OpenCV Erode
Bureau: OpenCV Denoise
Bureau: Rectangle OpenCV
Bureau: OpenCV Watershed
Bureau: Texte OpenCV
Bureau: OpenCV Inpaint
Bureau: OpenCV NormalizeBlur
Bureau: OpenCV Spot
Bureau: OpenCV Canny
Bureau: OpenCV Denoise3
Bureau: histogramme OpenCV
Bureau: OpenCV Dft
Bureau: OpenCV Decolor
Bureau: OpenCV FaceDetector
Bureau: OpenCV Denoise2
Bureau: OpenCV StereoBM
Bureau: Filtre OpenCV Kirsch
Bureau: Filtre laplacien OpenCV 2
Bureau: Changement d'éclairage OpenCV
Bureau: OpenCV Add WaterMark
Bureau: OpenCV Fill ConvexPoly
Bureau: OpenCV Grab Cut
Bureau: OpenCV Sharpness Gui
Bureau: Changement de couleur OpenCV
Bureau: Filtre Freichennel OpenCV
Bureau: seuil adaptatif OpenCV
Bureau: OpenCV Fill Poly
Bureau: OpenCV Mean Filter
Bureau: référentiel Java OpenCV
Bureau: OpenCV Sobel Filter2
Bureau: OpenCV pyrMeanShift Filter
Bureau: OpenCV OpticalFlow PyrLK
Bureau: Piano virtuel OpenCV
Bureau: image de fusion OpenCV
Bureau: Filtre OpenCV Scharr
Bureau: aperçu de la webcam Opencv
Bureau: Filtre laplacien OpenCV
Bureau: Flou médian OpenCV
Bureau: OpenCV Add Broad
Bureau: OpenCV Robinson Filter
Bureau: enregistrement vidéo OpenCV
Bureau: Aplatissement de la texture OpenCV
Bureau: OpenCV Flood Fill
Bureau: espace colorimétrique OpenCV
Bureau: Filtre OpenCV SqrBox
Bureau: redimensionner l'image OpenCV
Bureau: Croquis au crayon OpenCV