gpt4 book ai didi

opencv - Ubuntu Opencv Camera settings V4L2 error 不支持曝光控制

转载 作者:行者123 更新时间:2023-12-02 17:50:19 33 4
gpt4 key购买 nike

我在 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 supported by device
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 程序显示的内容
Here is what the camera displays with Cheese or in Windows using my Opencv program

这是 OpenCV 在 Ubuntu 上显示的内容
Here is what OpenCV displays on Ubuntu

有想法该怎么解决这个吗?

最佳答案

问题与您使用的范围有关。 CV 属性的值是 0 到 1 之间的两倍,但您使用的轨迹栏的值从 0 到 255...
一种可能的解决方案是将所有内容放在相同的范围内,例如从 0 到 100。

#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=25;
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, 100);
createTrackbar("Contrast", "camera 1", &contrast_slider, 100);
createTrackbar("Gain", "camera 1", &gain_slider, 100);
createTrackbar("Saturation", "camera 1", &saturation_slider, 100);
createTrackbar("Exposure", "camera 1", &exposure_slider, 100);

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)*100;
contrast_slider = cam.get(CV_CAP_PROP_CONTRAST)*100;
gain_slider=cam.get(CV_CAP_PROP_GAIN)*100;
saturation_slider=cam.get(CV_CAP_PROP_SATURATION)*100;
exposure_slider=cam.get(CV_CAP_PROP_EXPOSURE)*100;

}
void calibrateCamera()
{
cam.set(CV_CAP_PROP_BRIGHTNESS, double(brightness_slider/100));
cam.set(CV_CAP_PROP_CONTRAST, double(contrast_slider/100));
cam.set(CV_CAP_PROP_GAIN, double(gain_slider/100));
cam.set(CV_CAP_PROP_SATURATION, double(saturation_slider/100));
cam.set(CV_CAP_PROP_EXPOSURE, double(exposure_slider/100));
//cam.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
//cam.set(CV_CAP_PROP_FRAME_HEIGHT, 720);
}

希望对你有帮助!!!

关于opencv - Ubuntu Opencv Camera settings V4L2 error 不支持曝光控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23418480/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com