[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 讀 image image to Java Swing window 1");
        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 讀 image image to Java Swing window 2");
        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 讀 image image to Java Swing window 2");
        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 讀 image image to Java Swing window");

                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 By WebCam
Desktop: OpenCV Find Chessboard Corners By WebCam
Desktop: OpenCV Find Chessboard Corners By WebCam
Desktop: Opencv webcam preview
Desktop: OpenCV webcam preview tutorial
Desktop: OpenCV Subdiv2d Make Delaunay For Face By WebCam
Desktop: OpenCV Rectangle Check Inside By ClipLine
Desktop: OpenCV Threshold
Desktop: OpenCV Dilate
Desktop: OpenCV Expand
Desktop: OpenCV Affine
Desktop: OpenCV Emboss
Desktop: OpenCV CLAHE
Desktop: OpenCV Ellipse2Poly
Desktop: OpenCV HDR
Desktop: OpenCV Polylines
Desktop: OpenCV Denoise
Desktop: OpenCV Sharpness
Desktop: OpenCV Concat
Desktop: OpenCV OpenCV_SalonUseBlurAddWeighted
Desktop: OpenCV Mosaic
Desktop: OpenCV Erode
Desktop: OpenCV Denoise
Desktop: OpenCV Rectangle
Desktop: OpenCV Watershed
Desktop: OpenCV Text
Desktop: OpenCV Inpaint
Desktop: OpenCV NormalizeBlur
Desktop: OpenCV StereoSGBM
Desktop: OpenCV Spot
Desktop: OpenCV Canny
Desktop: OpenCV Denoise3
Desktop: OpenCV Histogram
Desktop: OpenCV Dft
Desktop: OpenCV Decolor
Desktop: OpenCV FaceDetector
Desktop: OpenCV Denoise2
Desktop: OpenCV StereoBM
Desktop: OpenCV Kirsch Filter
Desktop: OpenCV Laplacian Filter 2
Desktop: OpenCV Add WaterMark
Desktop: OpenCV Fill ConvexPoly
Desktop: OpenCV Grab Cut
Desktop: OpenCV Sharpness Gui
Desktop: OpenCV Color Change
Desktop: OpenCV Freichennel Filter
Desktop: OpenCV Adaptive Threshold
Desktop: OpenCV Draw Circle
Desktop: OpenCV Fill Poly
Desktop: OpenCV Mean Filter
Desktop: OpenCV Java Repository
Desktop: OpenCV Sobel Filter2
Desktop: OpenCV pyrMeanShift Filter
Desktop: OpenCV OpticalFlow PyrLK
Desktop: Gui show image
Desktop: OpenCV Virtual Piano
Desktop: OpenCV merge Picture
Desktop: OpenCV Scharr Filter
Desktop: OpenCV Laplacian Filter
Desktop: OpenCV Median Blur