[JAVA] Desktop: OpenCV Show Stylization By 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("從 Webcam 讀 讀 讀 讀 讀");
        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

Desktop: OpenCV Show Stylization By WebCam
Desktop: OpenCV FaceDetector von WebCam
Desktop: OpenCV Find Chessboard Corners von WebCam
Desktop: OpenCV Find Chessboard Corners von WebCam
Desktop: Opencv-Webcam-Vorschau
Desktop: OpenCV-Webcam-Vorschau-Tutorial
Desktop: OpenCV Subdiv2d Machen Sie Delaunay für Face By WebCam
Desktop: OpenCV Rectangle Check Inside von ClipLine
Desktop: OpenCV-Schwellenwert
Desktop: OpenCV Dilate
Desktop: OpenCV-Erweiterung
Desktop: OpenCV Affine
Desktop: OpenCV Emboss
Desktop: OpenCV CLAHE
Desktop: OpenCV Ellipse2Poly
Desktop: OpenCV HDR
Desktop: OpenCV-Polylinien
Desktop: OpenCV Denoise
Desktop: OpenCV-Schärfe
Desktop: OpenCV Concat
Desktop: OpenCV OpenCV_SalonUseBlurAddWeighted
Desktop: OpenCV-Mosaik
Desktop: OpenCV Erode
Desktop: OpenCV Denoise
Desktop: OpenCV-Rechteck
Desktop: OpenCV-Wasserscheide
Desktop: OpenCV-Text
Desktop: OpenCV Inpaint
Desktop: OpenCV NormalizeBlur
Desktop: OpenCV StereoSGBM
Desktop: OpenCV Spot
Desktop: OpenCV Canny
Desktop: OpenCV Denoise3
Desktop: OpenCV-Histogramm
Desktop: OpenCV Dft
Desktop: OpenCV Decolor
Desktop: OpenCV FaceDetector
Desktop: OpenCV Denoise2
Desktop: OpenCV StereoBM
Desktop: OpenCV Kirsch Filter
Desktop: OpenCV Laplace Filter 2
Desktop: OpenCV WaterMark hinzufügen
Desktop: OpenCV Fill ConvexPoly
Desktop: OpenCV Grab Cut
Desktop: OpenCV Sharpness Gui
Desktop: OpenCV-Farbänderung
Desktop: OpenCV Freichennel Filter
Desktop: OpenCV Adaptive Threshold
Desktop: OpenCV-Zeichnungskreis
Desktop: OpenCV Fill Poly
Desktop: OpenCV-Mittelwertfilter
Desktop: OpenCV Java Repository
Desktop: OpenCV Sobel Filter2
Desktop: OpenCV pyrMeanShift Filter
Desktop: OpenCV OpticalFlow PyrLK
Desktop: GUI-Showbild
Desktop: OpenCV Virtual Piano
Desktop: OpenCV-Bild zusammenführen
Desktop: OpenCV Scharr Filter
Desktop: OpenCV-Laplace-Filter
Desktop: OpenCV Median Blur