Desktop : Opencv webcam preview
Goal
Show Camera Preview
OpenCV_webcam3.java
import javax.swing.JFrame;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;
public class OpenCV_webcam3 {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
VideoCapture camera = null;
camera = initWebcam();
JFrame frame1 = new JFrame("Show image");
frame1.setTitle("從 webcam 讀取影像到 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);
if(camera.isOpened()) {
Mat webcam_frame = new Mat();
camera.read(webcam_frame);
frame1.setSize(webcam_frame.width(),webcam_frame.height());
while (true) {
camera.read(webcam_frame);
panel1.setimagewithMat(webcam_frame);
frame1.repaint();
}
}else {
System.out.print("Error");
}
}
private static VideoCapture initWebcam() {
VideoCapture cameraCapture = new VideoCapture();
cameraCapture.open(0);
return cameraCapture;
}
}
Result
Author And Source
この問題について(Desktop : Opencv webcam preview), 我々は、より多くの情報をここで見つけました https://qiita.com/kangyueluo777/items/841616ce1f9f72eb79e8著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .