Ask Your Question
0

How to change the contrast and brightness of the camera?

asked 2014-03-06 04:05:39 -0600

tiho_bg gravatar image

updated 2014-03-06 04:16:25 -0600

berak gravatar image

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();

         }
edit retag flag offensive close merge delete

Comments

1

your camera driver probably does not support it.

check the return value for cvSetCaptureProperty(), if it's false, - you know.

berak gravatar imageberak ( 2014-03-06 04:25:48 -0600 )edit

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.

tiho_bg gravatar imagetiho_bg ( 2014-03-11 03:25:20 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-03-25 15:50:04 -0600

Here is my code (winapi) - it works:

case WM_HSCROLL: switch (LOWORD(wParam)) {

  case TB_ENDTRACK:           {
          if ((HWND)lParam==hSliBright){

              char buf[100] = "Brightness: ";
              char tmp[10];
              dwPos = SendMessage(hSliBright, TBM_GETPOS, 0, 0);
              strncat(buf,_itoa(dwPos,tmp,10),strlen(buf));
              SetWindowText( hLabBright, buf);
              cam->capture.set(CV_CAP_PROP_BRIGHTNESS,dwPos);
              /*if (dwPos > 100) 
              SendMessage(hSliBright, TBM_SETPOS, 
              (WPARAM) TRUE,       // redraw flag 
              (LPARAM) 100); 

              else if (dwPos < 0) 
              SendMessage(hSliBright, TBM_SETPOS, 
              (WPARAM) TRUE,       // redraw flag 
              (LPARAM) 0); */
              buf[0];
              tmp[0];
              break; 
          }
          if ((HWND)lParam==hSliContrast)
          {
              char buf[100] = "Contrast: ";
              char tmp[10];
              dwPos = SendMessage(hSliContrast, TBM_GETPOS, 0, 0);
              strncat(buf,_itoa(dwPos,tmp,10),strlen(buf));
              SetWindowText( hLabContrast, buf);
              cam->capture.set(CV_CAP_PROP_CONTRAST,dwPos);
              buf[0];
              tmp[0];
              break; 
          }           }       default: 

      break;          }       break;
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-03-06 04:05:39 -0600

Seen: 8,791 times

Last updated: Mar 25 '14