OpenCV3 VideoCapture buffer

在ubuntu16.04下写关于opencv的工程,在调用摄像头时发现VideoCapture有5帧的buffer,所以采用5个capture>>mat来处理。

if (FlagContinue)
{
  capture >> snap;
}
else
{
  capture >> snap;
  capture >> snap;
  capture >> snap;
  capture >> snap;
  capture >> snap;
}

官方论坛有同学遇到了同样的问题。

http://answers.opencv.org/question/90583/videocapture-buffer/

转载于:https://www.cnblogs.com/bodom/p/9229108.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要获取 USB 摄像头的名称,可以使用 OpenCV 中的 VideoCapture 类。以下是获取 USB 摄像头名称的示例代码: ``` #include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; int main() { int camera_id = 0; VideoCapture cap(camera_id); if (!cap.isOpened()) { cerr << "ERROR: Unable to open the camera" << endl; return 1; } // Get the camera name string camera_name = ""; cap.set(CAP_PROP_SETTINGS, 1); // Open the camera properties dialog cap.set(CAP_PROP_SETTINGS, 0); // Close the camera properties dialog cap.set(CAP_PROP_SETTINGS, 1); // Open the camera properties dialog cap.set(CAP_PROP_SETTINGS, 0); // Close the camera properties dialog cap.set(CAP_PROP_SETTINGS, 1); // Open the camera properties dialog cap.set(CAP_PROP_SETTINGS, 0); // Close the camera properties dialog cap.set(CAP_PROP_SETTINGS, 1); // Open the camera properties dialog cap.set(CAP_PROP_SETTINGS, 0); // Close the camera properties dialog cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer cap >> Mat(); // Release the camera buffer int prop_id = CAP_PROP_FOURCC; int fourcc = static_cast<int>(cap.get(prop_id)); if (fourcc == static_cast<int>(CAP_FFMPEG)) { prop_id = CAP_PROP_BACKEND; int backend_id = static_cast<int>(cap.get(prop_id)); if (backend_id == static_cast<int>(CAP_BACKEND_V4L2)) { prop_id = CAP_PROP_V4L2_CAPS; string v4l2_caps = cap.get(prop_id); size_t name_start_pos = v4l2_caps.find("card="); if (name_start_pos != string::npos) { name_start_pos += strlen("card="); size_t name_end_pos = v4l2_caps.find(",", name_start_pos); if (name_end_pos != string::npos) { camera_name = v4l2_caps.substr(name_start_pos, name_end_pos - name_start_pos); } else { camera_name = v4l2_caps.substr(name_start_pos); } } } else if (backend_id == static_cast<int>(CAP_BACKEND_MSMF)) { prop_id = CAP_PROP_MSMF_DEVICE_NAME; camera_name = cap.get(prop_id); } else if (backend_id == static_cast<int>(CAP_BACKEND_DSHOW)) { prop_id = CAP_PROP_DSHOW_DEVICE_NAME; camera_name = cap.get(prop_id); } else if (backend_id == static_cast<int>(CAP_BACKEND_AVFOUNDATION)) { prop_id = CAP_PROP_AVFOUNDATION_VIDEO_DEVICE_NAME; camera_name = cap.get(prop_id); } } cout << "Camera Name: " << camera_name << endl; return 0; } ``` 此代码使用 `VideoCapture` 类打开摄像头,并通过 `set` 函数打开和关闭摄像头属性对话框。然后,它检索摄像头的名称并将其打印到控制台上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值