This gist contains a very minimal Python script that shows how to set the analogue and digital gains of the Raspberry Pi camera module from within Python. It is a trivial thing, all the actual work was done by the developers of userland in particular 6by9, and of course the developers of picamera. It does require the latest version of the userland libraries in order to be able to send the gain-setting commands. These are not yet (as of January 2018) in the main Raspbian distribution, but it is not scary to build this yourself:
sudo apt-get install cmake
git clone https://github.com/raspberrypi/userland.git
cd userland
./buildme
sudo shutdown -r now
After you've got the latest version of the userland libraries, you should be able to run
python set_gain.py
This will open a preview window and then freeze the analogue and digital gains at 1. Look at the code to see how it's done - it is not complicated. To use this in your own code, just do:
import picamera
from set_picamera_gain import set_analog_gain, set_digital_gain
with picamera.PiCamera() as cam:
set_analog_gain(cam, 2)
set_digital_gain(cam, 1)
Hopefully I will get round to making a pull request to picamera - but of course that's only really useful once the userland code is updated in the distribution.
I am trying to reverse engineer this for a project using the C++ raspicam library. I'm setting the gains, I think appropriately, but it is not working.
What is the significance of line 49?
cam.shutter_speed = cam.exposure_speed
In the C++ I set shutter speed to a value I like, and exposure to off. I think this should do the same thing?