Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not set awb_gains #318

Closed
messismore opened this issue Aug 24, 2016 · 4 comments
Closed

Can not set awb_gains #318

messismore opened this issue Aug 24, 2016 · 4 comments

Comments

@messismore
Copy link

Hi everyone,

I am trying to hard code a certain white balance for a time lapse camera, however, it seems like setting camera.awb_gains = Fraction(497, 256), Fraction(177, 128) has no effect. The code below outputs a different awb_gains each time.

import picamera
import time
from fractions import Fraction


camera = picamera.PiCamera()
camera.framerate = 10

time.sleep(1)
# This capture discovers initial AWB and SS.
camera.capture('try.jpg')
camera.shutter_speed = camera.exposure_speed
currentss = camera.exposure_speed
camera.exposure_mode = 'off'
camera.resolution = (1920, 1080)
camera.awb_mode = 'off'
camera.awb_gains = (Fraction(497, 256), Fraction(177, 128))

print camera.awb_gains
$ python wb_gains_test.py 
(Fraction(203, 256), Fraction(675, 256))
$ python wb_gains_test.py 
(Fraction(211, 256), Fraction(367, 128))
$ python wb_gains_test.py
(Fraction(197, 256), Fraction(675, 256))

What a I doing wrong?

@Berryfier
Copy link

The value of awb_gains used by print seems to take a while to settle. Inserting repeat print and capture statements will reveal this unexpected behaviour. However, looking at repeat captures, the used value of awb_gains does seem to be very close to what is input.

@6by9
Copy link
Collaborator

6by9 commented Oct 21, 2016

Reading awb_gains returns the values used on the last completed image.

You've set new values and immediately requested the settings before a new frame has been generated, therefore you're reading back stale data. Either set awb_gains before you start the camera streaming, or delay by at least one frame time, and you should get the value you set (rounded to the nearest 1/256th).

@waveform80
Copy link
Owner

This looks pretty comprehensively answered to me, so I'll close it (feel free to re-open if you've got anything further to add though!)

@JolleJolles
Copy link

JolleJolles commented Jul 31, 2019

I have a similar issue. I created the following script based on the picamera documentation

`from time import sleep
from picamera import PiCamera
from fractions import Fraction

camera = PiCamera(resolution=(1280, 720), framerate=30)
camera.iso = 100
sleep(2)
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'off'
camera.awb_gains = (2.5, 2.5)
camera.capture('try.jpg')
print(camera.awb_gains)`

But whatever I put as camera.awb_gains, also with Fractions, the values returned are always very similar fractions in the range (Fraction(167, 128), Fraction(257, 128)). The images returned also always have a nice white balance and not the overly red or blue that I would expect with the provided awb_gains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants