Capturing image from webcam in java?

Multi tool use
Multi tool use












78















How can I continuously capture images from a webcam?



I want to experiment with object recognition (by maybe using java media framework).



I was thinking of creating two threads



one thread:




  • Node 1: capture live image

  • Node 2: save image as "1.jpg"

  • Node 3: wait 5 seconds

  • Node 4: repeat...


other thread:




  • Node 1: wait until image is captured

  • Node 2: using the "1.jpg" get colors
    from every pixle

  • Node 3: save data in arrays

  • Node 4: repeat...










share|improve this question


















  • 2





    Here is your answer-- Java Swing program to capture images from webcam tutorial Slightly modify it and youre done..

    – Aman
    Mar 25 '13 at 19:44
















78















How can I continuously capture images from a webcam?



I want to experiment with object recognition (by maybe using java media framework).



I was thinking of creating two threads



one thread:




  • Node 1: capture live image

  • Node 2: save image as "1.jpg"

  • Node 3: wait 5 seconds

  • Node 4: repeat...


other thread:




  • Node 1: wait until image is captured

  • Node 2: using the "1.jpg" get colors
    from every pixle

  • Node 3: save data in arrays

  • Node 4: repeat...










share|improve this question


















  • 2





    Here is your answer-- Java Swing program to capture images from webcam tutorial Slightly modify it and youre done..

    – Aman
    Mar 25 '13 at 19:44














78












78








78


59






How can I continuously capture images from a webcam?



I want to experiment with object recognition (by maybe using java media framework).



I was thinking of creating two threads



one thread:




  • Node 1: capture live image

  • Node 2: save image as "1.jpg"

  • Node 3: wait 5 seconds

  • Node 4: repeat...


other thread:




  • Node 1: wait until image is captured

  • Node 2: using the "1.jpg" get colors
    from every pixle

  • Node 3: save data in arrays

  • Node 4: repeat...










share|improve this question














How can I continuously capture images from a webcam?



I want to experiment with object recognition (by maybe using java media framework).



I was thinking of creating two threads



one thread:




  • Node 1: capture live image

  • Node 2: save image as "1.jpg"

  • Node 3: wait 5 seconds

  • Node 4: repeat...


other thread:




  • Node 1: wait until image is captured

  • Node 2: using the "1.jpg" get colors
    from every pixle

  • Node 3: save data in arrays

  • Node 4: repeat...







java image webcam capture






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 '08 at 18:42









Divide By ZeroDivide By Zero

391143




391143








  • 2





    Here is your answer-- Java Swing program to capture images from webcam tutorial Slightly modify it and youre done..

    – Aman
    Mar 25 '13 at 19:44














  • 2





    Here is your answer-- Java Swing program to capture images from webcam tutorial Slightly modify it and youre done..

    – Aman
    Mar 25 '13 at 19:44








2




2





Here is your answer-- Java Swing program to capture images from webcam tutorial Slightly modify it and youre done..

– Aman
Mar 25 '13 at 19:44





Here is your answer-- Java Swing program to capture images from webcam tutorial Slightly modify it and youre done..

– Aman
Mar 25 '13 at 19:44












16 Answers
16






active

oldest

votes


















44














This JavaCV implementation works fine.



Code:



import org.bytedeco.javacv.*;

import static org.bytedeco.javacpp.opencv_core.IplImage;
import static org.bytedeco.javacpp.opencv_core.cvFlip;
import static org.bytedeco.javacpp.opencv_imgcodecs.cvSaveImage;


/**
* Created by gtiwari on 1/3/2017.
*/

public class Test implements Runnable {
final int INTERVAL = 100;///you may use interval
CanvasFrame canvas = new CanvasFrame("Web Cam");

public Test() {
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}

public void run() {

FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera
OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
IplImage img;
int i = 0;
try {
grabber.start();
while (true) {
Frame frame = grabber.grab();

img = converter.convert(frame);

//the grabbed frame will be flipped, re-flip to make it right
cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise

//save
cvSaveImage((i++) + "-aa.jpg", img);

canvas.showImage(converter.convert(img));

Thread.sleep(INTERVAL);
}
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String args) {
Test gs = new Test();
Thread th = new Thread(gs);
th.start();
}
}


There is also post on configuration for JavaCV



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






share|improve this answer





















  • 4





    +1 You rock! I was looking for a good open source and supported alternative to JMF for webcam captures in both Windows and Linux. This works like a charm! Thank you :)

    – maple_shaft
    Feb 21 '12 at 18:38






  • 2





    Doesn't work for me, it says Exception in thread "main" java.lang.UnsatisfiedLinkError: C:UserssteveAppDataLocalTempjavacpp213892357885346jniopencv_core.dll: Can't find dependent libraries

    – Stepan Yakovenko
    Sep 19 '12 at 20:03











  • This will work, but the video quality isn't as good as it should be. See my answer for better video output quality.

    – syb0rg
    Apr 12 '13 at 22:47











  • Thank you for the suggestion. I am interested how to set it on Windows? Do I need the 3Gb extracted zip? Otherwise my program, using JavaCV on Linux works fine.

    – Ilian Zapryanov
    Dec 13 '13 at 18:40











  • @StepanYakovenko you need OpenCV installed.

    – Matthieu
    Apr 23 '18 at 13:04



















29














Some time ago I've created generic Java library which can be used to take pictures with a PC webcam. The API is very simple, not overfeatured, can work standalone, but also supports additional webcam drivers like OpenIMAJ, JMF, FMJ, LTI-CIVIL, etc, and some IP cameras.



Link to the project is https://github.com/sarxos/webcam-capture



Example code (take picture and save in test.jpg):



Webcam webcam = Webcam.getDefault();
webcam.open();
BufferedImage image = webcam.getImage();
ImageIO.write(image, "JPG", new File("test.jpg"));


It is also available in Maven Central Repository or as a separate ZIP which includes all required dependencies and 3rd party JARs.






share|improve this answer





















  • 1





    For ease of getting started this is well worth a look. The code worked great for me, hopefully you also :)

    – mrswadge
    Jul 25 '13 at 19:49











  • @Bartosz Firyn : hello I am working with your API. awesome work man!but now I want to know that if zooming in camera supported or not? how to zoom camera using this API?

    – Java Man
    Dec 1 '14 at 5:52











  • @JavaMan, there is no native support for zooming.

    – Bartosz Firyn
    Dec 1 '14 at 14:50






  • 2





    @JavaMan, you can draw either on the panel that display view from camera (WebcamPanel) by setting your custom Painter instance, or directly on the image that comes from camera by using WebcamImageTransformer feature. For more details please open the ticket on the Webcam Capture project page on Github since I do not want to explain this in details here on Stack Overflow (too much to write and too few characters to use in comments). The project can be found here github.com/sarxos/webcam-capture

    – Bartosz Firyn
    Dec 2 '14 at 9:36






  • 1





    @Elyas Hadizadeh, in case of problems you can always create new issue ticket at github.com/sarxos/webcam-capture where you can also find documentation and examples. Please also bear in mind that this is framework for people rather familiar with Java. In case you are Java newby there are also people willing to help, but you have to learn basics on your own.

    – Bartosz Firyn
    Apr 23 '15 at 14:38





















7














JMyron is very simple for use.
http://webcamxtra.sourceforge.net/



myron = new JMyron();
myron.start(imgw, imgh);
myron.update();
int img = myron.image();





share|improve this answer































    5














    Here is a similar question with some - yet unaccepted - answers. One of them mentions FMJ as a java alternative to JMF.






    share|improve this answer

































      5














      This kind of goes off of gt_ebuddy's answer using JavaCV, but my video output is at a much higher quality then his answer. I've also added some other random improvements (such as closing down the program when ESC and CTRL+C are pressed, and making sure to close down the resources the program uses properly).



      import java.awt.event.ActionEvent;
      import java.awt.event.KeyEvent;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import java.awt.image.BufferedImage;

      import javax.swing.AbstractAction;
      import javax.swing.ActionMap;
      import javax.swing.InputMap;
      import javax.swing.JComponent;
      import javax.swing.JFrame;
      import javax.swing.KeyStroke;

      import com.googlecode.javacv.CanvasFrame;
      import com.googlecode.javacv.OpenCVFrameGrabber;
      import com.googlecode.javacv.cpp.opencv_core.IplImage;

      public class HighRes extends JComponent implements Runnable {
      private static final long serialVersionUID = 1L;

      private static CanvasFrame frame = new CanvasFrame("Web Cam");
      private static boolean running = false;
      private static int frameWidth = 800;
      private static int frameHeight = 600;
      private static OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
      private static BufferedImage bufImg;

      public HighRes()
      {
      // setup key bindings
      ActionMap actionMap = frame.getRootPane().getActionMap();
      InputMap inputMap = frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

      for (Keys direction : Keys.values())
      {
      actionMap.put(direction.getText(), new KeyBinding(direction.getText()));
      inputMap.put(direction.getKeyStroke(), direction.getText());
      }

      frame.getRootPane().setActionMap(actionMap);
      frame.getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);

      // setup window listener for close action
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.addWindowListener(new WindowAdapter()
      {
      public void windowClosing(WindowEvent e)
      {
      stop();
      }
      });
      }

      public static void main(String... args)
      {
      HighRes webcam = new HighRes();
      webcam.start();
      }

      @Override
      public void run()
      {
      try
      {

      grabber.setImageWidth(frameWidth);
      grabber.setImageHeight(frameHeight);
      grabber.start();
      while (running)
      {

      final IplImage cvimg = grabber.grab();
      if (cvimg != null)
      {

      // cvFlip(cvimg, cvimg, 1); // mirror

      // show image on window
      bufImg = cvimg.getBufferedImage();
      frame.showImage(bufImg);
      }
      }
      grabber.stop();
      grabber.release();
      frame.dispose();
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }
      }

      public void start()
      {
      new Thread(this).start();
      running = true;
      }

      public void stop()
      {
      running = false;
      }

      private class KeyBinding extends AbstractAction {

      private static final long serialVersionUID = 1L;

      public KeyBinding(String text)
      {
      super(text);
      putValue(ACTION_COMMAND_KEY, text);
      }

      @Override
      public void actionPerformed(ActionEvent e)
      {
      String action = e.getActionCommand();
      if (action.equals(Keys.ESCAPE.toString()) || action.equals(Keys.CTRLC.toString())) stop();
      else System.out.println("Key Binding: " + action);
      }
      }
      }

      enum Keys
      {
      ESCAPE("Escape", KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)),
      CTRLC("Control-C", KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK)),
      UP("Up", KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)),
      DOWN("Down", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)),
      LEFT("Left", KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)),
      RIGHT("Right", KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));

      private String text;
      private KeyStroke keyStroke;

      Keys(String text, KeyStroke keyStroke)
      {
      this.text = text;
      this.keyStroke = keyStroke;
      }

      public String getText()
      {
      return text;
      }

      public KeyStroke getKeyStroke()
      {
      return keyStroke;
      }

      @Override
      public String toString()
      {
      return text;
      }
      }





      share|improve this answer

































        4














        You can try Java Webcam SDK library also.
        SDK demo applet is available at link.






        share|improve this answer



















        • 4





          this is not free

          – Bonus Kun
          Jul 9 '12 at 14:45



















        3














        I have used JMF on a videoconference application and it worked well on two laptops: one with integrated webcam and another with an old USB webcam. It requires JMF being installed and configured before-hand, but once you're done you can access the hardware via Java code fairly easily.






        share|improve this answer
























        • can you give me snippet code of your project?

          – Java D
          May 4 '13 at 6:14



















        3














        You can try Marvin Framework. It provides an interface to work with cameras. Moreover, it also provides a set of real-time video processing features, like object tracking and filtering.



        Take a look!



        Real-time Video Processing Demo:
        http://www.youtube.com/watch?v=D5mBt0kRYvk



        You can use the source below. Just save a frame using MarvinImageIO.saveImage() every 5 second.



        Webcam video demo:



        public class SimpleVideoTest extends JFrame implements Runnable{

        private MarvinVideoInterface videoAdapter;
        private MarvinImage image;
        private MarvinImagePanel videoPanel;

        public SimpleVideoTest(){
        super("Simple Video Test");
        videoAdapter = new MarvinJavaCVAdapter();
        videoAdapter.connect(0);
        videoPanel = new MarvinImagePanel();
        add(videoPanel);
        new Thread(this).start();
        setSize(800,600);
        setVisible(true);
        }
        @Override
        public void run() {
        while(true){
        // Request a video frame and set into the VideoPanel
        image = videoAdapter.getFrame();
        videoPanel.setImage(image);
        }
        }
        public static void main(String args) {
        SimpleVideoTest t = new SimpleVideoTest();
        t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
        }


        For those who just want to take a single picture:



        WebcamPicture.java



        public class WebcamPicture {
        public static void main(String args) {
        try{
        MarvinVideoInterface videoAdapter = new MarvinJavaCVAdapter();
        videoAdapter.connect(0);
        MarvinImage image = videoAdapter.getFrame();
        MarvinImageIO.saveImage(image, "./res/webcam_picture.jpg");
        } catch(MarvinVideoInterfaceException e){
        e.printStackTrace();
        }
        }
        }





        share|improve this answer

































          2














          http://grack.com/downloads/school/enel619.10/report/java_media_framework.html



          Using the Player with Swing



          The Player can be easily used in a Swing application as well. The following code creates a Swing-based TV capture program with the video output displayed in the entire window:



          import javax.media.*;
          import javax.swing.*;
          import java.awt.*;
          import java.net.*;
          import java.awt.event.*;
          import javax.swing.event.*;

          public class JMFTest extends JFrame {
          Player _player;
          JMFTest() {
          addWindowListener( new WindowAdapter() {
          public void windowClosing( WindowEvent e ) {
          _player.stop();
          _player.deallocate();
          _player.close();
          System.exit( 0 );
          }
          });
          setExtent( 0, 0, 320, 260 );
          JPanel panel = (JPanel)getContentPane();
          panel.setLayout( new BorderLayout() );
          String mediaFile = "vfw://1";
          try {
          MediaLocator mlr = new MediaLocator( mediaFile );
          _player = Manager.createRealizedPlayer( mlr );
          if (_player.getVisualComponent() != null)
          panel.add("Center", _player.getVisualComponent());
          if (_player.getControlPanelComponent() != null)
          panel.add("South", _player.getControlPanelComponent());
          }
          catch (Exception e) {
          System.err.println( "Got exception " + e );
          }
          }

          public static void main(String args) {
          JMFTest jmfTest = new JMFTest();
          jmfTest.show();
          }
          }





          share|improve this answer

































            2














            I used Webcam Capture API...u can download from this http://webcam-capture.sarxos.pl/



                    webcam = Webcam.getDefault();
            webcam.open();

            if (webcam.isOpen()) { //if web cam open
            BufferedImage image = webcam.getImage();
            JLabel imageLbl = new JLabel();
            imageLbl.setSize(640, 480); //show captured image
            imageLbl.setIcon(new ImageIcon(image));

            int showConfirmDialog = JOptionPane.showConfirmDialog(null, imageLbl, "Image Viewer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(""));

            if (showConfirmDialog == JOptionPane.YES_OPTION) {
            JFileChooser chooser = new JFileChooser();
            chooser.setDialogTitle("Save Image");
            chooser.setFileFilter(new FileNameExtensionFilter("IMAGES ONLY", "png", "jpeg", "jpg")); //this file extentions are shown
            int showSaveDialog = chooser.showSaveDialog(this);
            if (showSaveDialog == 0) { //if pressed 'Save' button
            String filePath = chooser.getCurrentDirectory().toString().replace("\", "/");
            String fileName = chooser.getSelectedFile().getName(); //get user entered file name to save
            ImageIO.write(image, "PNG", new File(filePath + "/" + fileName + ".png"));

            }
            }
            }





            share|improve this answer


























            • You should provide some explanation along with the code

              – fen1x
              Sep 10 '17 at 21:17











            • thanks. it's light and instead javacv this one works for me.

              – Lucke
              Oct 29 '18 at 18:52



















            1














            Java usually doesn't like accessing hardware, so you will need a driver program of some sort, as goldenmean said. I've done this on my laptop by finding a command line program that snaps a picture. Then it's the same as goldenmean explained; you run the command line program from your java program in the takepicture() routine, and the rest of your code runs the same.



            Except for the part about reading pixel values into an array, you might be better served by saving the file to BMP, which is nearly that format already, then using the standard java image libraries on it.



            Using a command line program adds a dependency to your program and makes it less portable, but so was the webcam, right?






            share|improve this answer































              0














              I believe the web-cam application software which comes along with the web-cam, or you native windows webcam software can be run in a batch script(windows/dos script) after turning the web cam on(i.e. if it needs an external power supply). In the bacth script , u can add appropriate delay to capture after certain time period. And keep executing the capture command in loop.



              I guess this should be possible



              -AD






              share|improve this answer































                0














                There's a pretty nice interface for this in processing, which is kind of a pidgin java designed for graphics. It gets used in some image recognition work, such as that link.



                Depending on what you need out of it, you might be able to load the video library that's used there in java, or if you're just playing around with it you might be able to get by using processing itself.






                share|improve this answer































                  0














                  FMJ can do this, as can the supporting library it uses, LTI-CIVIL. Both are on sourceforge.






                  share|improve this answer































                    0














                    Recommand using FMJ for multimedia relatived java app.






                    share|improve this answer































                      0














                      Try using JMyron How To Use Webcam Using Java. I think using JMyron is the easiest way to access a webcam using java. I tried to use it with a 64-bit processor, but it gave me an error. It worked just fine on a 32-bit processor, though.






                      share|improve this answer

























                        Your Answer






                        StackExchange.ifUsing("editor", function () {
                        StackExchange.using("externalEditor", function () {
                        StackExchange.using("snippets", function () {
                        StackExchange.snippets.init();
                        });
                        });
                        }, "code-snippets");

                        StackExchange.ready(function() {
                        var channelOptions = {
                        tags: "".split(" "),
                        id: "1"
                        };
                        initTagRenderer("".split(" "), "".split(" "), channelOptions);

                        StackExchange.using("externalEditor", function() {
                        // Have to fire editor after snippets, if snippets enabled
                        if (StackExchange.settings.snippets.snippetsEnabled) {
                        StackExchange.using("snippets", function() {
                        createEditor();
                        });
                        }
                        else {
                        createEditor();
                        }
                        });

                        function createEditor() {
                        StackExchange.prepareEditor({
                        heartbeatType: 'answer',
                        autoActivateHeartbeat: false,
                        convertImagesToLinks: true,
                        noModals: true,
                        showLowRepImageUploadWarning: true,
                        reputationToPostImages: 10,
                        bindNavPrevention: true,
                        postfix: "",
                        imageUploader: {
                        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                        allowUrls: true
                        },
                        onDemand: true,
                        discardSelector: ".discard-answer"
                        ,immediatelyShowMarkdownHelp:true
                        });


                        }
                        });














                        draft saved

                        draft discarded


















                        StackExchange.ready(
                        function () {
                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f276292%2fcapturing-image-from-webcam-in-java%23new-answer', 'question_page');
                        }
                        );

                        Post as a guest















                        Required, but never shown

























                        16 Answers
                        16






                        active

                        oldest

                        votes








                        16 Answers
                        16






                        active

                        oldest

                        votes









                        active

                        oldest

                        votes






                        active

                        oldest

                        votes









                        44














                        This JavaCV implementation works fine.



                        Code:



                        import org.bytedeco.javacv.*;

                        import static org.bytedeco.javacpp.opencv_core.IplImage;
                        import static org.bytedeco.javacpp.opencv_core.cvFlip;
                        import static org.bytedeco.javacpp.opencv_imgcodecs.cvSaveImage;


                        /**
                        * Created by gtiwari on 1/3/2017.
                        */

                        public class Test implements Runnable {
                        final int INTERVAL = 100;///you may use interval
                        CanvasFrame canvas = new CanvasFrame("Web Cam");

                        public Test() {
                        canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
                        }

                        public void run() {

                        FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera
                        OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
                        IplImage img;
                        int i = 0;
                        try {
                        grabber.start();
                        while (true) {
                        Frame frame = grabber.grab();

                        img = converter.convert(frame);

                        //the grabbed frame will be flipped, re-flip to make it right
                        cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise

                        //save
                        cvSaveImage((i++) + "-aa.jpg", img);

                        canvas.showImage(converter.convert(img));

                        Thread.sleep(INTERVAL);
                        }
                        } catch (Exception e) {
                        e.printStackTrace();
                        }
                        }

                        public static void main(String args) {
                        Test gs = new Test();
                        Thread th = new Thread(gs);
                        th.start();
                        }
                        }


                        There is also post on configuration for JavaCV



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






                        share|improve this answer





















                        • 4





                          +1 You rock! I was looking for a good open source and supported alternative to JMF for webcam captures in both Windows and Linux. This works like a charm! Thank you :)

                          – maple_shaft
                          Feb 21 '12 at 18:38






                        • 2





                          Doesn't work for me, it says Exception in thread "main" java.lang.UnsatisfiedLinkError: C:UserssteveAppDataLocalTempjavacpp213892357885346jniopencv_core.dll: Can't find dependent libraries

                          – Stepan Yakovenko
                          Sep 19 '12 at 20:03











                        • This will work, but the video quality isn't as good as it should be. See my answer for better video output quality.

                          – syb0rg
                          Apr 12 '13 at 22:47











                        • Thank you for the suggestion. I am interested how to set it on Windows? Do I need the 3Gb extracted zip? Otherwise my program, using JavaCV on Linux works fine.

                          – Ilian Zapryanov
                          Dec 13 '13 at 18:40











                        • @StepanYakovenko you need OpenCV installed.

                          – Matthieu
                          Apr 23 '18 at 13:04
















                        44














                        This JavaCV implementation works fine.



                        Code:



                        import org.bytedeco.javacv.*;

                        import static org.bytedeco.javacpp.opencv_core.IplImage;
                        import static org.bytedeco.javacpp.opencv_core.cvFlip;
                        import static org.bytedeco.javacpp.opencv_imgcodecs.cvSaveImage;


                        /**
                        * Created by gtiwari on 1/3/2017.
                        */

                        public class Test implements Runnable {
                        final int INTERVAL = 100;///you may use interval
                        CanvasFrame canvas = new CanvasFrame("Web Cam");

                        public Test() {
                        canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
                        }

                        public void run() {

                        FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera
                        OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
                        IplImage img;
                        int i = 0;
                        try {
                        grabber.start();
                        while (true) {
                        Frame frame = grabber.grab();

                        img = converter.convert(frame);

                        //the grabbed frame will be flipped, re-flip to make it right
                        cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise

                        //save
                        cvSaveImage((i++) + "-aa.jpg", img);

                        canvas.showImage(converter.convert(img));

                        Thread.sleep(INTERVAL);
                        }
                        } catch (Exception e) {
                        e.printStackTrace();
                        }
                        }

                        public static void main(String args) {
                        Test gs = new Test();
                        Thread th = new Thread(gs);
                        th.start();
                        }
                        }


                        There is also post on configuration for JavaCV



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






                        share|improve this answer





















                        • 4





                          +1 You rock! I was looking for a good open source and supported alternative to JMF for webcam captures in both Windows and Linux. This works like a charm! Thank you :)

                          – maple_shaft
                          Feb 21 '12 at 18:38






                        • 2





                          Doesn't work for me, it says Exception in thread "main" java.lang.UnsatisfiedLinkError: C:UserssteveAppDataLocalTempjavacpp213892357885346jniopencv_core.dll: Can't find dependent libraries

                          – Stepan Yakovenko
                          Sep 19 '12 at 20:03











                        • This will work, but the video quality isn't as good as it should be. See my answer for better video output quality.

                          – syb0rg
                          Apr 12 '13 at 22:47











                        • Thank you for the suggestion. I am interested how to set it on Windows? Do I need the 3Gb extracted zip? Otherwise my program, using JavaCV on Linux works fine.

                          – Ilian Zapryanov
                          Dec 13 '13 at 18:40











                        • @StepanYakovenko you need OpenCV installed.

                          – Matthieu
                          Apr 23 '18 at 13:04














                        44












                        44








                        44







                        This JavaCV implementation works fine.



                        Code:



                        import org.bytedeco.javacv.*;

                        import static org.bytedeco.javacpp.opencv_core.IplImage;
                        import static org.bytedeco.javacpp.opencv_core.cvFlip;
                        import static org.bytedeco.javacpp.opencv_imgcodecs.cvSaveImage;


                        /**
                        * Created by gtiwari on 1/3/2017.
                        */

                        public class Test implements Runnable {
                        final int INTERVAL = 100;///you may use interval
                        CanvasFrame canvas = new CanvasFrame("Web Cam");

                        public Test() {
                        canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
                        }

                        public void run() {

                        FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera
                        OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
                        IplImage img;
                        int i = 0;
                        try {
                        grabber.start();
                        while (true) {
                        Frame frame = grabber.grab();

                        img = converter.convert(frame);

                        //the grabbed frame will be flipped, re-flip to make it right
                        cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise

                        //save
                        cvSaveImage((i++) + "-aa.jpg", img);

                        canvas.showImage(converter.convert(img));

                        Thread.sleep(INTERVAL);
                        }
                        } catch (Exception e) {
                        e.printStackTrace();
                        }
                        }

                        public static void main(String args) {
                        Test gs = new Test();
                        Thread th = new Thread(gs);
                        th.start();
                        }
                        }


                        There is also post on configuration for JavaCV



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






                        share|improve this answer















                        This JavaCV implementation works fine.



                        Code:



                        import org.bytedeco.javacv.*;

                        import static org.bytedeco.javacpp.opencv_core.IplImage;
                        import static org.bytedeco.javacpp.opencv_core.cvFlip;
                        import static org.bytedeco.javacpp.opencv_imgcodecs.cvSaveImage;


                        /**
                        * Created by gtiwari on 1/3/2017.
                        */

                        public class Test implements Runnable {
                        final int INTERVAL = 100;///you may use interval
                        CanvasFrame canvas = new CanvasFrame("Web Cam");

                        public Test() {
                        canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
                        }

                        public void run() {

                        FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera
                        OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
                        IplImage img;
                        int i = 0;
                        try {
                        grabber.start();
                        while (true) {
                        Frame frame = grabber.grab();

                        img = converter.convert(frame);

                        //the grabbed frame will be flipped, re-flip to make it right
                        cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise

                        //save
                        cvSaveImage((i++) + "-aa.jpg", img);

                        canvas.showImage(converter.convert(img));

                        Thread.sleep(INTERVAL);
                        }
                        } catch (Exception e) {
                        e.printStackTrace();
                        }
                        }

                        public static void main(String args) {
                        Test gs = new Test();
                        Thread th = new Thread(gs);
                        th.start();
                        }
                        }


                        There is also post on configuration for JavaCV



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







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jan 3 '17 at 9:16

























                        answered Jan 28 '12 at 15:21









                        gtiwari333gtiwari333

                        15.9k136186




                        15.9k136186








                        • 4





                          +1 You rock! I was looking for a good open source and supported alternative to JMF for webcam captures in both Windows and Linux. This works like a charm! Thank you :)

                          – maple_shaft
                          Feb 21 '12 at 18:38






                        • 2





                          Doesn't work for me, it says Exception in thread "main" java.lang.UnsatisfiedLinkError: C:UserssteveAppDataLocalTempjavacpp213892357885346jniopencv_core.dll: Can't find dependent libraries

                          – Stepan Yakovenko
                          Sep 19 '12 at 20:03











                        • This will work, but the video quality isn't as good as it should be. See my answer for better video output quality.

                          – syb0rg
                          Apr 12 '13 at 22:47











                        • Thank you for the suggestion. I am interested how to set it on Windows? Do I need the 3Gb extracted zip? Otherwise my program, using JavaCV on Linux works fine.

                          – Ilian Zapryanov
                          Dec 13 '13 at 18:40











                        • @StepanYakovenko you need OpenCV installed.

                          – Matthieu
                          Apr 23 '18 at 13:04














                        • 4





                          +1 You rock! I was looking for a good open source and supported alternative to JMF for webcam captures in both Windows and Linux. This works like a charm! Thank you :)

                          – maple_shaft
                          Feb 21 '12 at 18:38






                        • 2





                          Doesn't work for me, it says Exception in thread "main" java.lang.UnsatisfiedLinkError: C:UserssteveAppDataLocalTempjavacpp213892357885346jniopencv_core.dll: Can't find dependent libraries

                          – Stepan Yakovenko
                          Sep 19 '12 at 20:03











                        • This will work, but the video quality isn't as good as it should be. See my answer for better video output quality.

                          – syb0rg
                          Apr 12 '13 at 22:47











                        • Thank you for the suggestion. I am interested how to set it on Windows? Do I need the 3Gb extracted zip? Otherwise my program, using JavaCV on Linux works fine.

                          – Ilian Zapryanov
                          Dec 13 '13 at 18:40











                        • @StepanYakovenko you need OpenCV installed.

                          – Matthieu
                          Apr 23 '18 at 13:04








                        4




                        4





                        +1 You rock! I was looking for a good open source and supported alternative to JMF for webcam captures in both Windows and Linux. This works like a charm! Thank you :)

                        – maple_shaft
                        Feb 21 '12 at 18:38





                        +1 You rock! I was looking for a good open source and supported alternative to JMF for webcam captures in both Windows and Linux. This works like a charm! Thank you :)

                        – maple_shaft
                        Feb 21 '12 at 18:38




                        2




                        2





                        Doesn't work for me, it says Exception in thread "main" java.lang.UnsatisfiedLinkError: C:UserssteveAppDataLocalTempjavacpp213892357885346jniopencv_core.dll: Can't find dependent libraries

                        – Stepan Yakovenko
                        Sep 19 '12 at 20:03





                        Doesn't work for me, it says Exception in thread "main" java.lang.UnsatisfiedLinkError: C:UserssteveAppDataLocalTempjavacpp213892357885346jniopencv_core.dll: Can't find dependent libraries

                        – Stepan Yakovenko
                        Sep 19 '12 at 20:03













                        This will work, but the video quality isn't as good as it should be. See my answer for better video output quality.

                        – syb0rg
                        Apr 12 '13 at 22:47





                        This will work, but the video quality isn't as good as it should be. See my answer for better video output quality.

                        – syb0rg
                        Apr 12 '13 at 22:47













                        Thank you for the suggestion. I am interested how to set it on Windows? Do I need the 3Gb extracted zip? Otherwise my program, using JavaCV on Linux works fine.

                        – Ilian Zapryanov
                        Dec 13 '13 at 18:40





                        Thank you for the suggestion. I am interested how to set it on Windows? Do I need the 3Gb extracted zip? Otherwise my program, using JavaCV on Linux works fine.

                        – Ilian Zapryanov
                        Dec 13 '13 at 18:40













                        @StepanYakovenko you need OpenCV installed.

                        – Matthieu
                        Apr 23 '18 at 13:04





                        @StepanYakovenko you need OpenCV installed.

                        – Matthieu
                        Apr 23 '18 at 13:04













                        29














                        Some time ago I've created generic Java library which can be used to take pictures with a PC webcam. The API is very simple, not overfeatured, can work standalone, but also supports additional webcam drivers like OpenIMAJ, JMF, FMJ, LTI-CIVIL, etc, and some IP cameras.



                        Link to the project is https://github.com/sarxos/webcam-capture



                        Example code (take picture and save in test.jpg):



                        Webcam webcam = Webcam.getDefault();
                        webcam.open();
                        BufferedImage image = webcam.getImage();
                        ImageIO.write(image, "JPG", new File("test.jpg"));


                        It is also available in Maven Central Repository or as a separate ZIP which includes all required dependencies and 3rd party JARs.






                        share|improve this answer





















                        • 1





                          For ease of getting started this is well worth a look. The code worked great for me, hopefully you also :)

                          – mrswadge
                          Jul 25 '13 at 19:49











                        • @Bartosz Firyn : hello I am working with your API. awesome work man!but now I want to know that if zooming in camera supported or not? how to zoom camera using this API?

                          – Java Man
                          Dec 1 '14 at 5:52











                        • @JavaMan, there is no native support for zooming.

                          – Bartosz Firyn
                          Dec 1 '14 at 14:50






                        • 2





                          @JavaMan, you can draw either on the panel that display view from camera (WebcamPanel) by setting your custom Painter instance, or directly on the image that comes from camera by using WebcamImageTransformer feature. For more details please open the ticket on the Webcam Capture project page on Github since I do not want to explain this in details here on Stack Overflow (too much to write and too few characters to use in comments). The project can be found here github.com/sarxos/webcam-capture

                          – Bartosz Firyn
                          Dec 2 '14 at 9:36






                        • 1





                          @Elyas Hadizadeh, in case of problems you can always create new issue ticket at github.com/sarxos/webcam-capture where you can also find documentation and examples. Please also bear in mind that this is framework for people rather familiar with Java. In case you are Java newby there are also people willing to help, but you have to learn basics on your own.

                          – Bartosz Firyn
                          Apr 23 '15 at 14:38


















                        29














                        Some time ago I've created generic Java library which can be used to take pictures with a PC webcam. The API is very simple, not overfeatured, can work standalone, but also supports additional webcam drivers like OpenIMAJ, JMF, FMJ, LTI-CIVIL, etc, and some IP cameras.



                        Link to the project is https://github.com/sarxos/webcam-capture



                        Example code (take picture and save in test.jpg):



                        Webcam webcam = Webcam.getDefault();
                        webcam.open();
                        BufferedImage image = webcam.getImage();
                        ImageIO.write(image, "JPG", new File("test.jpg"));


                        It is also available in Maven Central Repository or as a separate ZIP which includes all required dependencies and 3rd party JARs.






                        share|improve this answer





















                        • 1





                          For ease of getting started this is well worth a look. The code worked great for me, hopefully you also :)

                          – mrswadge
                          Jul 25 '13 at 19:49











                        • @Bartosz Firyn : hello I am working with your API. awesome work man!but now I want to know that if zooming in camera supported or not? how to zoom camera using this API?

                          – Java Man
                          Dec 1 '14 at 5:52











                        • @JavaMan, there is no native support for zooming.

                          – Bartosz Firyn
                          Dec 1 '14 at 14:50






                        • 2





                          @JavaMan, you can draw either on the panel that display view from camera (WebcamPanel) by setting your custom Painter instance, or directly on the image that comes from camera by using WebcamImageTransformer feature. For more details please open the ticket on the Webcam Capture project page on Github since I do not want to explain this in details here on Stack Overflow (too much to write and too few characters to use in comments). The project can be found here github.com/sarxos/webcam-capture

                          – Bartosz Firyn
                          Dec 2 '14 at 9:36






                        • 1





                          @Elyas Hadizadeh, in case of problems you can always create new issue ticket at github.com/sarxos/webcam-capture where you can also find documentation and examples. Please also bear in mind that this is framework for people rather familiar with Java. In case you are Java newby there are also people willing to help, but you have to learn basics on your own.

                          – Bartosz Firyn
                          Apr 23 '15 at 14:38
















                        29












                        29








                        29







                        Some time ago I've created generic Java library which can be used to take pictures with a PC webcam. The API is very simple, not overfeatured, can work standalone, but also supports additional webcam drivers like OpenIMAJ, JMF, FMJ, LTI-CIVIL, etc, and some IP cameras.



                        Link to the project is https://github.com/sarxos/webcam-capture



                        Example code (take picture and save in test.jpg):



                        Webcam webcam = Webcam.getDefault();
                        webcam.open();
                        BufferedImage image = webcam.getImage();
                        ImageIO.write(image, "JPG", new File("test.jpg"));


                        It is also available in Maven Central Repository or as a separate ZIP which includes all required dependencies and 3rd party JARs.






                        share|improve this answer















                        Some time ago I've created generic Java library which can be used to take pictures with a PC webcam. The API is very simple, not overfeatured, can work standalone, but also supports additional webcam drivers like OpenIMAJ, JMF, FMJ, LTI-CIVIL, etc, and some IP cameras.



                        Link to the project is https://github.com/sarxos/webcam-capture



                        Example code (take picture and save in test.jpg):



                        Webcam webcam = Webcam.getDefault();
                        webcam.open();
                        BufferedImage image = webcam.getImage();
                        ImageIO.write(image, "JPG", new File("test.jpg"));


                        It is also available in Maven Central Repository or as a separate ZIP which includes all required dependencies and 3rd party JARs.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jun 11 '15 at 8:01









                        Peter Walser

                        10.5k23655




                        10.5k23655










                        answered Nov 12 '12 at 16:51









                        Bartosz FirynBartosz Firyn

                        2,24511616




                        2,24511616








                        • 1





                          For ease of getting started this is well worth a look. The code worked great for me, hopefully you also :)

                          – mrswadge
                          Jul 25 '13 at 19:49











                        • @Bartosz Firyn : hello I am working with your API. awesome work man!but now I want to know that if zooming in camera supported or not? how to zoom camera using this API?

                          – Java Man
                          Dec 1 '14 at 5:52











                        • @JavaMan, there is no native support for zooming.

                          – Bartosz Firyn
                          Dec 1 '14 at 14:50






                        • 2





                          @JavaMan, you can draw either on the panel that display view from camera (WebcamPanel) by setting your custom Painter instance, or directly on the image that comes from camera by using WebcamImageTransformer feature. For more details please open the ticket on the Webcam Capture project page on Github since I do not want to explain this in details here on Stack Overflow (too much to write and too few characters to use in comments). The project can be found here github.com/sarxos/webcam-capture

                          – Bartosz Firyn
                          Dec 2 '14 at 9:36






                        • 1





                          @Elyas Hadizadeh, in case of problems you can always create new issue ticket at github.com/sarxos/webcam-capture where you can also find documentation and examples. Please also bear in mind that this is framework for people rather familiar with Java. In case you are Java newby there are also people willing to help, but you have to learn basics on your own.

                          – Bartosz Firyn
                          Apr 23 '15 at 14:38
















                        • 1





                          For ease of getting started this is well worth a look. The code worked great for me, hopefully you also :)

                          – mrswadge
                          Jul 25 '13 at 19:49











                        • @Bartosz Firyn : hello I am working with your API. awesome work man!but now I want to know that if zooming in camera supported or not? how to zoom camera using this API?

                          – Java Man
                          Dec 1 '14 at 5:52











                        • @JavaMan, there is no native support for zooming.

                          – Bartosz Firyn
                          Dec 1 '14 at 14:50






                        • 2





                          @JavaMan, you can draw either on the panel that display view from camera (WebcamPanel) by setting your custom Painter instance, or directly on the image that comes from camera by using WebcamImageTransformer feature. For more details please open the ticket on the Webcam Capture project page on Github since I do not want to explain this in details here on Stack Overflow (too much to write and too few characters to use in comments). The project can be found here github.com/sarxos/webcam-capture

                          – Bartosz Firyn
                          Dec 2 '14 at 9:36






                        • 1





                          @Elyas Hadizadeh, in case of problems you can always create new issue ticket at github.com/sarxos/webcam-capture where you can also find documentation and examples. Please also bear in mind that this is framework for people rather familiar with Java. In case you are Java newby there are also people willing to help, but you have to learn basics on your own.

                          – Bartosz Firyn
                          Apr 23 '15 at 14:38










                        1




                        1





                        For ease of getting started this is well worth a look. The code worked great for me, hopefully you also :)

                        – mrswadge
                        Jul 25 '13 at 19:49





                        For ease of getting started this is well worth a look. The code worked great for me, hopefully you also :)

                        – mrswadge
                        Jul 25 '13 at 19:49













                        @Bartosz Firyn : hello I am working with your API. awesome work man!but now I want to know that if zooming in camera supported or not? how to zoom camera using this API?

                        – Java Man
                        Dec 1 '14 at 5:52





                        @Bartosz Firyn : hello I am working with your API. awesome work man!but now I want to know that if zooming in camera supported or not? how to zoom camera using this API?

                        – Java Man
                        Dec 1 '14 at 5:52













                        @JavaMan, there is no native support for zooming.

                        – Bartosz Firyn
                        Dec 1 '14 at 14:50





                        @JavaMan, there is no native support for zooming.

                        – Bartosz Firyn
                        Dec 1 '14 at 14:50




                        2




                        2





                        @JavaMan, you can draw either on the panel that display view from camera (WebcamPanel) by setting your custom Painter instance, or directly on the image that comes from camera by using WebcamImageTransformer feature. For more details please open the ticket on the Webcam Capture project page on Github since I do not want to explain this in details here on Stack Overflow (too much to write and too few characters to use in comments). The project can be found here github.com/sarxos/webcam-capture

                        – Bartosz Firyn
                        Dec 2 '14 at 9:36





                        @JavaMan, you can draw either on the panel that display view from camera (WebcamPanel) by setting your custom Painter instance, or directly on the image that comes from camera by using WebcamImageTransformer feature. For more details please open the ticket on the Webcam Capture project page on Github since I do not want to explain this in details here on Stack Overflow (too much to write and too few characters to use in comments). The project can be found here github.com/sarxos/webcam-capture

                        – Bartosz Firyn
                        Dec 2 '14 at 9:36




                        1




                        1





                        @Elyas Hadizadeh, in case of problems you can always create new issue ticket at github.com/sarxos/webcam-capture where you can also find documentation and examples. Please also bear in mind that this is framework for people rather familiar with Java. In case you are Java newby there are also people willing to help, but you have to learn basics on your own.

                        – Bartosz Firyn
                        Apr 23 '15 at 14:38







                        @Elyas Hadizadeh, in case of problems you can always create new issue ticket at github.com/sarxos/webcam-capture where you can also find documentation and examples. Please also bear in mind that this is framework for people rather familiar with Java. In case you are Java newby there are also people willing to help, but you have to learn basics on your own.

                        – Bartosz Firyn
                        Apr 23 '15 at 14:38













                        7














                        JMyron is very simple for use.
                        http://webcamxtra.sourceforge.net/



                        myron = new JMyron();
                        myron.start(imgw, imgh);
                        myron.update();
                        int img = myron.image();





                        share|improve this answer




























                          7














                          JMyron is very simple for use.
                          http://webcamxtra.sourceforge.net/



                          myron = new JMyron();
                          myron.start(imgw, imgh);
                          myron.update();
                          int img = myron.image();





                          share|improve this answer


























                            7












                            7








                            7







                            JMyron is very simple for use.
                            http://webcamxtra.sourceforge.net/



                            myron = new JMyron();
                            myron.start(imgw, imgh);
                            myron.update();
                            int img = myron.image();





                            share|improve this answer













                            JMyron is very simple for use.
                            http://webcamxtra.sourceforge.net/



                            myron = new JMyron();
                            myron.start(imgw, imgh);
                            myron.update();
                            int img = myron.image();






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 8 '10 at 1:32









                            SamSam

                            364513




                            364513























                                5














                                Here is a similar question with some - yet unaccepted - answers. One of them mentions FMJ as a java alternative to JMF.






                                share|improve this answer






























                                  5














                                  Here is a similar question with some - yet unaccepted - answers. One of them mentions FMJ as a java alternative to JMF.






                                  share|improve this answer




























                                    5












                                    5








                                    5







                                    Here is a similar question with some - yet unaccepted - answers. One of them mentions FMJ as a java alternative to JMF.






                                    share|improve this answer















                                    Here is a similar question with some - yet unaccepted - answers. One of them mentions FMJ as a java alternative to JMF.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited May 23 '17 at 12:10









                                    Community

                                    11




                                    11










                                    answered Nov 15 '08 at 11:19









                                    ricsrics

                                    3,99232440




                                    3,99232440























                                        5














                                        This kind of goes off of gt_ebuddy's answer using JavaCV, but my video output is at a much higher quality then his answer. I've also added some other random improvements (such as closing down the program when ESC and CTRL+C are pressed, and making sure to close down the resources the program uses properly).



                                        import java.awt.event.ActionEvent;
                                        import java.awt.event.KeyEvent;
                                        import java.awt.event.WindowAdapter;
                                        import java.awt.event.WindowEvent;
                                        import java.awt.image.BufferedImage;

                                        import javax.swing.AbstractAction;
                                        import javax.swing.ActionMap;
                                        import javax.swing.InputMap;
                                        import javax.swing.JComponent;
                                        import javax.swing.JFrame;
                                        import javax.swing.KeyStroke;

                                        import com.googlecode.javacv.CanvasFrame;
                                        import com.googlecode.javacv.OpenCVFrameGrabber;
                                        import com.googlecode.javacv.cpp.opencv_core.IplImage;

                                        public class HighRes extends JComponent implements Runnable {
                                        private static final long serialVersionUID = 1L;

                                        private static CanvasFrame frame = new CanvasFrame("Web Cam");
                                        private static boolean running = false;
                                        private static int frameWidth = 800;
                                        private static int frameHeight = 600;
                                        private static OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
                                        private static BufferedImage bufImg;

                                        public HighRes()
                                        {
                                        // setup key bindings
                                        ActionMap actionMap = frame.getRootPane().getActionMap();
                                        InputMap inputMap = frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

                                        for (Keys direction : Keys.values())
                                        {
                                        actionMap.put(direction.getText(), new KeyBinding(direction.getText()));
                                        inputMap.put(direction.getKeyStroke(), direction.getText());
                                        }

                                        frame.getRootPane().setActionMap(actionMap);
                                        frame.getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);

                                        // setup window listener for close action
                                        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                        frame.addWindowListener(new WindowAdapter()
                                        {
                                        public void windowClosing(WindowEvent e)
                                        {
                                        stop();
                                        }
                                        });
                                        }

                                        public static void main(String... args)
                                        {
                                        HighRes webcam = new HighRes();
                                        webcam.start();
                                        }

                                        @Override
                                        public void run()
                                        {
                                        try
                                        {

                                        grabber.setImageWidth(frameWidth);
                                        grabber.setImageHeight(frameHeight);
                                        grabber.start();
                                        while (running)
                                        {

                                        final IplImage cvimg = grabber.grab();
                                        if (cvimg != null)
                                        {

                                        // cvFlip(cvimg, cvimg, 1); // mirror

                                        // show image on window
                                        bufImg = cvimg.getBufferedImage();
                                        frame.showImage(bufImg);
                                        }
                                        }
                                        grabber.stop();
                                        grabber.release();
                                        frame.dispose();
                                        }
                                        catch (Exception e)
                                        {
                                        e.printStackTrace();
                                        }
                                        }

                                        public void start()
                                        {
                                        new Thread(this).start();
                                        running = true;
                                        }

                                        public void stop()
                                        {
                                        running = false;
                                        }

                                        private class KeyBinding extends AbstractAction {

                                        private static final long serialVersionUID = 1L;

                                        public KeyBinding(String text)
                                        {
                                        super(text);
                                        putValue(ACTION_COMMAND_KEY, text);
                                        }

                                        @Override
                                        public void actionPerformed(ActionEvent e)
                                        {
                                        String action = e.getActionCommand();
                                        if (action.equals(Keys.ESCAPE.toString()) || action.equals(Keys.CTRLC.toString())) stop();
                                        else System.out.println("Key Binding: " + action);
                                        }
                                        }
                                        }

                                        enum Keys
                                        {
                                        ESCAPE("Escape", KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)),
                                        CTRLC("Control-C", KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK)),
                                        UP("Up", KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)),
                                        DOWN("Down", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)),
                                        LEFT("Left", KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)),
                                        RIGHT("Right", KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));

                                        private String text;
                                        private KeyStroke keyStroke;

                                        Keys(String text, KeyStroke keyStroke)
                                        {
                                        this.text = text;
                                        this.keyStroke = keyStroke;
                                        }

                                        public String getText()
                                        {
                                        return text;
                                        }

                                        public KeyStroke getKeyStroke()
                                        {
                                        return keyStroke;
                                        }

                                        @Override
                                        public String toString()
                                        {
                                        return text;
                                        }
                                        }





                                        share|improve this answer






























                                          5














                                          This kind of goes off of gt_ebuddy's answer using JavaCV, but my video output is at a much higher quality then his answer. I've also added some other random improvements (such as closing down the program when ESC and CTRL+C are pressed, and making sure to close down the resources the program uses properly).



                                          import java.awt.event.ActionEvent;
                                          import java.awt.event.KeyEvent;
                                          import java.awt.event.WindowAdapter;
                                          import java.awt.event.WindowEvent;
                                          import java.awt.image.BufferedImage;

                                          import javax.swing.AbstractAction;
                                          import javax.swing.ActionMap;
                                          import javax.swing.InputMap;
                                          import javax.swing.JComponent;
                                          import javax.swing.JFrame;
                                          import javax.swing.KeyStroke;

                                          import com.googlecode.javacv.CanvasFrame;
                                          import com.googlecode.javacv.OpenCVFrameGrabber;
                                          import com.googlecode.javacv.cpp.opencv_core.IplImage;

                                          public class HighRes extends JComponent implements Runnable {
                                          private static final long serialVersionUID = 1L;

                                          private static CanvasFrame frame = new CanvasFrame("Web Cam");
                                          private static boolean running = false;
                                          private static int frameWidth = 800;
                                          private static int frameHeight = 600;
                                          private static OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
                                          private static BufferedImage bufImg;

                                          public HighRes()
                                          {
                                          // setup key bindings
                                          ActionMap actionMap = frame.getRootPane().getActionMap();
                                          InputMap inputMap = frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

                                          for (Keys direction : Keys.values())
                                          {
                                          actionMap.put(direction.getText(), new KeyBinding(direction.getText()));
                                          inputMap.put(direction.getKeyStroke(), direction.getText());
                                          }

                                          frame.getRootPane().setActionMap(actionMap);
                                          frame.getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);

                                          // setup window listener for close action
                                          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                          frame.addWindowListener(new WindowAdapter()
                                          {
                                          public void windowClosing(WindowEvent e)
                                          {
                                          stop();
                                          }
                                          });
                                          }

                                          public static void main(String... args)
                                          {
                                          HighRes webcam = new HighRes();
                                          webcam.start();
                                          }

                                          @Override
                                          public void run()
                                          {
                                          try
                                          {

                                          grabber.setImageWidth(frameWidth);
                                          grabber.setImageHeight(frameHeight);
                                          grabber.start();
                                          while (running)
                                          {

                                          final IplImage cvimg = grabber.grab();
                                          if (cvimg != null)
                                          {

                                          // cvFlip(cvimg, cvimg, 1); // mirror

                                          // show image on window
                                          bufImg = cvimg.getBufferedImage();
                                          frame.showImage(bufImg);
                                          }
                                          }
                                          grabber.stop();
                                          grabber.release();
                                          frame.dispose();
                                          }
                                          catch (Exception e)
                                          {
                                          e.printStackTrace();
                                          }
                                          }

                                          public void start()
                                          {
                                          new Thread(this).start();
                                          running = true;
                                          }

                                          public void stop()
                                          {
                                          running = false;
                                          }

                                          private class KeyBinding extends AbstractAction {

                                          private static final long serialVersionUID = 1L;

                                          public KeyBinding(String text)
                                          {
                                          super(text);
                                          putValue(ACTION_COMMAND_KEY, text);
                                          }

                                          @Override
                                          public void actionPerformed(ActionEvent e)
                                          {
                                          String action = e.getActionCommand();
                                          if (action.equals(Keys.ESCAPE.toString()) || action.equals(Keys.CTRLC.toString())) stop();
                                          else System.out.println("Key Binding: " + action);
                                          }
                                          }
                                          }

                                          enum Keys
                                          {
                                          ESCAPE("Escape", KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)),
                                          CTRLC("Control-C", KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK)),
                                          UP("Up", KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)),
                                          DOWN("Down", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)),
                                          LEFT("Left", KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)),
                                          RIGHT("Right", KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));

                                          private String text;
                                          private KeyStroke keyStroke;

                                          Keys(String text, KeyStroke keyStroke)
                                          {
                                          this.text = text;
                                          this.keyStroke = keyStroke;
                                          }

                                          public String getText()
                                          {
                                          return text;
                                          }

                                          public KeyStroke getKeyStroke()
                                          {
                                          return keyStroke;
                                          }

                                          @Override
                                          public String toString()
                                          {
                                          return text;
                                          }
                                          }





                                          share|improve this answer




























                                            5












                                            5








                                            5







                                            This kind of goes off of gt_ebuddy's answer using JavaCV, but my video output is at a much higher quality then his answer. I've also added some other random improvements (such as closing down the program when ESC and CTRL+C are pressed, and making sure to close down the resources the program uses properly).



                                            import java.awt.event.ActionEvent;
                                            import java.awt.event.KeyEvent;
                                            import java.awt.event.WindowAdapter;
                                            import java.awt.event.WindowEvent;
                                            import java.awt.image.BufferedImage;

                                            import javax.swing.AbstractAction;
                                            import javax.swing.ActionMap;
                                            import javax.swing.InputMap;
                                            import javax.swing.JComponent;
                                            import javax.swing.JFrame;
                                            import javax.swing.KeyStroke;

                                            import com.googlecode.javacv.CanvasFrame;
                                            import com.googlecode.javacv.OpenCVFrameGrabber;
                                            import com.googlecode.javacv.cpp.opencv_core.IplImage;

                                            public class HighRes extends JComponent implements Runnable {
                                            private static final long serialVersionUID = 1L;

                                            private static CanvasFrame frame = new CanvasFrame("Web Cam");
                                            private static boolean running = false;
                                            private static int frameWidth = 800;
                                            private static int frameHeight = 600;
                                            private static OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
                                            private static BufferedImage bufImg;

                                            public HighRes()
                                            {
                                            // setup key bindings
                                            ActionMap actionMap = frame.getRootPane().getActionMap();
                                            InputMap inputMap = frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

                                            for (Keys direction : Keys.values())
                                            {
                                            actionMap.put(direction.getText(), new KeyBinding(direction.getText()));
                                            inputMap.put(direction.getKeyStroke(), direction.getText());
                                            }

                                            frame.getRootPane().setActionMap(actionMap);
                                            frame.getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);

                                            // setup window listener for close action
                                            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                            frame.addWindowListener(new WindowAdapter()
                                            {
                                            public void windowClosing(WindowEvent e)
                                            {
                                            stop();
                                            }
                                            });
                                            }

                                            public static void main(String... args)
                                            {
                                            HighRes webcam = new HighRes();
                                            webcam.start();
                                            }

                                            @Override
                                            public void run()
                                            {
                                            try
                                            {

                                            grabber.setImageWidth(frameWidth);
                                            grabber.setImageHeight(frameHeight);
                                            grabber.start();
                                            while (running)
                                            {

                                            final IplImage cvimg = grabber.grab();
                                            if (cvimg != null)
                                            {

                                            // cvFlip(cvimg, cvimg, 1); // mirror

                                            // show image on window
                                            bufImg = cvimg.getBufferedImage();
                                            frame.showImage(bufImg);
                                            }
                                            }
                                            grabber.stop();
                                            grabber.release();
                                            frame.dispose();
                                            }
                                            catch (Exception e)
                                            {
                                            e.printStackTrace();
                                            }
                                            }

                                            public void start()
                                            {
                                            new Thread(this).start();
                                            running = true;
                                            }

                                            public void stop()
                                            {
                                            running = false;
                                            }

                                            private class KeyBinding extends AbstractAction {

                                            private static final long serialVersionUID = 1L;

                                            public KeyBinding(String text)
                                            {
                                            super(text);
                                            putValue(ACTION_COMMAND_KEY, text);
                                            }

                                            @Override
                                            public void actionPerformed(ActionEvent e)
                                            {
                                            String action = e.getActionCommand();
                                            if (action.equals(Keys.ESCAPE.toString()) || action.equals(Keys.CTRLC.toString())) stop();
                                            else System.out.println("Key Binding: " + action);
                                            }
                                            }
                                            }

                                            enum Keys
                                            {
                                            ESCAPE("Escape", KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)),
                                            CTRLC("Control-C", KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK)),
                                            UP("Up", KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)),
                                            DOWN("Down", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)),
                                            LEFT("Left", KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)),
                                            RIGHT("Right", KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));

                                            private String text;
                                            private KeyStroke keyStroke;

                                            Keys(String text, KeyStroke keyStroke)
                                            {
                                            this.text = text;
                                            this.keyStroke = keyStroke;
                                            }

                                            public String getText()
                                            {
                                            return text;
                                            }

                                            public KeyStroke getKeyStroke()
                                            {
                                            return keyStroke;
                                            }

                                            @Override
                                            public String toString()
                                            {
                                            return text;
                                            }
                                            }





                                            share|improve this answer















                                            This kind of goes off of gt_ebuddy's answer using JavaCV, but my video output is at a much higher quality then his answer. I've also added some other random improvements (such as closing down the program when ESC and CTRL+C are pressed, and making sure to close down the resources the program uses properly).



                                            import java.awt.event.ActionEvent;
                                            import java.awt.event.KeyEvent;
                                            import java.awt.event.WindowAdapter;
                                            import java.awt.event.WindowEvent;
                                            import java.awt.image.BufferedImage;

                                            import javax.swing.AbstractAction;
                                            import javax.swing.ActionMap;
                                            import javax.swing.InputMap;
                                            import javax.swing.JComponent;
                                            import javax.swing.JFrame;
                                            import javax.swing.KeyStroke;

                                            import com.googlecode.javacv.CanvasFrame;
                                            import com.googlecode.javacv.OpenCVFrameGrabber;
                                            import com.googlecode.javacv.cpp.opencv_core.IplImage;

                                            public class HighRes extends JComponent implements Runnable {
                                            private static final long serialVersionUID = 1L;

                                            private static CanvasFrame frame = new CanvasFrame("Web Cam");
                                            private static boolean running = false;
                                            private static int frameWidth = 800;
                                            private static int frameHeight = 600;
                                            private static OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
                                            private static BufferedImage bufImg;

                                            public HighRes()
                                            {
                                            // setup key bindings
                                            ActionMap actionMap = frame.getRootPane().getActionMap();
                                            InputMap inputMap = frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

                                            for (Keys direction : Keys.values())
                                            {
                                            actionMap.put(direction.getText(), new KeyBinding(direction.getText()));
                                            inputMap.put(direction.getKeyStroke(), direction.getText());
                                            }

                                            frame.getRootPane().setActionMap(actionMap);
                                            frame.getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);

                                            // setup window listener for close action
                                            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                            frame.addWindowListener(new WindowAdapter()
                                            {
                                            public void windowClosing(WindowEvent e)
                                            {
                                            stop();
                                            }
                                            });
                                            }

                                            public static void main(String... args)
                                            {
                                            HighRes webcam = new HighRes();
                                            webcam.start();
                                            }

                                            @Override
                                            public void run()
                                            {
                                            try
                                            {

                                            grabber.setImageWidth(frameWidth);
                                            grabber.setImageHeight(frameHeight);
                                            grabber.start();
                                            while (running)
                                            {

                                            final IplImage cvimg = grabber.grab();
                                            if (cvimg != null)
                                            {

                                            // cvFlip(cvimg, cvimg, 1); // mirror

                                            // show image on window
                                            bufImg = cvimg.getBufferedImage();
                                            frame.showImage(bufImg);
                                            }
                                            }
                                            grabber.stop();
                                            grabber.release();
                                            frame.dispose();
                                            }
                                            catch (Exception e)
                                            {
                                            e.printStackTrace();
                                            }
                                            }

                                            public void start()
                                            {
                                            new Thread(this).start();
                                            running = true;
                                            }

                                            public void stop()
                                            {
                                            running = false;
                                            }

                                            private class KeyBinding extends AbstractAction {

                                            private static final long serialVersionUID = 1L;

                                            public KeyBinding(String text)
                                            {
                                            super(text);
                                            putValue(ACTION_COMMAND_KEY, text);
                                            }

                                            @Override
                                            public void actionPerformed(ActionEvent e)
                                            {
                                            String action = e.getActionCommand();
                                            if (action.equals(Keys.ESCAPE.toString()) || action.equals(Keys.CTRLC.toString())) stop();
                                            else System.out.println("Key Binding: " + action);
                                            }
                                            }
                                            }

                                            enum Keys
                                            {
                                            ESCAPE("Escape", KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)),
                                            CTRLC("Control-C", KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK)),
                                            UP("Up", KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)),
                                            DOWN("Down", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)),
                                            LEFT("Left", KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)),
                                            RIGHT("Right", KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));

                                            private String text;
                                            private KeyStroke keyStroke;

                                            Keys(String text, KeyStroke keyStroke)
                                            {
                                            this.text = text;
                                            this.keyStroke = keyStroke;
                                            }

                                            public String getText()
                                            {
                                            return text;
                                            }

                                            public KeyStroke getKeyStroke()
                                            {
                                            return keyStroke;
                                            }

                                            @Override
                                            public String toString()
                                            {
                                            return text;
                                            }
                                            }






                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited May 4 '13 at 16:17

























                                            answered Apr 12 '13 at 22:46









                                            syb0rgsyb0rg

                                            6,28973169




                                            6,28973169























                                                4














                                                You can try Java Webcam SDK library also.
                                                SDK demo applet is available at link.






                                                share|improve this answer



















                                                • 4





                                                  this is not free

                                                  – Bonus Kun
                                                  Jul 9 '12 at 14:45
















                                                4














                                                You can try Java Webcam SDK library also.
                                                SDK demo applet is available at link.






                                                share|improve this answer



















                                                • 4





                                                  this is not free

                                                  – Bonus Kun
                                                  Jul 9 '12 at 14:45














                                                4












                                                4








                                                4







                                                You can try Java Webcam SDK library also.
                                                SDK demo applet is available at link.






                                                share|improve this answer













                                                You can try Java Webcam SDK library also.
                                                SDK demo applet is available at link.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Feb 6 '12 at 12:23









                                                Andrei Andrei

                                                12612




                                                12612








                                                • 4





                                                  this is not free

                                                  – Bonus Kun
                                                  Jul 9 '12 at 14:45














                                                • 4





                                                  this is not free

                                                  – Bonus Kun
                                                  Jul 9 '12 at 14:45








                                                4




                                                4





                                                this is not free

                                                – Bonus Kun
                                                Jul 9 '12 at 14:45





                                                this is not free

                                                – Bonus Kun
                                                Jul 9 '12 at 14:45











                                                3














                                                I have used JMF on a videoconference application and it worked well on two laptops: one with integrated webcam and another with an old USB webcam. It requires JMF being installed and configured before-hand, but once you're done you can access the hardware via Java code fairly easily.






                                                share|improve this answer
























                                                • can you give me snippet code of your project?

                                                  – Java D
                                                  May 4 '13 at 6:14
















                                                3














                                                I have used JMF on a videoconference application and it worked well on two laptops: one with integrated webcam and another with an old USB webcam. It requires JMF being installed and configured before-hand, but once you're done you can access the hardware via Java code fairly easily.






                                                share|improve this answer
























                                                • can you give me snippet code of your project?

                                                  – Java D
                                                  May 4 '13 at 6:14














                                                3












                                                3








                                                3







                                                I have used JMF on a videoconference application and it worked well on two laptops: one with integrated webcam and another with an old USB webcam. It requires JMF being installed and configured before-hand, but once you're done you can access the hardware via Java code fairly easily.






                                                share|improve this answer













                                                I have used JMF on a videoconference application and it worked well on two laptops: one with integrated webcam and another with an old USB webcam. It requires JMF being installed and configured before-hand, but once you're done you can access the hardware via Java code fairly easily.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Nov 10 '08 at 18:14









                                                ArnauVPArnauVP

                                                311




                                                311













                                                • can you give me snippet code of your project?

                                                  – Java D
                                                  May 4 '13 at 6:14



















                                                • can you give me snippet code of your project?

                                                  – Java D
                                                  May 4 '13 at 6:14

















                                                can you give me snippet code of your project?

                                                – Java D
                                                May 4 '13 at 6:14





                                                can you give me snippet code of your project?

                                                – Java D
                                                May 4 '13 at 6:14











                                                3














                                                You can try Marvin Framework. It provides an interface to work with cameras. Moreover, it also provides a set of real-time video processing features, like object tracking and filtering.



                                                Take a look!



                                                Real-time Video Processing Demo:
                                                http://www.youtube.com/watch?v=D5mBt0kRYvk



                                                You can use the source below. Just save a frame using MarvinImageIO.saveImage() every 5 second.



                                                Webcam video demo:



                                                public class SimpleVideoTest extends JFrame implements Runnable{

                                                private MarvinVideoInterface videoAdapter;
                                                private MarvinImage image;
                                                private MarvinImagePanel videoPanel;

                                                public SimpleVideoTest(){
                                                super("Simple Video Test");
                                                videoAdapter = new MarvinJavaCVAdapter();
                                                videoAdapter.connect(0);
                                                videoPanel = new MarvinImagePanel();
                                                add(videoPanel);
                                                new Thread(this).start();
                                                setSize(800,600);
                                                setVisible(true);
                                                }
                                                @Override
                                                public void run() {
                                                while(true){
                                                // Request a video frame and set into the VideoPanel
                                                image = videoAdapter.getFrame();
                                                videoPanel.setImage(image);
                                                }
                                                }
                                                public static void main(String args) {
                                                SimpleVideoTest t = new SimpleVideoTest();
                                                t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                                }
                                                }


                                                For those who just want to take a single picture:



                                                WebcamPicture.java



                                                public class WebcamPicture {
                                                public static void main(String args) {
                                                try{
                                                MarvinVideoInterface videoAdapter = new MarvinJavaCVAdapter();
                                                videoAdapter.connect(0);
                                                MarvinImage image = videoAdapter.getFrame();
                                                MarvinImageIO.saveImage(image, "./res/webcam_picture.jpg");
                                                } catch(MarvinVideoInterfaceException e){
                                                e.printStackTrace();
                                                }
                                                }
                                                }





                                                share|improve this answer






























                                                  3














                                                  You can try Marvin Framework. It provides an interface to work with cameras. Moreover, it also provides a set of real-time video processing features, like object tracking and filtering.



                                                  Take a look!



                                                  Real-time Video Processing Demo:
                                                  http://www.youtube.com/watch?v=D5mBt0kRYvk



                                                  You can use the source below. Just save a frame using MarvinImageIO.saveImage() every 5 second.



                                                  Webcam video demo:



                                                  public class SimpleVideoTest extends JFrame implements Runnable{

                                                  private MarvinVideoInterface videoAdapter;
                                                  private MarvinImage image;
                                                  private MarvinImagePanel videoPanel;

                                                  public SimpleVideoTest(){
                                                  super("Simple Video Test");
                                                  videoAdapter = new MarvinJavaCVAdapter();
                                                  videoAdapter.connect(0);
                                                  videoPanel = new MarvinImagePanel();
                                                  add(videoPanel);
                                                  new Thread(this).start();
                                                  setSize(800,600);
                                                  setVisible(true);
                                                  }
                                                  @Override
                                                  public void run() {
                                                  while(true){
                                                  // Request a video frame and set into the VideoPanel
                                                  image = videoAdapter.getFrame();
                                                  videoPanel.setImage(image);
                                                  }
                                                  }
                                                  public static void main(String args) {
                                                  SimpleVideoTest t = new SimpleVideoTest();
                                                  t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                                  }
                                                  }


                                                  For those who just want to take a single picture:



                                                  WebcamPicture.java



                                                  public class WebcamPicture {
                                                  public static void main(String args) {
                                                  try{
                                                  MarvinVideoInterface videoAdapter = new MarvinJavaCVAdapter();
                                                  videoAdapter.connect(0);
                                                  MarvinImage image = videoAdapter.getFrame();
                                                  MarvinImageIO.saveImage(image, "./res/webcam_picture.jpg");
                                                  } catch(MarvinVideoInterfaceException e){
                                                  e.printStackTrace();
                                                  }
                                                  }
                                                  }





                                                  share|improve this answer




























                                                    3












                                                    3








                                                    3







                                                    You can try Marvin Framework. It provides an interface to work with cameras. Moreover, it also provides a set of real-time video processing features, like object tracking and filtering.



                                                    Take a look!



                                                    Real-time Video Processing Demo:
                                                    http://www.youtube.com/watch?v=D5mBt0kRYvk



                                                    You can use the source below. Just save a frame using MarvinImageIO.saveImage() every 5 second.



                                                    Webcam video demo:



                                                    public class SimpleVideoTest extends JFrame implements Runnable{

                                                    private MarvinVideoInterface videoAdapter;
                                                    private MarvinImage image;
                                                    private MarvinImagePanel videoPanel;

                                                    public SimpleVideoTest(){
                                                    super("Simple Video Test");
                                                    videoAdapter = new MarvinJavaCVAdapter();
                                                    videoAdapter.connect(0);
                                                    videoPanel = new MarvinImagePanel();
                                                    add(videoPanel);
                                                    new Thread(this).start();
                                                    setSize(800,600);
                                                    setVisible(true);
                                                    }
                                                    @Override
                                                    public void run() {
                                                    while(true){
                                                    // Request a video frame and set into the VideoPanel
                                                    image = videoAdapter.getFrame();
                                                    videoPanel.setImage(image);
                                                    }
                                                    }
                                                    public static void main(String args) {
                                                    SimpleVideoTest t = new SimpleVideoTest();
                                                    t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                                    }
                                                    }


                                                    For those who just want to take a single picture:



                                                    WebcamPicture.java



                                                    public class WebcamPicture {
                                                    public static void main(String args) {
                                                    try{
                                                    MarvinVideoInterface videoAdapter = new MarvinJavaCVAdapter();
                                                    videoAdapter.connect(0);
                                                    MarvinImage image = videoAdapter.getFrame();
                                                    MarvinImageIO.saveImage(image, "./res/webcam_picture.jpg");
                                                    } catch(MarvinVideoInterfaceException e){
                                                    e.printStackTrace();
                                                    }
                                                    }
                                                    }





                                                    share|improve this answer















                                                    You can try Marvin Framework. It provides an interface to work with cameras. Moreover, it also provides a set of real-time video processing features, like object tracking and filtering.



                                                    Take a look!



                                                    Real-time Video Processing Demo:
                                                    http://www.youtube.com/watch?v=D5mBt0kRYvk



                                                    You can use the source below. Just save a frame using MarvinImageIO.saveImage() every 5 second.



                                                    Webcam video demo:



                                                    public class SimpleVideoTest extends JFrame implements Runnable{

                                                    private MarvinVideoInterface videoAdapter;
                                                    private MarvinImage image;
                                                    private MarvinImagePanel videoPanel;

                                                    public SimpleVideoTest(){
                                                    super("Simple Video Test");
                                                    videoAdapter = new MarvinJavaCVAdapter();
                                                    videoAdapter.connect(0);
                                                    videoPanel = new MarvinImagePanel();
                                                    add(videoPanel);
                                                    new Thread(this).start();
                                                    setSize(800,600);
                                                    setVisible(true);
                                                    }
                                                    @Override
                                                    public void run() {
                                                    while(true){
                                                    // Request a video frame and set into the VideoPanel
                                                    image = videoAdapter.getFrame();
                                                    videoPanel.setImage(image);
                                                    }
                                                    }
                                                    public static void main(String args) {
                                                    SimpleVideoTest t = new SimpleVideoTest();
                                                    t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                                    }
                                                    }


                                                    For those who just want to take a single picture:



                                                    WebcamPicture.java



                                                    public class WebcamPicture {
                                                    public static void main(String args) {
                                                    try{
                                                    MarvinVideoInterface videoAdapter = new MarvinJavaCVAdapter();
                                                    videoAdapter.connect(0);
                                                    MarvinImage image = videoAdapter.getFrame();
                                                    MarvinImageIO.saveImage(image, "./res/webcam_picture.jpg");
                                                    } catch(MarvinVideoInterfaceException e){
                                                    e.printStackTrace();
                                                    }
                                                    }
                                                    }






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Dec 22 '16 at 10:55









                                                    Gabriel Ambrósio Archanjo

                                                    3,62421633




                                                    3,62421633










                                                    answered Nov 18 '11 at 15:48









                                                    HugoHugo

                                                    311




                                                    311























                                                        2














                                                        http://grack.com/downloads/school/enel619.10/report/java_media_framework.html



                                                        Using the Player with Swing



                                                        The Player can be easily used in a Swing application as well. The following code creates a Swing-based TV capture program with the video output displayed in the entire window:



                                                        import javax.media.*;
                                                        import javax.swing.*;
                                                        import java.awt.*;
                                                        import java.net.*;
                                                        import java.awt.event.*;
                                                        import javax.swing.event.*;

                                                        public class JMFTest extends JFrame {
                                                        Player _player;
                                                        JMFTest() {
                                                        addWindowListener( new WindowAdapter() {
                                                        public void windowClosing( WindowEvent e ) {
                                                        _player.stop();
                                                        _player.deallocate();
                                                        _player.close();
                                                        System.exit( 0 );
                                                        }
                                                        });
                                                        setExtent( 0, 0, 320, 260 );
                                                        JPanel panel = (JPanel)getContentPane();
                                                        panel.setLayout( new BorderLayout() );
                                                        String mediaFile = "vfw://1";
                                                        try {
                                                        MediaLocator mlr = new MediaLocator( mediaFile );
                                                        _player = Manager.createRealizedPlayer( mlr );
                                                        if (_player.getVisualComponent() != null)
                                                        panel.add("Center", _player.getVisualComponent());
                                                        if (_player.getControlPanelComponent() != null)
                                                        panel.add("South", _player.getControlPanelComponent());
                                                        }
                                                        catch (Exception e) {
                                                        System.err.println( "Got exception " + e );
                                                        }
                                                        }

                                                        public static void main(String args) {
                                                        JMFTest jmfTest = new JMFTest();
                                                        jmfTest.show();
                                                        }
                                                        }





                                                        share|improve this answer






























                                                          2














                                                          http://grack.com/downloads/school/enel619.10/report/java_media_framework.html



                                                          Using the Player with Swing



                                                          The Player can be easily used in a Swing application as well. The following code creates a Swing-based TV capture program with the video output displayed in the entire window:



                                                          import javax.media.*;
                                                          import javax.swing.*;
                                                          import java.awt.*;
                                                          import java.net.*;
                                                          import java.awt.event.*;
                                                          import javax.swing.event.*;

                                                          public class JMFTest extends JFrame {
                                                          Player _player;
                                                          JMFTest() {
                                                          addWindowListener( new WindowAdapter() {
                                                          public void windowClosing( WindowEvent e ) {
                                                          _player.stop();
                                                          _player.deallocate();
                                                          _player.close();
                                                          System.exit( 0 );
                                                          }
                                                          });
                                                          setExtent( 0, 0, 320, 260 );
                                                          JPanel panel = (JPanel)getContentPane();
                                                          panel.setLayout( new BorderLayout() );
                                                          String mediaFile = "vfw://1";
                                                          try {
                                                          MediaLocator mlr = new MediaLocator( mediaFile );
                                                          _player = Manager.createRealizedPlayer( mlr );
                                                          if (_player.getVisualComponent() != null)
                                                          panel.add("Center", _player.getVisualComponent());
                                                          if (_player.getControlPanelComponent() != null)
                                                          panel.add("South", _player.getControlPanelComponent());
                                                          }
                                                          catch (Exception e) {
                                                          System.err.println( "Got exception " + e );
                                                          }
                                                          }

                                                          public static void main(String args) {
                                                          JMFTest jmfTest = new JMFTest();
                                                          jmfTest.show();
                                                          }
                                                          }





                                                          share|improve this answer




























                                                            2












                                                            2








                                                            2







                                                            http://grack.com/downloads/school/enel619.10/report/java_media_framework.html



                                                            Using the Player with Swing



                                                            The Player can be easily used in a Swing application as well. The following code creates a Swing-based TV capture program with the video output displayed in the entire window:



                                                            import javax.media.*;
                                                            import javax.swing.*;
                                                            import java.awt.*;
                                                            import java.net.*;
                                                            import java.awt.event.*;
                                                            import javax.swing.event.*;

                                                            public class JMFTest extends JFrame {
                                                            Player _player;
                                                            JMFTest() {
                                                            addWindowListener( new WindowAdapter() {
                                                            public void windowClosing( WindowEvent e ) {
                                                            _player.stop();
                                                            _player.deallocate();
                                                            _player.close();
                                                            System.exit( 0 );
                                                            }
                                                            });
                                                            setExtent( 0, 0, 320, 260 );
                                                            JPanel panel = (JPanel)getContentPane();
                                                            panel.setLayout( new BorderLayout() );
                                                            String mediaFile = "vfw://1";
                                                            try {
                                                            MediaLocator mlr = new MediaLocator( mediaFile );
                                                            _player = Manager.createRealizedPlayer( mlr );
                                                            if (_player.getVisualComponent() != null)
                                                            panel.add("Center", _player.getVisualComponent());
                                                            if (_player.getControlPanelComponent() != null)
                                                            panel.add("South", _player.getControlPanelComponent());
                                                            }
                                                            catch (Exception e) {
                                                            System.err.println( "Got exception " + e );
                                                            }
                                                            }

                                                            public static void main(String args) {
                                                            JMFTest jmfTest = new JMFTest();
                                                            jmfTest.show();
                                                            }
                                                            }





                                                            share|improve this answer















                                                            http://grack.com/downloads/school/enel619.10/report/java_media_framework.html



                                                            Using the Player with Swing



                                                            The Player can be easily used in a Swing application as well. The following code creates a Swing-based TV capture program with the video output displayed in the entire window:



                                                            import javax.media.*;
                                                            import javax.swing.*;
                                                            import java.awt.*;
                                                            import java.net.*;
                                                            import java.awt.event.*;
                                                            import javax.swing.event.*;

                                                            public class JMFTest extends JFrame {
                                                            Player _player;
                                                            JMFTest() {
                                                            addWindowListener( new WindowAdapter() {
                                                            public void windowClosing( WindowEvent e ) {
                                                            _player.stop();
                                                            _player.deallocate();
                                                            _player.close();
                                                            System.exit( 0 );
                                                            }
                                                            });
                                                            setExtent( 0, 0, 320, 260 );
                                                            JPanel panel = (JPanel)getContentPane();
                                                            panel.setLayout( new BorderLayout() );
                                                            String mediaFile = "vfw://1";
                                                            try {
                                                            MediaLocator mlr = new MediaLocator( mediaFile );
                                                            _player = Manager.createRealizedPlayer( mlr );
                                                            if (_player.getVisualComponent() != null)
                                                            panel.add("Center", _player.getVisualComponent());
                                                            if (_player.getControlPanelComponent() != null)
                                                            panel.add("South", _player.getControlPanelComponent());
                                                            }
                                                            catch (Exception e) {
                                                            System.err.println( "Got exception " + e );
                                                            }
                                                            }

                                                            public static void main(String args) {
                                                            JMFTest jmfTest = new JMFTest();
                                                            jmfTest.show();
                                                            }
                                                            }






                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Nov 15 '09 at 14:12









                                                            Boris Pavlović

                                                            44.2k23103134




                                                            44.2k23103134










                                                            answered Jun 9 '09 at 18:19







                                                            Shereif 102






























                                                                2














                                                                I used Webcam Capture API...u can download from this http://webcam-capture.sarxos.pl/



                                                                        webcam = Webcam.getDefault();
                                                                webcam.open();

                                                                if (webcam.isOpen()) { //if web cam open
                                                                BufferedImage image = webcam.getImage();
                                                                JLabel imageLbl = new JLabel();
                                                                imageLbl.setSize(640, 480); //show captured image
                                                                imageLbl.setIcon(new ImageIcon(image));

                                                                int showConfirmDialog = JOptionPane.showConfirmDialog(null, imageLbl, "Image Viewer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(""));

                                                                if (showConfirmDialog == JOptionPane.YES_OPTION) {
                                                                JFileChooser chooser = new JFileChooser();
                                                                chooser.setDialogTitle("Save Image");
                                                                chooser.setFileFilter(new FileNameExtensionFilter("IMAGES ONLY", "png", "jpeg", "jpg")); //this file extentions are shown
                                                                int showSaveDialog = chooser.showSaveDialog(this);
                                                                if (showSaveDialog == 0) { //if pressed 'Save' button
                                                                String filePath = chooser.getCurrentDirectory().toString().replace("\", "/");
                                                                String fileName = chooser.getSelectedFile().getName(); //get user entered file name to save
                                                                ImageIO.write(image, "PNG", new File(filePath + "/" + fileName + ".png"));

                                                                }
                                                                }
                                                                }





                                                                share|improve this answer


























                                                                • You should provide some explanation along with the code

                                                                  – fen1x
                                                                  Sep 10 '17 at 21:17











                                                                • thanks. it's light and instead javacv this one works for me.

                                                                  – Lucke
                                                                  Oct 29 '18 at 18:52
















                                                                2














                                                                I used Webcam Capture API...u can download from this http://webcam-capture.sarxos.pl/



                                                                        webcam = Webcam.getDefault();
                                                                webcam.open();

                                                                if (webcam.isOpen()) { //if web cam open
                                                                BufferedImage image = webcam.getImage();
                                                                JLabel imageLbl = new JLabel();
                                                                imageLbl.setSize(640, 480); //show captured image
                                                                imageLbl.setIcon(new ImageIcon(image));

                                                                int showConfirmDialog = JOptionPane.showConfirmDialog(null, imageLbl, "Image Viewer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(""));

                                                                if (showConfirmDialog == JOptionPane.YES_OPTION) {
                                                                JFileChooser chooser = new JFileChooser();
                                                                chooser.setDialogTitle("Save Image");
                                                                chooser.setFileFilter(new FileNameExtensionFilter("IMAGES ONLY", "png", "jpeg", "jpg")); //this file extentions are shown
                                                                int showSaveDialog = chooser.showSaveDialog(this);
                                                                if (showSaveDialog == 0) { //if pressed 'Save' button
                                                                String filePath = chooser.getCurrentDirectory().toString().replace("\", "/");
                                                                String fileName = chooser.getSelectedFile().getName(); //get user entered file name to save
                                                                ImageIO.write(image, "PNG", new File(filePath + "/" + fileName + ".png"));

                                                                }
                                                                }
                                                                }





                                                                share|improve this answer


























                                                                • You should provide some explanation along with the code

                                                                  – fen1x
                                                                  Sep 10 '17 at 21:17











                                                                • thanks. it's light and instead javacv this one works for me.

                                                                  – Lucke
                                                                  Oct 29 '18 at 18:52














                                                                2












                                                                2








                                                                2







                                                                I used Webcam Capture API...u can download from this http://webcam-capture.sarxos.pl/



                                                                        webcam = Webcam.getDefault();
                                                                webcam.open();

                                                                if (webcam.isOpen()) { //if web cam open
                                                                BufferedImage image = webcam.getImage();
                                                                JLabel imageLbl = new JLabel();
                                                                imageLbl.setSize(640, 480); //show captured image
                                                                imageLbl.setIcon(new ImageIcon(image));

                                                                int showConfirmDialog = JOptionPane.showConfirmDialog(null, imageLbl, "Image Viewer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(""));

                                                                if (showConfirmDialog == JOptionPane.YES_OPTION) {
                                                                JFileChooser chooser = new JFileChooser();
                                                                chooser.setDialogTitle("Save Image");
                                                                chooser.setFileFilter(new FileNameExtensionFilter("IMAGES ONLY", "png", "jpeg", "jpg")); //this file extentions are shown
                                                                int showSaveDialog = chooser.showSaveDialog(this);
                                                                if (showSaveDialog == 0) { //if pressed 'Save' button
                                                                String filePath = chooser.getCurrentDirectory().toString().replace("\", "/");
                                                                String fileName = chooser.getSelectedFile().getName(); //get user entered file name to save
                                                                ImageIO.write(image, "PNG", new File(filePath + "/" + fileName + ".png"));

                                                                }
                                                                }
                                                                }





                                                                share|improve this answer















                                                                I used Webcam Capture API...u can download from this http://webcam-capture.sarxos.pl/



                                                                        webcam = Webcam.getDefault();
                                                                webcam.open();

                                                                if (webcam.isOpen()) { //if web cam open
                                                                BufferedImage image = webcam.getImage();
                                                                JLabel imageLbl = new JLabel();
                                                                imageLbl.setSize(640, 480); //show captured image
                                                                imageLbl.setIcon(new ImageIcon(image));

                                                                int showConfirmDialog = JOptionPane.showConfirmDialog(null, imageLbl, "Image Viewer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(""));

                                                                if (showConfirmDialog == JOptionPane.YES_OPTION) {
                                                                JFileChooser chooser = new JFileChooser();
                                                                chooser.setDialogTitle("Save Image");
                                                                chooser.setFileFilter(new FileNameExtensionFilter("IMAGES ONLY", "png", "jpeg", "jpg")); //this file extentions are shown
                                                                int showSaveDialog = chooser.showSaveDialog(this);
                                                                if (showSaveDialog == 0) { //if pressed 'Save' button
                                                                String filePath = chooser.getCurrentDirectory().toString().replace("\", "/");
                                                                String fileName = chooser.getSelectedFile().getName(); //get user entered file name to save
                                                                ImageIO.write(image, "PNG", new File(filePath + "/" + fileName + ".png"));

                                                                }
                                                                }
                                                                }






                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited Sep 10 '17 at 21:42

























                                                                answered Sep 10 '17 at 20:38









                                                                Uddika DilshanUddika Dilshan

                                                                213




                                                                213













                                                                • You should provide some explanation along with the code

                                                                  – fen1x
                                                                  Sep 10 '17 at 21:17











                                                                • thanks. it's light and instead javacv this one works for me.

                                                                  – Lucke
                                                                  Oct 29 '18 at 18:52



















                                                                • You should provide some explanation along with the code

                                                                  – fen1x
                                                                  Sep 10 '17 at 21:17











                                                                • thanks. it's light and instead javacv this one works for me.

                                                                  – Lucke
                                                                  Oct 29 '18 at 18:52

















                                                                You should provide some explanation along with the code

                                                                – fen1x
                                                                Sep 10 '17 at 21:17





                                                                You should provide some explanation along with the code

                                                                – fen1x
                                                                Sep 10 '17 at 21:17













                                                                thanks. it's light and instead javacv this one works for me.

                                                                – Lucke
                                                                Oct 29 '18 at 18:52





                                                                thanks. it's light and instead javacv this one works for me.

                                                                – Lucke
                                                                Oct 29 '18 at 18:52











                                                                1














                                                                Java usually doesn't like accessing hardware, so you will need a driver program of some sort, as goldenmean said. I've done this on my laptop by finding a command line program that snaps a picture. Then it's the same as goldenmean explained; you run the command line program from your java program in the takepicture() routine, and the rest of your code runs the same.



                                                                Except for the part about reading pixel values into an array, you might be better served by saving the file to BMP, which is nearly that format already, then using the standard java image libraries on it.



                                                                Using a command line program adds a dependency to your program and makes it less portable, but so was the webcam, right?






                                                                share|improve this answer




























                                                                  1














                                                                  Java usually doesn't like accessing hardware, so you will need a driver program of some sort, as goldenmean said. I've done this on my laptop by finding a command line program that snaps a picture. Then it's the same as goldenmean explained; you run the command line program from your java program in the takepicture() routine, and the rest of your code runs the same.



                                                                  Except for the part about reading pixel values into an array, you might be better served by saving the file to BMP, which is nearly that format already, then using the standard java image libraries on it.



                                                                  Using a command line program adds a dependency to your program and makes it less portable, but so was the webcam, right?






                                                                  share|improve this answer


























                                                                    1












                                                                    1








                                                                    1







                                                                    Java usually doesn't like accessing hardware, so you will need a driver program of some sort, as goldenmean said. I've done this on my laptop by finding a command line program that snaps a picture. Then it's the same as goldenmean explained; you run the command line program from your java program in the takepicture() routine, and the rest of your code runs the same.



                                                                    Except for the part about reading pixel values into an array, you might be better served by saving the file to BMP, which is nearly that format already, then using the standard java image libraries on it.



                                                                    Using a command line program adds a dependency to your program and makes it less portable, but so was the webcam, right?






                                                                    share|improve this answer













                                                                    Java usually doesn't like accessing hardware, so you will need a driver program of some sort, as goldenmean said. I've done this on my laptop by finding a command line program that snaps a picture. Then it's the same as goldenmean explained; you run the command line program from your java program in the takepicture() routine, and the rest of your code runs the same.



                                                                    Except for the part about reading pixel values into an array, you might be better served by saving the file to BMP, which is nearly that format already, then using the standard java image libraries on it.



                                                                    Using a command line program adds a dependency to your program and makes it less portable, but so was the webcam, right?







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Nov 10 '08 at 17:52









                                                                    KarlKarl

                                                                    5,63642529




                                                                    5,63642529























                                                                        0














                                                                        I believe the web-cam application software which comes along with the web-cam, or you native windows webcam software can be run in a batch script(windows/dos script) after turning the web cam on(i.e. if it needs an external power supply). In the bacth script , u can add appropriate delay to capture after certain time period. And keep executing the capture command in loop.



                                                                        I guess this should be possible



                                                                        -AD






                                                                        share|improve this answer




























                                                                          0














                                                                          I believe the web-cam application software which comes along with the web-cam, or you native windows webcam software can be run in a batch script(windows/dos script) after turning the web cam on(i.e. if it needs an external power supply). In the bacth script , u can add appropriate delay to capture after certain time period. And keep executing the capture command in loop.



                                                                          I guess this should be possible



                                                                          -AD






                                                                          share|improve this answer


























                                                                            0












                                                                            0








                                                                            0







                                                                            I believe the web-cam application software which comes along with the web-cam, or you native windows webcam software can be run in a batch script(windows/dos script) after turning the web cam on(i.e. if it needs an external power supply). In the bacth script , u can add appropriate delay to capture after certain time period. And keep executing the capture command in loop.



                                                                            I guess this should be possible



                                                                            -AD






                                                                            share|improve this answer













                                                                            I believe the web-cam application software which comes along with the web-cam, or you native windows webcam software can be run in a batch script(windows/dos script) after turning the web cam on(i.e. if it needs an external power supply). In the bacth script , u can add appropriate delay to capture after certain time period. And keep executing the capture command in loop.



                                                                            I guess this should be possible



                                                                            -AD







                                                                            share|improve this answer












                                                                            share|improve this answer



                                                                            share|improve this answer










                                                                            answered Nov 10 '08 at 0:41









                                                                            goldenmeangoldenmean

                                                                            8,35341134191




                                                                            8,35341134191























                                                                                0














                                                                                There's a pretty nice interface for this in processing, which is kind of a pidgin java designed for graphics. It gets used in some image recognition work, such as that link.



                                                                                Depending on what you need out of it, you might be able to load the video library that's used there in java, or if you're just playing around with it you might be able to get by using processing itself.






                                                                                share|improve this answer




























                                                                                  0














                                                                                  There's a pretty nice interface for this in processing, which is kind of a pidgin java designed for graphics. It gets used in some image recognition work, such as that link.



                                                                                  Depending on what you need out of it, you might be able to load the video library that's used there in java, or if you're just playing around with it you might be able to get by using processing itself.






                                                                                  share|improve this answer


























                                                                                    0












                                                                                    0








                                                                                    0







                                                                                    There's a pretty nice interface for this in processing, which is kind of a pidgin java designed for graphics. It gets used in some image recognition work, such as that link.



                                                                                    Depending on what you need out of it, you might be able to load the video library that's used there in java, or if you're just playing around with it you might be able to get by using processing itself.






                                                                                    share|improve this answer













                                                                                    There's a pretty nice interface for this in processing, which is kind of a pidgin java designed for graphics. It gets used in some image recognition work, such as that link.



                                                                                    Depending on what you need out of it, you might be able to load the video library that's used there in java, or if you're just playing around with it you might be able to get by using processing itself.







                                                                                    share|improve this answer












                                                                                    share|improve this answer



                                                                                    share|improve this answer










                                                                                    answered Nov 10 '08 at 18:39









                                                                                    Dan MonegoDan Monego

                                                                                    4,47052460




                                                                                    4,47052460























                                                                                        0














                                                                                        FMJ can do this, as can the supporting library it uses, LTI-CIVIL. Both are on sourceforge.






                                                                                        share|improve this answer




























                                                                                          0














                                                                                          FMJ can do this, as can the supporting library it uses, LTI-CIVIL. Both are on sourceforge.






                                                                                          share|improve this answer


























                                                                                            0












                                                                                            0








                                                                                            0







                                                                                            FMJ can do this, as can the supporting library it uses, LTI-CIVIL. Both are on sourceforge.






                                                                                            share|improve this answer













                                                                                            FMJ can do this, as can the supporting library it uses, LTI-CIVIL. Both are on sourceforge.







                                                                                            share|improve this answer












                                                                                            share|improve this answer



                                                                                            share|improve this answer










                                                                                            answered Dec 27 '08 at 14:51







                                                                                            Ken Larson






























                                                                                                0














                                                                                                Recommand using FMJ for multimedia relatived java app.






                                                                                                share|improve this answer




























                                                                                                  0














                                                                                                  Recommand using FMJ for multimedia relatived java app.






                                                                                                  share|improve this answer


























                                                                                                    0












                                                                                                    0








                                                                                                    0







                                                                                                    Recommand using FMJ for multimedia relatived java app.






                                                                                                    share|improve this answer













                                                                                                    Recommand using FMJ for multimedia relatived java app.







                                                                                                    share|improve this answer












                                                                                                    share|improve this answer



                                                                                                    share|improve this answer










                                                                                                    answered Oct 5 '09 at 13:52









                                                                                                    RoseRose

                                                                                                    27269




                                                                                                    27269























                                                                                                        0














                                                                                                        Try using JMyron How To Use Webcam Using Java. I think using JMyron is the easiest way to access a webcam using java. I tried to use it with a 64-bit processor, but it gave me an error. It worked just fine on a 32-bit processor, though.






                                                                                                        share|improve this answer






























                                                                                                          0














                                                                                                          Try using JMyron How To Use Webcam Using Java. I think using JMyron is the easiest way to access a webcam using java. I tried to use it with a 64-bit processor, but it gave me an error. It worked just fine on a 32-bit processor, though.






                                                                                                          share|improve this answer




























                                                                                                            0












                                                                                                            0








                                                                                                            0







                                                                                                            Try using JMyron How To Use Webcam Using Java. I think using JMyron is the easiest way to access a webcam using java. I tried to use it with a 64-bit processor, but it gave me an error. It worked just fine on a 32-bit processor, though.






                                                                                                            share|improve this answer















                                                                                                            Try using JMyron How To Use Webcam Using Java. I think using JMyron is the easiest way to access a webcam using java. I tried to use it with a 64-bit processor, but it gave me an error. It worked just fine on a 32-bit processor, though.







                                                                                                            share|improve this answer














                                                                                                            share|improve this answer



                                                                                                            share|improve this answer








                                                                                                            edited Oct 19 '12 at 22:10









                                                                                                            RustyTheBoyRobot

                                                                                                            5,04522650




                                                                                                            5,04522650










                                                                                                            answered May 9 '12 at 3:20









                                                                                                            extjstutorial.infoextjstutorial.info

                                                                                                            111




                                                                                                            111






























                                                                                                                draft saved

                                                                                                                draft discarded




















































                                                                                                                Thanks for contributing an answer to Stack Overflow!


                                                                                                                • Please be sure to answer the question. Provide details and share your research!

                                                                                                                But avoid



                                                                                                                • Asking for help, clarification, or responding to other answers.

                                                                                                                • Making statements based on opinion; back them up with references or personal experience.


                                                                                                                To learn more, see our tips on writing great answers.




                                                                                                                draft saved


                                                                                                                draft discarded














                                                                                                                StackExchange.ready(
                                                                                                                function () {
                                                                                                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f276292%2fcapturing-image-from-webcam-in-java%23new-answer', 'question_page');
                                                                                                                }
                                                                                                                );

                                                                                                                Post as a guest















                                                                                                                Required, but never shown





















































                                                                                                                Required, but never shown














                                                                                                                Required, but never shown












                                                                                                                Required, but never shown







                                                                                                                Required, but never shown

































                                                                                                                Required, but never shown














                                                                                                                Required, but never shown












                                                                                                                Required, but never shown







                                                                                                                Required, but never shown







                                                                                                                k,QrZFk5 1sz8Ess,F,AWLBvFFE0,0uyQvXb25,44yWeqVIGq,Apf6ov756z
                                                                                                                RVw9vbWK64Gv T6I,hKIUFNtLQrHtX9wUL4p V3fsDwp xBF,6ru6

                                                                                                                Popular posts from this blog

                                                                                                                Monofisismo

                                                                                                                Angular Downloading a file using contenturl with Basic Authentication

                                                                                                                Olmecas