I am trying to grab continuous images using Raspicam 1.3v on Raspberry Pi 2.
I use c++ and the following library for interface: http://www.uco.es/investiga/grupos/ava/node/40
When I use raspistill, image is quite nice. However when I use the grab() function in this library, image ends up being quite dark.
I am going to work on 90fps, but the image do not improve even in 30fps.
What might be the cause of this, and how do I approach this problem? I suspect it is a configuration problem on https://github.com/cedricve/raspicam/blob/master/src/private/private_impl.cpp
Image I got was darker when I did not specify saturation and gain. Here is the properties I have set:
CV_CAP_PROP_BRIGHTNESS: [0,100]
left this at automatic mode -1
CV_CAP_PROP_CONTRAST: [0,100]
left this at automatic mode -1 as well
CV_CAP_PROP_SATURATION: [0,100]
used 100
CV_CAP_PROP_GAIN: (iso): [0,100]
used 100
CV_CAP_PROP_EXPOSURE: -1 auto. [1,100] shutter speed from 0 to 33ms
used 100
CV_CAP_PROP_WHITE_BALANCE_RED_V : [1,100] -1 auto whitebalance
left it at automatic mode (anything nonzero messed the image up for some reason)
CV_CAP_PROP_WHITE_BALANCE_BLUE_U : [1,100] -1 auto whitebalance
left it at automatic mode
Below is the test code I used to test:
#include <ctime>
#include <iostream>
#include <raspicam/raspicam_cv.h>
using namespace std;
int main ( int argc,char **argv ) {
time_t timer_begin,timer_end;
raspicam::RaspiCam_Cv Camera;
cv::Mat image;
int nCount=100;
//set camera params
Camera.set( CV_CAP_PROP_FORMAT, CV_8UC1 );
Camera.set( CV_CAP_PROP_FRAME_WIDTH, 640 );
Camera.set( CV_CAP_PROP_FRAME_HEIGHT, 480 );
Camera.set( CV_CAP_PROP_FPS, 90 );
//Open camera
cout<<"Opening Camera..."<<endl;
if (!Camera.open()) {cerr<<"Error opening the camera"<<endl;return -1;}
//Start capture
cout<<"Capturing "<<nCount<<" frames ...."<<endl;
time ( &timer_begin );
for ( int i=0; i<nCount; i++ ) {
Camera.grab();
Camera.retrieve ( image);
if ( i%5==0 ) cout<<"\r captured "<<i<<" images"<<std::flush;
}
cout<<"Stop camera..."<<endl;
Camera.release();
//show time statistics
time ( &timer_end ); /* get current time; same as: timer = time(NULL) */
double secondsElapsed = difftime ( timer_end,timer_begin );
cout<< secondsElapsed<<" seconds for "<< nCount<<" frames : FPS = "<< ( float ) ( ( float ) ( nCount ) /secondsElapsed ) <<endl;
//save image
cv::imwrite("raspicam_cv_image.jpg",image);
cout<<"Image saved at raspicam_cv_image.jpg"<<endl;
}
Here is the image I get with raspistill:
Here is the image I get with grab function: