9/30/2013

OpenCV video capture (using VideoCapture, Mat class)

The method to video capture using VideoCapture function and Mat class.

Source code is..

...
void main()
{
 VideoCapture stream1(1);   //0 is the id of video device.0 if you have only one camera
 
 if (!stream1.isOpened()) { //check if video device has been initialised
  cout << "cannot open camera";
 }

 namedWindow("Processing");
 namedWindow("Origin");

 //unconditional loop
 while (true) {
  Mat cameraFrame;
  stream1.read(cameraFrame); //get one frame form video
  imshow("Origin", cameraFrame);

  Sobel(cameraFrame, cameraFrame, CV_8U, 1, 0); //sobel processing
  imshow("Processing",cameraFrame);

  if (waitKey(30) >= 0)
   break;
 }

 destroyAllWindows();
 
 
}
...



Reference this page
The method to capture video using cvCaptureFromCAM
http://feelmare.blogspot.kr/2011/11/web-cam-capture-source-code-using.html
And reference to set opencv and know basic code structure.
http://feelmare.blogspot.kr/2013/08/visual-studio-2012-opencv-246-setting.html

This source code is referenced from "http://thefreecoder.wordpress.com/2012/09/11/opencv-c-video-capture/"

Thank you.

No comments:

Post a Comment