Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video capturing(live video streaming) through Java

I want to write a program that can capture video through my webcam by using Java language, i.e live video streaming. I have found some threads about this topic but the issue is how can i make my program Operating system independent, like how to capture video on 32 bit and 64bit operating systems..

Kindly help me to solve this, i have very short time for this job. Also if anybody have some lead to this topic, post its link here.. Thanks.

like image 663
Arslan Avatar asked Jul 04 '12 17:07

Arslan


1 Answers

  1. As there are no classes in j2se that can be used to capture video from a webcam, so you need an external library like JMF or JavaCV, to do the same.

  2. To install JavaCV you will find instructions on these links:

    a. ganeshtiwaridotcomdotnp.blogspot.in Link

    b. code.google.com Link

  3. The code to capture video in real time from camera:

    import com.googlecode.javacv.CanvasFrame;
    import com.googlecode.javacv.FrameGrabber;
    import com.googlecode.javacv.VideoInputFrameGrabber;
    import com.googlecode.javacv.cpp.opencv_core.IplImage;
    import static com.googlecode.javacv.cpp.opencv_core.cvFlip;
    
    class GrabberShow implements Runnable 
    {    
       IplImage image;
       CanvasFrame canvas = new CanvasFrame("Web Cam");
       public GrabberShow() {
           canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
       }
       @Override
       public void run() {
           FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera
           try {
               grabber.start();
               IplImage img;
               while (true) {
                   img = grabber.grab();
                   if (img != null) {
                       cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise
                       canvas.showImage(img);
                   }
               } 
           } catch (Exception e) {}
       }
    }
    
    public class Main 
    {
           public static void main(String[] args) 
           {
               GrabberShow gs = new GrabberShow();
               Thread th = new Thread(gs);
               th.start();
           }
    }
    

hope this helps.

like image 141
codeDEXTER Avatar answered Nov 08 '22 15:11

codeDEXTER