How to change the contrast and brightness of the camera?
Hi, I am using opencv and microsoft visual studio 2010 express edition. I have made a windows form application for camera (uEye camera) control. I tried to change the contrast and brightness of my camera using this code:
cvSetCaptureProperty(capture,CV_CAP_PROP_BRIGHTNESS,trackBar1->Value);
cvSetCaptureProperty(capture,CV_CAP_PROP_CONTRAST,trackBar2->Value);
There are no errors but the brightness and the contrast are the same as previous without a change.
Could you please give me an advise.
Here is my code:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
capture = cvCaptureFromCAM(0);
cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH,640) ;
cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT,480) ;
cvSetCaptureProperty(capture,CV_CAP_PROP_FPS, 40.00) ;
cvSetCaptureProperty(capture,CV_CAP_PROP_BRIGHTNESS,trackBar1->Value);
cvSetCaptureProperty(capture,CV_CAP_PROP_CONTRAST,trackBar2->Value);
timer1->Start();
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
IplImage* frame = cvQueryFrame(capture);
pictureBox2->Image = gcnew //replacement of cvShowImage
System::Drawing::Bitmap(frame->width,frame->height,frame->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame->imageData);
pictureBox2->Refresh();
gray = cvQueryFrame(capture);
cvThreshold(frame, gray, 100,255,CV_THRESH_BINARY_INV);
pictureBox1->Image = gcnew //replacement of cvShowImage
System::Drawing::Bitmap(gray->width,gray->height,gray->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) gray->imageData);
pictureBox1->Refresh();
}
your camera driver probably does not support it.
check the return value for cvSetCaptureProperty(), if it's false, - you know.
I have checked cvSetCaptureProperty() on this way:
int ret = cvSetCaptureProperty(capture,CV_CAP_PROP_BRIGHTNESS,trackBar1->Value); if (ret == 0) button2->Text = "OK";
I made this checking and for the other lines with cvSetCaptureProperty and the result is always equal to 1. I think if my camera doesn't support the property CV_CAP_PROP_BRIGHTNESS, it will give me 1 and for the property CV_CAP_PROP_FRAME_WIDTH, it will give me 0. In my case the result always is 1. In this situation this property has to be maintained by my camera.