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.

Comments

Popular posts from this blog

OpenCV Stitching example (Stitcher class, Panorama)

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Optical Flow sample source code using OpenCV

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

(OpenCV Study) calcOpticalFlowFarneback example source code ( dense optical flow )

yuv422(YUYV) to RGB and RGB to yuv422(YUYV), (Using OpenCV and TBB)

(C, C++) TinyXML , xml read & write