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:

left this at automatic mode -1

left this at automatic mode -1 as well

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.retrieve ( image);
if ( i%5==0 ) cout<<"\r captured "<<i<<" images"<<std::flush;
cout<<"Stop camera..."<<endl;
//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 
cout<<"Image saved at raspicam_cv_image.jpg"<<endl;

Here is the image I get with raspistill:

enter image description here

Here is the image I get with grab function:

enter image description here

  • I am having a similar problem in v0.1.3. Like you, I have tried about everything and find that despite using RASPICAM_EXPOSURE_OFF and specifying a shutter speed, the camera still behaves as if it is in AUTO mode.
    – ph0t0n
    Apr 23, 2016 at 0:41
  • Please let me know if you find a solution, I have ended up reducing the fps of my camera just because of it.
    – ozgeneral
    Apr 23, 2016 at 8:11
  • Proper code indentation and white space would make your code a lot easier to read, and therefore much more likely to get the help you want.
    – Jacobm001
    Apr 25, 2016 at 0:23

2 Answers 2


I don't know the exact solution to your problem, but I had the same issue with raspistill when the camera had not enough time to "warm up" (when the --timout option is set to 0 or a only a few microseconds).

Try to add a second of sleep() before //Start capture.

I hope this helps!

  • Sadly, the quality barely improved. I think this should be about the way camera sets itself but honestly I am stuck.
    – ozgeneral
    Feb 24, 2016 at 18:44

Trying changing shutter speed to zero if it is not already zero in private_impl.cpp in raspicam/src/private/.

Shutter speed decides the time till which the frames is exposed hence regulates the amount of light received by the frame. Also try increasing the iso. ![private_impl.cpp]1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.