[JAVA] Bureau: OpenCV Show Stylisation par WebCam

Goal
Test OpenCV show stylization by WebCam.

OpenCV_ShowStylizationByWebCam.java


import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.photo.Photo;
import org.opencv.videoio.VideoCapture;

import javax.swing.*;


public class OpenCV_ShowStylizationByWebCam {
    static {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }

    public static void main(String arg[]) {
        VideoCapture capture = new VideoCapture();
        capture.open(0);
        JFrame frame1 = new JFrame("show image");
        frame1.setTitle("Java Swing");
        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);

        JFrame frame2 = new JFrame("show image");
        frame2.setTitle("從 webcam 讀 讀 讀 讀");
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame2.setSize(640, 480);
        frame2.setBounds(160, 0, frame1.getWidth(), frame1.getHeight());
        Panel panel2 = new Panel();
        frame2.setContentPane(panel2);
        frame2.setVisible(true);

        JFrame frame3 = new JFrame("show image");
        frame3.setTitle("從 webcam 讀 讀 讀 讀");
        frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame3.setSize(640, 480);
        frame3.setBounds(280, 0, frame1.getWidth(), frame1.getHeight());
        Panel panel3 = new Panel();
        frame3.setContentPane(panel3);
        frame3.setVisible(true);
        if (!capture.isOpened()) {
            System.out.println("Error");
        } else {
            Mat webcam_image = new Mat();


            capture.read(webcam_image);
            frame1.setSize(webcam_image.width() + 40,webcam_image.height() + 60);
            frame2.setSize(webcam_image.width() + 50,webcam_image.height() + 70);
            frame3.setSize(webcam_image.width() + 60,webcam_image.height() + 80);
            while (true) {
                capture.read(webcam_image);
                //System.out.println("從 webcam 讀 讀 讀 讀 讀");

                Mat stylizationResult1=new Mat();
                Mat stylizationResult2=new Mat();

                Photo.stylization(webcam_image,stylizationResult1,50.0f,0.1f);
                Photo.stylization(webcam_image,stylizationResult2,200.0f,0.7f);

                panel1.setimagewithMat(webcam_image);
                panel2.setimagewithMat(stylizationResult1);
                panel3.setimagewithMat(stylizationResult2);
                frame1.repaint();
                frame2.repaint();
                frame3.repaint();
            }
        }
    }
}
Result
![擷取1.JPG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/276243/95782a39-a230-40d3-57f2-4fe735e8d8e8.jpeg) ![擷取2.JPG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/276243/dc62f239-8f9b-9706-60fe-2be08c225226.jpeg) ![擷取3.JPG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/276243/bbad84c7-82c2-75ae-3049-2209bd7493d1.jpeg)

Recommended Posts

Bureau: OpenCV Show Stylisation par WebCam
Bureau: OpenCV FaceDetector par WebCam
Bureau: OpenCV Trouver les coins de l'échiquier par WebCam
Bureau: OpenCV Trouver les coins de l'échiquier par WebCam
Bureau: aperçu de la webcam Opencv
Bureau: Tutoriel de prévisualisation de la webcam OpenCV
Bureau: OpenCV Subdiv2d Make Delaunay For Face By WebCam
Bureau: vérification du rectangle OpenCV à l'intérieur par ClipLine
Bureau: seuil OpenCV
Bureau: OpenCV Dilate
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: 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 Draw Circle
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: Gui afficher l'image
Bureau: Piano virtuel OpenCV
Bureau: image de fusion OpenCV
Bureau: Filtre OpenCV Scharr
Bureau: Filtre laplacien OpenCV
Bureau: Flou médian OpenCV