What is the best method to capture images from a live video device for use by a Java-based application?

前端 未结 6 1210
南笙
南笙 2020-11-28 21:56

I am looking into an image processing problem for semi-real time detection of certain scenarios. My goal is to have the live video arrive as Motion JPEG frames in my Java c

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 22:15

    Below is shown a very simple implementation using Marvin Framework. Using Marvin you can add real time video processing easily.

    import javax.swing.JFrame;
    import marvin.gui.MarvinImagePanel;
    import marvin.image.MarvinImage;
    import marvin.video.MarvinJavaCVAdapter;
    import marvin.video.MarvinVideoInterface;
    
    public class SimpleVideoTest extends JFrame implements Runnable{
    
        private MarvinVideoInterface    videoAdapter;
        private MarvinImage             image;
        private MarvinImagePanel        videoPanel;
    
        public SimpleVideoTest(){
            super("Simple Video Test");
    
            // Create the VideoAdapter and connect to the camera
            videoAdapter = new MarvinJavaCVAdapter();
            videoAdapter.connect(0);
    
            // Create VideoPanel
            videoPanel = new MarvinImagePanel();
            add(videoPanel);
    
            // Start the thread for requesting the video frames 
            new Thread(this).start();
    
            setSize(800,600);
            setVisible(true);
        }
    
        public static void main(String[] args) {
            SimpleVideoTest t = new SimpleVideoTest();
            t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    
        @Override
        public void run() {
            while(true){
                // Request a video frame and set into the VideoPanel
                image = videoAdapter.getFrame();
                videoPanel.setImage(image);
            }
        }
    }
    

    Another example applying multiple algorithms for real time video processing.

提交回复
热议问题