code:
using namespace cv;
int main(int, char)
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
Note: In C API the black-box structure CvCapture is used instead of VideoCapture.
Note:
- A basic sample on using the VideoCapture interface can be found at opencv_source_code/samples/cpp/starter_video.cpp
- Another basic video processing sample can be found at opencv_source_code/samples/cpp/video_dmtx.cpp
- (Python) A basic sample on using the VideoCapture interface can be found at opencv_source_code/samples/python2/video.py
- (Python) Another basic video processing sample can be found at opencv_source_code/samples/python2/video_dmtx.py
- (Python) A multi threaded video processing sample can be found at opencv_source_code/samples/python2/video_threaded.py
@see
org.opencv.highgui.VideoCapture