我在 Ubuntu 12.04LTS 中编写了一个简单的 Opencv 程序,它可以调整网络摄像头(Logitech C525)的设置,例如亮度和曝光等。
它在 Windows 7 中运行良好,但在 Linux 中它给了我这个错误
$ ./adjust-camera
init done
opengl support available
HIGHGUI ERROR: V4L2: Unable to get property Exposure(9963793) - Invalid argument
HIGHGUI ERROR: V4L: Exposure control in V4L is not supported
HIGHGUI ERROR: V4L: Property Exposure(15) not设备支持
HIGHGUI ERROR: V4L: Property Exposure(15) not supported by device
HIGHGUI ERROR: V4L: Property Exposure(15) not supported by device
附带说明一下,如果我启动 Ubuntu 并插入网络摄像头,我可以使用 Cheese 之类的程序打开它。但是如果我用相机运行我的 Opencv 程序,在我关闭 Opencv 后,相机将不再能够在 Cheese 上显示。我必须重新启动 Ubuntu 才能让它与其他任何东西一起工作。
这是代码adjust-camera.cpp
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp" // Basic OpenCV structures (cv::Mat)
#include "opencv2/highgui/highgui.hpp" // Video write
#include "string.h"
using namespace cv;
using namespace std;
void calibrateCamera();
void getCameraVals();
VideoCapture cam(0);
//variables for cam camera
int brightness_slider=125;
int contrast_slider=86;
int gain_slider=77;
int saturation_slider=34;
int exposure_slider=6; //exposure range is from 0 to -7.
int main()
{
namedWindow("camera 1",WINDOW_AUTOSIZE);
Mat frame;
getCameraVals();
createTrackbar("Brightness", "camera 1", &brightness_slider, 255);
createTrackbar("Contrast", "camera 1", &contrast_slider, 255);
createTrackbar("Gain", "camera 1", &gain_slider, 255);
createTrackbar("Saturation", "camera 1", &saturation_slider, 255);
createTrackbar("Exposure", "camera 1", &exposure_slider, 2047);
while(true)
{
calibrateCamera();
cam>>frame;
imshow("camera 1",frame);
if(waitKey(3)>=0) break;
}
return(0);
}
void getCameraVals()
{
brightness_slider = cam.get(CV_CAP_PROP_BRIGHTNESS);
contrast_slider = cam.get(CV_CAP_PROP_CONTRAST);
gain_slider=cam.get(CV_CAP_PROP_GAIN);
saturation_slider=cam.get(CV_CAP_PROP_SATURATION);
exposure_slider=cam.get(CV_CAP_PROP_EXPOSURE);
}
void calibrateCamera()
{
cam.set(CV_CAP_PROP_BRIGHTNESS, brightness_slider);
cam.set(CV_CAP_PROP_CONTRAST, contrast_slider);
cam.set(CV_CAP_PROP_GAIN, gain_slider);
cam.set(CV_CAP_PROP_SATURATION, saturation_slider);
cam.set(CV_CAP_PROP_EXPOSURE, exposure_slider);
//cam.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
//cam.set(CV_CAP_PROP_FRAME_HEIGHT, 720);
}
这是我用来编译的脚本
![enter image description here][1]ls#!/bin/bash
echo "compiling $1"
if [[ $1 == *.c ]]
then
gcc -ggdb `pkg-config --cflags opencv` -o `basename $1 .c` $1 `pkg-config --libs opencv`;
elif [[ $1 == *.cpp ]]
then
g++ -ggdb `pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `pkg-config --libs opencv`;
else
echo "Please compile only .c or .cpp files"
fi
echo "Output file => ${1%.*}"
这是相机使用 Cheese 或在 Windows 中使用我的 Opencv 程序显示的内容
这是 OpenCV 在 Ubuntu 上显示的内容
有想法该怎么解决这个吗?