使用 VideoCapture 与 OpenCV Java

java 中没有 imshow,你需要为此编写一个方法。此方法是 Mat2bufferedImage。将 mat 对象作为参数并返回图像。

public static void main(String[] args) {
    Mat frame = new Mat();
    //0; default video device id
    VideoCapture camera = new VideoCapture(0);
    JFrame jframe = new JFrame("Title");
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel vidpanel = new JLabel();
    jframe.setContentPane(vidpanel);
    jframe.setVisible(true);

    while (true) {
        if (camera.read(frame)) {

            ImageIcon image = new ImageIcon(Mat2bufferedImage(frame));
            vidpanel.setIcon(image);
            vidpanel.repaint();

        }
    }
}