VideoCapture源代码分析

本文转自: http://blog.csdn.net/dsgthlr/article/details/42265107

[cpp] view plain copy print ?
  1. 获取摄像头图像代码  
[cpp] view plain copy print ?
  1. #include "opencv2/opencv.hpp"  
  2.   
  3. using namespace cv;  
  4.   
  5. int main(intchar**)  
  6. {  
  7.     VideoCapture cap(0); // open the default camera  
  8.     if(!cap.isOpened())  // check if we succeeded  
  9.         return -1;  
  10.   
  11.     Mat edges;  
  12.     namedWindow("edges",1);  
  13.     for(;;)  
  14.     {  
  15.         Mat frame;  
  16.         cap >> frame; // get a new frame from camera  
  17.         cvtColor(frame, edges, COLOR_BGR2GRAY);  
  18.         GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);  
  19.         Canny(edges, edges, 0, 30, 3);  
  20.         imshow("edges", edges);  
  21.         if(waitKey(30) >= 0) break;  
  22.     }  
  23.     // the camera will be deinitialized automatically in VideoCapture destructor  
  24.     return 0;  
  25. }  
[cpp] view plain copy print ?
  1.   
[cpp] view plain copy print ?
  1. <pre name="code" class="cpp">class CV_EXPORTS_W VideoCapture  
  2. {  
  3. public:  
  4.     CV_WRAP VideoCapture();  
  5.     CV_WRAP VideoCapture(const String& filename);       <span style="white-space:pre">    </span>//open video from url;  
  6.     CV_WRAP VideoCapture(int device);                   //open device  
  7.   
  8.     virtual ~VideoCapture();  
  9.     CV_WRAP virtual bool open(const String& filename);<span style="white-space:pre">          </span><span style="font-family: Arial, Helvetica, sans-serif;">                        </span><span style="font-family: Arial, Helvetica, sans-serif;">  
  10. </span>    CV_WRAP virtual bool open(int device);<span style="white-space:pre">             </span><pre name="code" class="cpp"><span style="white-space:pre">                                    </span>//<span style="font-family: Arial, Helvetica, sans-serif;">VideoCapture cap(0)   等价于</span><pre name="code" class="cpp"><span style="font-family: Arial, Helvetica, sans-serif;"><span>                                                                      </span>//VideoCapture cap;</span>  
[cpp] view plain copy print ?
  1. <span style="font-family: Arial, Helvetica, sans-serif;"><span>                                                                     </span>//cap.open(0);<span> </span></span>  
 
 

CV_WRAP virtual bool isOpened() const; //check if open sucessed CV_WRAP virtual void release();//close the already opened file or camera.CV_WRAP virtual bool grab();//The primary use of the function is in multi-camera environments, CV_WRAP virtual bool retrieve(OutputArray image, int flag = 0); virtual VideoCapture& operator >> (CV_OUT Mat& image); virtual VideoCapture& operator >> (CV_OUT UMat& image);

 
 
[cpp] view plain copy print ?
  1.     CV_WRAP virtual bool read(OutputArray image);<span style="white-space:pre">           </span>//cap.read(frame);等价于  cap>>frame;  
  2.   
  3.     CV_WRAP virtual bool set(int propId, double value);  
  4.     CV_WRAP virtual double get(int propId);  
  5.   
  6. protected:  
  7.     Ptr<CvCapture> cap;  
  8.     Ptr<IVideoCapture> icap;  
  9. private:  
  10.     static Ptr<IVideoCapture> createCameraCapture(int index);  
  11. };  


你可能感兴趣的:(VideoCapture源代码分析)