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

前端 未结 6 1169
南笙
南笙 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条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 22:11

    This JavaCV implementation works fine.

    CODE:

    import com.googlecode.javacv.OpenCVFrameGrabber;
    
    import com.googlecode.javacv.cpp.opencv_core.IplImage;
    import static com.googlecode.javacv.cpp.opencv_highgui.*;
    
    public class CaptureImage {
        private static void captureFrame() {
            // 0-default camera, 1 - next...so on
            final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
            try {
                grabber.start();
                IplImage img = grabber.grab();
                if (img != null) {
                    cvSaveImage("capture.jpg", img);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        public static void main(String[] args) {
            captureFrame();
        }
    }
    

    There is also post on viewing live video from Camera .And configuration for JavaCV :

    I think this will meet your requirements.

提交回复
热议问题