Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You could use VideoCapture::get() to get camera property. Also don’t use out dated C instead use new C++ interface.

See below C++ code

float Brightness;
float Contrast ;
float Saturation;
float Gain;

int B;
int C;
int S;
int G;

char winName[20]="Live";
Mat frame;
VideoCapture cap(0);

void onTrackbar_changed(int, void*)
{
 Brightness =float(B)/100;
 Contrast   =float(C)/100;
 Saturation =float(S)/100;
 Gain       =float(G)/100;

cap.set(CV_CAP_PROP_BRIGHTNESS,Brightness);
cap.set(CV_CAP_PROP_CONTRAST, Contrast);
cap.set(CV_CAP_PROP_SATURATION, Saturation);
cap.set(CV_CAP_PROP_GAIN, Gain);

}

int main(int, char**)
{

    if(!cap.isOpened())  // check if we succeeded
        return -1;

    cout<<"Press 's' to save snapshot"<<endl;
 namedWindow(winName);

 Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS);
 Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
 Saturation = cap.get(CV_CAP_PROP_SATURATION);
 Gain       = cap.get(CV_CAP_PROP_GAIN);

 cout<<"===================================="<<endl<<endl;
 cout<<"Default Brightness -------> "<<Brightness<<endl;
 cout<<"Default Contrast----------> "<<Contrast<<endl;
 cout<<"Default Saturation--------> "<<Saturation<<endl;
 cout<<"Default Gain--------------> "<<Gain<<endl<<endl;
 cout<<"===================================="<<endl;

  B=int(Brightness*100);
  C=int(Contrast*100);
  S=int(Saturation*100);
  G=int(Gain*100);

createTrackbar( "Brightness",winName, &B, 100, onTrackbar_changed );
createTrackbar( "Contrast",winName, &C, 100,onTrackbar_changed );
createTrackbar( "Saturation",winName, &S, 100,onTrackbar_changed);
createTrackbar( "Gain",winName, &G, 100,onTrackbar_changed);

    int i=0;
    char name[10];
    for(;;)
    {

        cap >> frame; // get a new frame from camera
        imshow(winName, frame);
        char c=waitKey(30);

        if(c=='s') {
     sprintf(name,"%d.jpg",i++);
     imwrite(name,frame);
    }
        if( c== 27) break;
    }
return 0;

}

image description

You could use VideoCapture::get() to get camera property. Also don’t use out dated C instead use new C++ interface.

See below C++ codecode, which will access default camera parameters, and also you can change it using track-bar.

float Brightness;
float Contrast ;
float Saturation;
float Gain;

int B;
int C;
int S;
int G;

char winName[20]="Live";
Mat frame;
VideoCapture cap(0);

void onTrackbar_changed(int, void*)
{
 Brightness =float(B)/100;
 Contrast   =float(C)/100;
 Saturation =float(S)/100;
 Gain       =float(G)/100;

cap.set(CV_CAP_PROP_BRIGHTNESS,Brightness);
cap.set(CV_CAP_PROP_CONTRAST, Contrast);
cap.set(CV_CAP_PROP_SATURATION, Saturation);
cap.set(CV_CAP_PROP_GAIN, Gain);

}

int main(int, char**)
{

    if(!cap.isOpened())  // check if we succeeded
        return -1;

    cout<<"Press 's' to save snapshot"<<endl;
 namedWindow(winName);

 Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS);
 Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
 Saturation = cap.get(CV_CAP_PROP_SATURATION);
 Gain       = cap.get(CV_CAP_PROP_GAIN);

 cout<<"===================================="<<endl<<endl;
 cout<<"Default Brightness -------> "<<Brightness<<endl;
 cout<<"Default Contrast----------> "<<Contrast<<endl;
 cout<<"Default Saturation--------> "<<Saturation<<endl;
 cout<<"Default Gain--------------> "<<Gain<<endl<<endl;
 cout<<"===================================="<<endl;

  B=int(Brightness*100);
  C=int(Contrast*100);
  S=int(Saturation*100);
  G=int(Gain*100);

createTrackbar( "Brightness",winName, &B, 100, onTrackbar_changed );
createTrackbar( "Contrast",winName, &C, 100,onTrackbar_changed );
createTrackbar( "Saturation",winName, &S, 100,onTrackbar_changed);
createTrackbar( "Gain",winName, &G, 100,onTrackbar_changed);

    int i=0;
    char name[10];
    for(;;)
    {

        cap >> frame; // get a new frame from camera
        imshow(winName, frame);
        char c=waitKey(30);

        if(c=='s') {
     sprintf(name,"%d.jpg",i++);
     imwrite(name,frame);
    }
        if( c== 27) break;
    }
return 0;

}

image description

You could use VideoCapture::get() to get camera property. Also don’t use out dated out-dated C instead use new C++ interface.

See below C++ code, which will access default camera parameters, and also you can change it using track-bar. I have tested it with Logitech webcam and works fine.

float Brightness;
float Contrast ;
float Saturation;
float Gain;

int B;
int C;
int S;
int G;

char winName[20]="Live";
Mat frame;
VideoCapture cap(0);

void onTrackbar_changed(int, void*)
{
 Brightness =float(B)/100;
 Contrast   =float(C)/100;
 Saturation =float(S)/100;
 Gain       =float(G)/100;

cap.set(CV_CAP_PROP_BRIGHTNESS,Brightness);
cap.set(CV_CAP_PROP_CONTRAST, Contrast);
cap.set(CV_CAP_PROP_SATURATION, Saturation);
cap.set(CV_CAP_PROP_GAIN, Gain);

}

int main(int, char**)
{

    if(!cap.isOpened())  // check if we succeeded
        return -1;

    cout<<"Press 's' to save snapshot"<<endl;
 namedWindow(winName);

 Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS);
 Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
 Saturation = cap.get(CV_CAP_PROP_SATURATION);
 Gain       = cap.get(CV_CAP_PROP_GAIN);

 cout<<"===================================="<<endl<<endl;
 cout<<"Default Brightness -------> "<<Brightness<<endl;
 cout<<"Default Contrast----------> "<<Contrast<<endl;
 cout<<"Default Saturation--------> "<<Saturation<<endl;
 cout<<"Default Gain--------------> "<<Gain<<endl<<endl;
 cout<<"===================================="<<endl;

  B=int(Brightness*100);
  C=int(Contrast*100);
  S=int(Saturation*100);
  G=int(Gain*100);

createTrackbar( "Brightness",winName, &B, 100, onTrackbar_changed );
createTrackbar( "Contrast",winName, &C, 100,onTrackbar_changed );
createTrackbar( "Saturation",winName, &S, 100,onTrackbar_changed);
createTrackbar( "Gain",winName, &G, 100,onTrackbar_changed);

    int i=0;
    char name[10];
    for(;;)
    {

        cap >> frame; // get a new frame from camera
        imshow(winName, frame);
        char c=waitKey(30);

        if(c=='s') {
     sprintf(name,"%d.jpg",i++);
     imwrite(name,frame);
    }
        if( c== 27) break;
    }
return 0;

}

image description