I have found that using raspistill with the --timeout option to significantly reduce the time before the camera takes a photo doesn't give the camera enough time to choose good exposure parameters (e.g. shutterspeed and iso).

My aim is to 'calibrate' the camera to the lighting conditions by taking a photo normally using raspistill (without the --timeout) and then use the values which raspistill chose for the shutter speed and iso for all future photos.

I am doing this inside a C++ program, using system() to call raspistill. I thought I could use exiftool (or similar) to extract the shutterspeed and iso from the exif data attached to the initial 'calibration' photo. However, the shutter speed in the exif data is recorded as a string representation of a fraction, e.g. '1/8'.

I have found this patch for specifying shutterspeed as a fraction but it is quite old and doesn't seem to have been merged into the official code. I'm assuming there was a reason behind this. I am also hesitant about downloading and making userland because I read somewhere that you could end up with a dead pi.

Does anyone either

  • know whether this patch is stable (and could you tell me how to integrate it?),
  • know of a way to parse a cstring (char*) containing something like "1/8" to convert it to a value in microseconds (an integer, double or as a string),
  • know of any other way to accomplish what I want?

Thank you very much in advanced.


After a lot more hunting, I came up with the (C++11) snippet:

char* shutterSpeed_exif = "1/8"; // My starting point

// Convert fraction to microseconds
string shutterSpeed_frac = shutterSpeed_exif;
unsigned int idx = shutterSpeed_frac.find('/');
double numerator = stod(shutterSpeed_frac.substr(0,idx));
double denominator = stod(shutterSpeed_frac.substr(idx+1));
m_ShutterSpeed = (numerator / denominator) * 1000000; // Convert seconds to microseconds

I can now save this and pass it as an argument to raspistill.

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.