1

I'm developing a Java desktop application and can not find a way to record webcam video. I began using the Sarxos library to detect the connected cameras and to preview any you choose. But to get to the part of video recording in the example Xuggler is used, which is deprecated and not even you can download .. Somewhere I read that uses Humble-video, but the only example we have is to record screen, no camera ... Any help to find the way will be appreciated.

PS: I'm using JavaFX but if necessary I switch to Swing

Ian
  • 1,221
  • 1
  • 18
  • 30
Maximiliano Sosa
  • 388
  • 1
  • 7
  • 18

1 Answers1

0

This is a JavaCV implementation which maybe can help you:

    import static com.googlecode.javacv.cpp.opencv_core.cvFlip;
    import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;

    import com.googlecode.javacv.CanvasFrame;
    import com.googlecode.javacv.FrameGrabber;
    import com.googlecode.javacv.VideoInputFrameGrabber;
    import com.googlecode.javacv.cpp.opencv_core.IplImage;
    public class GrabberShow implements Runnable {
        //final int INTERVAL=1000;///you may use interval
        IplImage image;
        CanvasFrame canvas = new CanvasFrame("Web Cam");
        public GrabberShow() {
            canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        }
        @Override
        public void run() {
            FrameGrabber grabber = new VideoInputFrameGrabber(0); 
            int i=0;
            try {
                grabber.start();
                IplImage img;
                while (true) {
                    img = grabber.grab();
                    if (img != null) {
                        cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise
                        cvSaveImage((i++)+"-capture.jpg", img);
                        // show image on window
                        canvas.showImage(img);
                    }
                     //Thread.sleep(INTERVAL);
                }
            } catch (Exception e) {
            }


}
}

You can modify the codes and be able to save the images in regular interval and do rest of the processing you want.

And here you can find another tutorial what could also be an option: Java Swing Program for capturing webcam

Mario J.G.
  • 74
  • 12
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Ivar Oct 13 '16 at 13:36
  • You have reason, but I don't understand how I should have given him then that links on the right way. I mean due to my english, I can't understand your comment completely. Thanks for your tip – Mario J.G. Oct 13 '16 at 13:39
  • On Stack Overflow, answers which only contains links are usually deleted, because if the link dies, the answer is useless. Also people like to see the answer directly and not have to click on links first. In your case, if all the links will stop working, your answer will have no value at all. Therefore it is better add the important parts of the link to the answer so it is still valuable if the links would be removed. – Ivar Oct 13 '16 at 13:49
  • I understand, it makes sense. Maybe you can add this link like a comment (I can't due to my rep.): http://tricksmode.com/2013/03/How-To-Capture-Webcam-Images-In-Java-Swings.html Maybe it helps him. Then I will delete my answer. Thanks for your help :) – Mario J.G. Oct 13 '16 at 13:53
  • I'm still very new in SO and I see often links in another answers which are also accepted, so I'm still not pretty sure in which situations I can make it. Thanks for the comments, I'm learning of it. – Mario J.G. Oct 13 '16 at 14:30
  • Thank you! As soon as I can try and have something working, I'll come back with feedback – Maximiliano Sosa Oct 13 '16 at 15:06