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.
@oferbentovim I've never found a definitive answer, but raw RGB captures don't often work at full resolution. I've had better success with JPEG captures at full resolution, or JPEG plus Bayer data (if you want the full uncompressed pixel data). The latter requires a bit more work to process the image and is slow, but seems way more reliable.