(Raspberry Pi 3)如何使用set()函数(从raspicam / raspicam_cv.h)设置相机属性?

时间:2019-02-16 15:29:18

标签: c++ opencv raspberry-pi

当我尝试为相机设置参数时,在编译过程中出现此错误:

  

错误:在此范围内未声明“ CV_CAP_PROP_FORMAT”   Camera.set(CV_CAP_PROP_FORMAT,CV_8UC3);

就像编译器不知道所有相机的属性(宏)一样。 对于CV_CAP_PROP_FRAME_WIDTHCV_CAP_PROP_FRAME_HEIGHT我遇到了相同的错误。

我认为错误可能是由于缺少某些库或我错误安装了raspicam package

代码在这里(FRAME_WIDTHFRAME_HEIGHT是我定义的常量):

#include <stdio.h>
#include <raspicam/raspicam_cv.h>

raspicam::RaspiCam_Cv Camera;
cv::Mat image;   

//set camera params
Camera.set( CV_CAP_PROP_FORMAT, CV_8UC3 );
Camera.set( CV_CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);
Camera.set( CV_CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);

1 个答案:

答案 0 :(得分:0)

您可能需要使用cv::并删除这些CV_(它们通常是旧式标志)。您可以看到它们的定义here。另外,FRAME_WIDTHFRAME_HEIGHT都不来自OpenCV,我看不到您在哪里定义它们。

// [...]
Camera.set(cv::CAP_PROP_FORMAT, cv::CV_8UC3);
Camera.set(cv::CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);   // FRAME_WIDTH?
Camera.set(cv::CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT); // FRAME_HEIGHT?
// [...]

您还可以检查可以设置哪些属性以读取raspicam/raspicam_cv.h

/**Sets a property in the VideoCapture. 
 * 
 * 
 * Implemented properties:
 * cv::CAP_PROP_FRAME_WIDTH,cv::CAP_PROP_FRAME_HEIGHT,
 * cv::CAP_PROP_FORMAT: CV_8UC1 or CV_8UC3
 * cv::CAP_PROP_BRIGHTNESS: [0,100]
 * cv::CAP_PROP_CONTRAST: [0,100]
 * cv::CAP_PROP_SATURATION: [0,100]
 * cv::CAP_PROP_GAIN: (iso): [0,100]
 * cv::CAP_PROP_EXPOSURE: -1 auto. [1,100] shutter speed from 0 to 33ms
 * cv::CAP_PROP_WHITE_BALANCE_RED_V : [1,100] -1 auto whitebalance
 * cv::CAP_PROP_WHITE_BALANCE_BLUE_U : [1,100] -1 auto whitebalance
 * cv::CAP_PROP_MODE : [1,7] 0 auto mode
 *
 */

bool set ( int propId, double value );