opencv学习之VideoCapture

获取摄像头图像代码
#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;
}

类成员:
<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>
<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);
};


 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值