[JAVA] Bureau: OpenCV Trouver les coins de l'échiquier par WebCam

Goal
Test OpenCV find chessboard corners by webcam.

OpenCV_FindChessboardCornersByWebCam.java


import javax.swing.JFrame;
import org.opencv.calib3d.Calib3d;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Size;
import org.opencv.core.TermCriteria;
import org.opencv.imgproc.Imgproc;
import org.opencv.videoio.VideoCapture;

public class OpenCV_FindChessboardCornersByWebCam {
    static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
    public static void main(String arg[]) throws Exception{
        // It is better to group all frames together so cut and paste to
        // create more frames is easier
        JFrame frame1 = new JFrame("Version live du tableau");
        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame1.setSize(640,480);
        frame1.setBounds(0, 0, frame1.getWidth(), frame1.getHeight());
        Panel panel1 = new Panel();
        frame1.setContentPane(panel1);
        frame1.setVisible(true);

        //-- 2. Read the video stream
        VideoCapture capture = new VideoCapture();
        capture.open(0);
        Mat webcam_image=new Mat();

        capture.read(webcam_image);
        frame1.setSize(webcam_image.width()+40,webcam_image.height()+60);

        if( capture.isOpened())
        {
            while( true )
            {
                Thread.sleep(200);


                capture.read(webcam_image);
                if( !webcam_image.empty() ){

                    Mat destination=webcam_image.clone();
                    Imgproc.cvtColor(destination, destination, Imgproc.COLOR_BGR2GRAY);
                    Size boarderSize=new Size(9,6);
                    MatOfPoint2f imageCorners=new MatOfPoint2f();
                    boolean found=Calib3d.findChessboardCorners(destination, boarderSize, imageCorners,Calib3d.CALIB_CB_ADAPTIVE_THRESH+Calib3d.CALIB_CB_NORMALIZE_IMAGE+Calib3d.CALIB_CB_FAST_CHECK);
                    if (found){
                        Imgproc.cornerSubPix(destination, imageCorners, new Size(11,11), new Size(-1,-1),new TermCriteria(TermCriteria.EPS|TermCriteria.MAX_ITER,30,0.1));
                        Calib3d.drawChessboardCorners(webcam_image, boarderSize, imageCorners, found);
                    }
                    panel1.setimagewithMat(webcam_image);
                    frame1.repaint();
                }
                else
                {
                    System.out.println("Pas de rendez-vous supplémentaire!");
                    break;
                }
            }
        }
        return;
    }

}
Result
![test-Calib3d-2.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/276243/77b15c1b-347c-8e7b-16d7-c7df09c1ba92.jpeg)

Recommended Posts

Bureau: OpenCV Trouver les coins de l'échiquier par WebCam
Bureau: OpenCV Trouver les coins de l'échiquier par WebCam
Bureau: OpenCV FaceDetector par WebCam
Bureau: OpenCV Show Stylisation par WebCam
Bureau: aperçu de la webcam Opencv
Bureau: OpenCV Find Transform ECC
Bureau: OpenCV Subdiv2d Make Delaunay For Face By WebCam
Bureau: Tutoriel de prévisualisation de la webcam OpenCV
Bureau: vérification du rectangle OpenCV à l'intérieur par ClipLine
Bureau: seuil OpenCV
Bureau: OpenCV BilateralFilterBlur
Bureau: OpenCV Expand
Bureau: OpenCV Affine
Bureau: OpenCV Emboss
Bureau: OpenCV CLAHE
Bureau: OpenCV Ellipse2Poly
Bureau: OpenCV HDR
Bureau: Polylignes OpenCV
Bureau: OpenCV Denoise
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 StereoSGBM
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: seuil adaptatif OpenCV
Bureau: OpenCV Draw Circle
Bureau: OpenCV Fill Poly
Bureau: OpenCV Mean Filter
Bureau: référentiel Java OpenCV
Bureau: OpenCV pyrMeanShift Filter
Bureau: OpenCV OpticalFlow PyrLK
Bureau: Piano virtuel OpenCV
Bureau: image de fusion OpenCV
Bureau: Filtre OpenCV Scharr
Bureau: Filtre laplacien OpenCV
Bureau: Flou médian OpenCV
Bureau: OpenCV Add Broad