How to set exposure of an usb camera?

Currently, I’m accessing the Logitech cameras using CameraServer functions.


        CameraServer::GetInstance()->StartAutomaticCapture("AimingCamera",0);
	CameraServer::GetInstance()->StartAutomaticCapture("GearCamera",1);
	CameraServer::GetInstance()->SetSize(CameraServer::kSize640x480);

For vision process, I learned a little bit about OpenCV and wrote the following.


        
        cs::CvSink sink =CameraServer::GetInstance()->GetVideo("AimingCamera");
	cv::Mat frame;
	sink.GrabFrameNoTimeout(frame);
	vision->Process(frame);
	std::vector<std::vector<cv::Point> >*  results = vision->GetFilterContoursOutput();

My question is, is there a way that I can adjust the exposure, or the brightness, of the camera before and after vision process? So that the program process the frames in lower exposure and the driver drives in normal exposure?

Any help is appreciated!

You need the VideoCapture::set method:

C++: bool VideoCapture::set(int propId, double value)

The propId parameter would be CV_CAP_PROP_EXPOSURE or CV_CAP_PROP_BRIGHTNESS, and the value will depend largely on your camera driver.

Thank you for your reply!

I wrote the following line:

cv::VideoCapture::set(CV_CAP_PROP_BRIGHTNESS,0);

and got 2 error messages:
“cannot call member function ‘virtual bool cv::VideoCapture::set(int, double)’ without object”
and “Invalid arguments”.

That is not a static function, it requires that you have an object of type VideoCapture to use to access it. There’s sample code at the hyperlink.

However, VideoCapture is an alternative technique to using the WPILIB cvSink object, so you’d have to restructure your code to use it. VideoCapture asks the camera for a snapshot. cvSink, I believe, builds a still image from a frame of the incoming stream.

I define this:
cs::UsbCamera mCamera0;
Run this:
mCamera0 = CameraServer::GetInstance()->StartAutomaticCapture(0);
mCamera0.SetExposureManual(40);