I wrote a simple Opencv program in Ubuntu 12.04LTS that adjusts a webcam (Logitech C525) settings like brightness and exposure and such.
It works fine in Windows 7, but in Linux it gives me this error
$ ./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
On a side note, if I bootup Ubuntu and plug in the webcam, I can open it with a program like Cheese. But if I run my Opencv program with the camera, after I close Opencv the camera will no longer be able to show on Cheese. I have to reboot Ubuntu in order for it to work with anything else.
Here is the code 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);
}
Here is the script I use to compile
![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%.*}"
Here is what the camera displays with Cheese or in Windows using my Opencv program
Here is what OpenCV displays on Ubuntu
Any ideas on how to fix this?