- Today I will show you how open the webcam by using javaCV
- Open your last netbeans project
- Add a button and I name it as Open WebCam
- Double click on the button and goto button click event
- Enter following codes
CvCapture capture=opencv_highgui.cvCreateCameraCapture(0);
Here 0 is a parsing a variable. o is for webcam. If you using another camera you can use 1 or 2 or something.
- Next we have to set the height and with of camera frame
opencv_highgui.cvSetCaptureProperty(capture,opencv_highgui.CV_CAP_PROP_FRAME_HEIGHT,480);
opencv_highgui.cvSetCaptureProperty(capture,opencv_highgui.CV_CAP_PROP_FRAME_WIDTH,480);
- Next we have to make IplImage
IplImage img=opencv_highgui.cvQueryFrame(capture);
- Next add a canves to show the images
CanvasFrame frame= new CanvasFrame("WebCam Loading");
- Now run the programm.
- Can you see, when you try to close can't close the window. As a solution for it you can write above code in this part
Thread x= new Thread(){
public void run(){
}
//above codes here
};
x.start();