本文主要是介绍VideoCapture源代码分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文转自: http://blog.csdn.net/dsgthlr/article/details/42265107- 获取摄像头图像代码
获取摄像头图像代码
- #include "opencv2/opencv.hpp"
- 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, COLOR_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;
- }
#include "opencv2/opencv.hpp"using namespace cv;int main(int, char**)
{VideoCapture cap(0); // open the default cameraif(!cap.isOpened()) // check if we succeededreturn -1;Mat edges;namedWindow("edges",1);for(;;){Mat frame;cap >> frame; // get a new frame from cameracvtColor(frame, edges, COLOR_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 destructorreturn 0;
}
</pre><div class="dp-highlighter bg_cpp"><div class="bar"><div class="tools"><strong>[cpp]</strong> <a target=_blank title="view plain" class="ViewSource" href="http://blog.csdn.net/dsgthlr/article/details/42265107#">view plain</a><a target=_blank title="copy" class="CopyToClipboard" href="http://blog.csdn.net/dsgthlr/article/details/42265107#">copy</a><a target=_blank title="print" class="PrintSource" href="http://blog.csdn.net/dsgthlr/article/details/42265107#">print</a><a target=_blank title="?" class="About" href="http://blog.csdn.net/dsgthlr/article/details/42265107#">?</a></div></div><ol class="dp-cpp"><li class="alt"><span><span>类成员: </span></span></li></ol></div><pre class="cpp" style="display: none;" name="code">类成员:
- <pre name="code" class="cpp">class CV_EXPORTS_W VideoCapture
- {
- public:
- CV_WRAP VideoCapture();
- CV_WRAP VideoCapture(const String& filename); <span style="white-space:pre"> </span>//open video from url;
- CV_WRAP VideoCapture(int device); //open device
- virtual ~VideoCapture();
- 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;">
- </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>
<pre name="code" class="cpp">class CV_EXPORTS_W VideoCapture
{
public:CV_WRAP VideoCapture();CV_WRAP VideoCapture(const String& filename); <span style="white-space:pre"> </span>//open video from url;CV_WRAP VideoCapture(int device); //open devicevirtual ~VideoCapture();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;">
</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>
- <span style="font-family: Arial, Helvetica, sans-serif;"><span> </span>//cap.open(0);<span> </span></span>
<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);
- CV_WRAP virtual bool read(OutputArray image);<span style="white-space:pre"> </span>//cap.read(frame);等价于 cap>>frame;
- CV_WRAP virtual bool set(int propId, double value);
- CV_WRAP virtual double get(int propId);
- protected:
- Ptr<CvCapture> cap;
- Ptr<IVideoCapture> icap;
- private:
- static Ptr<IVideoCapture> createCameraCapture(int index);
- };
CV_WRAP virtual bool read(OutputArray image);<span style="white-space:pre"> </span>//cap.read(frame);等价于 cap>>frame;CV_WRAP virtual bool set(int propId, double value);CV_WRAP virtual double get(int propId);protected:Ptr<CvCapture> cap;Ptr<IVideoCapture> icap;
private:static Ptr<IVideoCapture> createCameraCapture(int index);
};
这篇关于VideoCapture源代码分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!