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.
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.
To install JavaCV you will find instructions on these links:
a. ganeshtiwaridotcomdotnp.blogspot.in Link
b. code.google.com Link
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.