open video file with opencv java

前端 未结 4 806
北荒
北荒 2020-12-31 22:29

so there is OpenCV for Java now...! Can anyone tell me how to open Videofiles with it ?

I tryed and look all over the internet, but found nothing. The documentation

4条回答
  •  庸人自扰
    2020-12-31 22:56

    here is an example :

        public static void main(String[] args) {
        Mat frame = new Mat();
        VideoCapture camera = new VideoCapture("C:/Users/SAAD/Desktop/motion.mp4");
        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();
    
            }
        }
    }`
    

    if you are using Windows add C:\opencv\build\x86\vc11\bin to the Path variable

提交回复
热议问题