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";


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

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

  if (waitKey(30) >= 0)


Reference this page
The method to capture video using cvCaptureFromCAM
And reference to set opencv and know basic code structure.

This source code is referenced from ""

Thank you.


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