【问题标题】:How to get video capture devices information?如何获取视频采集设备信息?
【发布时间】:2014-08-29 02:10:14
【问题描述】:

我需要从 C++ 代码中查询连接的视频捕获设备(主要是网络摄像头)的设备信息。这些信息应至少包含帧速率、输出格式和控制值(颜色调整)。

【问题讨论】:

  • 看看 OpenCV 库。不是世界上最小的库,但设计得非常好,支持相当多的目标平台(包括 Windows、Linux、iOS)。它具有(尽管有限)视频捕获支持,这听起来应该足以满足您的需求
  • @YePhIcK 我目前正在使用 OpenCV。我想它没有 API 来枚举视频设备和检索功能、设备信息等。
  • AFAIK 它没有,它提供了一组非常有限的“列表、开始、获取框架”。但是您可以查看(随库提供的)源代码。当我有类似的需求时(在 Windows 上),它最初帮助了我很多

标签: c++ linux opencv v4l2


【解决方案1】:

Opencv 的VideoCapture::get(int propId) 可以获得以下信息

CV_CAP_PROP_POS_MSEC      Current position of the video file in milliseconds or video capture timestamp.
CV_CAP_PROP_POS_FRAMES    0-based index of the frame to be decoded/captured next.
CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file: 0 - start of the film, 1 - end of the film.
CV_CAP_PROP_FRAME_WIDTH   Width of the frames in the video stream.
CV_CAP_PROP_FRAME_HEIGHT  Height of the frames in the video stream.
CV_CAP_PROP_FPS           Frame rate.
CV_CAP_PROP_FOURCC        4-character code of codec.
CV_CAP_PROP_FRAME_COUNT   Number of frames in the video file.
CV_CAP_PROP_FORMAT        Format of the Mat objects returned by retrieve() .
CV_CAP_PROP_MODE          Backend-specific value indicating the current capture mode.
CV_CAP_PROP_BRIGHTNESS    Brightness of the image (only for cameras).
CV_CAP_PROP_CONTRAST      Contrast of the image (only for cameras).
CV_CAP_PROP_SATURATION    Saturation of the image (only for cameras).
CV_CAP_PROP_HUE           Hue of the image (only for cameras).
CV_CAP_PROP_GAIN          Gain of the image (only for cameras).
CV_CAP_PROP_EXPOSURE      Exposure (only for cameras).
CV_CAP_PROP_CONVERT_RGB   Boolean flags indicating whether images should be converted to RGB.
CV_CAP_PROP_WHITE_BALANCE Currently not supported
CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)

例如:

VideoCapture cap(0); // open the default camera
if(!cap.isOpened())  // check it exists
    return -1;
double fps = cap.get(CV_CAP_PROP_FPS);

【讨论】:

  • 不错 :) 那么设备呢?我怎么知道连接了多少设备? (遍历poropId?)
  • “尝试”逐个按索引访问设备,直到失败
  • 您应该遍历传递给 VideoCapture 构造函数的设备 ID。
猜你喜欢
  • 2015-09-09
  • 2019-07-07
  • 1970-01-01
  • 1970-01-01
  • 2012-02-15
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 2013-05-09
相关资源
最近更新 更多