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

New AWB algorithm breaks AWB gains after resolution change #1215

Open
jtc42 opened this issue Aug 1, 2019 · 14 comments
Open

New AWB algorithm breaks AWB gains after resolution change #1215

jtc42 opened this issue Aug 1, 2019 · 14 comments

Comments

@jtc42
Copy link

jtc42 commented Aug 1, 2019

Describe the bug
When using the new AWB algorithm, setting AWB gains is broken after changing the camera resolution (and possibly other properties?). Upon changing the resolution, the AWB gains seem to reset to their Auto values, and changing them back is broken.

To reproduce
Easiest to demonstrate in Python

import picamera as cam
import time

c = cam.PiCamera()
c.start_preview()

# Set the AWB mode to change the gains
c.awb_mode = "tungsten"
time.sleep(2)

# Show, and store, the gains it settled on
print(c.awb_gains)
g = c.awb_gains

# Turn auto AWB off, fixing the gains
c.awb_mode = "off"
time.sleep(2)

# Store the current resolution
r=c.resolution

# Apply a "new" resolution
c.resolution=r

print("At this point, the AWB gains will have reset if using the new AWB algorithm")
time.sleep(1)

# Try to set the AWB gains back
c.awb_gains = g

# Note: it didn't work
print(c.awb_gains)
# Wait for it to work...
time.sleep(2)

# It still doesn't work...
print(c.awb_gains)
print(c.awb_mode)
c.stop_preview()

Expected behaviour

  1. Changing resolution shouldn't reset the AWB gains
  2. AWB gains should be changeable after this anyway, if AWB is off.

Actual behaviour

  1. Changing resolution resets AWB gains, seemingly to their values when AWB is set to "auto"
  2. Turning the AWB off and trying to set new AWB gains after this point silently fails. AWB gains remain fixed at their reset values.

System

  • Pi3B+
  • Firmware 38e81f2, and 1.20190718 tested

Additional context
These issues seem related:
waveform80/picamera#581
waveform80/picamera#580

popcornmix added a commit that referenced this issue Aug 28, 2019
kernel: watchdog: bcm2835_wdt: Fix module autoload
See: raspberrypi/linux#3187

kernel: staging: bcm2835-codec: remove unnecessary padding on encoder input
See: raspberrypi/linux#3179

kernel: staging: bcm2835-codec: add support for V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME
See: raspberrypi/linux#3175

firmware: AWB: Fix for manual WB settings in capture
See: #1215
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Aug 28, 2019
kernel: watchdog: bcm2835_wdt: Fix module autoload
See: raspberrypi/linux#3187

kernel: staging: bcm2835-codec: remove unnecessary padding on encoder input
See: raspberrypi/linux#3179

kernel: staging: bcm2835-codec: add support for V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME
See: raspberrypi/linux#3175

firmware: AWB: Fix for manual WB settings in capture
See: raspberrypi/firmware#1215
@JeffJassky
Copy link

JeffJassky commented Aug 31, 2019

For anyone else experiencing this, this work-around shared by @6by9 works well for me. Run this code before running raspistill, raspivid, or using picamera.

sudo vcdbg set awb_mode 0 Note next comment @6by9 regarding updating to latest rpi-update.

@6by9
Copy link

6by9 commented Aug 31, 2019

The fix for the issue is in the latest rpi-update firmware.

sudo vcdbg set awb_mode 0 just switches back to the old algorithm, which doesn't help on a Pi4 as the old algorithm can't work due to the change in 3D hardware. Whilst it will work in the short term, it can not be recommended longer term.

@JeffJassky
Copy link

JeffJassky commented Aug 31, 2019

@6by9 thank you!

And for anyone interested - you can switch back to the new algorithm using sudo vcdbg set awb_mode 1

@dgalland
Copy link

With the new firmware and the new awb algorithm I also note the following behavior:

  • When I try the different modes (sunlight, cloudy, ...) it's OK
  • When I go to awb_mode off and I fix the gains it's OK
  • But after I can't change awb_mode which stays off
    The behavior is normal if I return to the old algorithm with sudo vcdbg set awb_mode 0
    Note: from Python with Picamera 1.13
    Regards

@JamesH65
Copy link
Contributor

vcdbg set_awb_mode is no longer recommended (and will be removed at some point). Use the greyworld AWB option.

@6by9
Copy link

6by9 commented Mar 30, 2020

Resuming AWB after having switched off was fixed in Hexxeh/rpi-firmware@1526192 - 30 Jan 2020.
Is your firmware after that date? If not, then update.

@dgalland
Copy link

@ 6by9
Thank you for answering.
I did rpi-update is that enough?
Here is what uname -a gives
Linux raspberrypi 4.19.113-v7+ #1300 SMP Thu Mar 26 16:53:09 GMT 2020 armv7l GNU/Linux
Not really blocking for me but I wanted to report
Anyway in my case the awb auto algorithm did not really give satisfactory results. Do you think the new algorithm is better?
@JamesH65
is there a trick to use "Greyworld with the Picamera library?

@6by9
Copy link

6by9 commented Mar 30, 2020

Blast. Sorry, we have two firmware source branches at present, one for Pi0-3, and one for Pi4. The fix is only on the Pi4 branch. I'll pull it across to the other one.

Re using greyworld, see waveform80/picamera#576.
I know waveform80 is busy on other stuff at present, but we'll look at what can be done to get it merged.

@6by9
Copy link

6by9 commented Mar 30, 2020

Actually if you want an interim fix on a non-critical Pi, then sudo BRANCH=next rpi-update will get a test firmware where the Pi0-3 fw is built from the same tree as Pi4. See https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=267576 for more info.

Cherry-pick done, so all being well a fix would be in the next "normal" rpi-update anyway.

@dgalland
Copy link

dgalland commented Apr 2, 2020

@6by9
It also seems to me that there is a change in behavior with the AGC algorithm. I posted in the raspberry forum, I don't know if I should open an issue?
Thanks for your help and best regards.

@6by9
Copy link

6by9 commented Apr 2, 2020

@dgalland Your comment is totally unrelated to AWB changing, therefore does not belong on this issue at all.

If you have a reproducable test case then raise an issue, but seeing as you've posted on the forums it'd be nice if you left more than 5 minutes for someone to have a chance to reply before cross posting here. And always add a link if you have asked the question on the forums so that we don't cover the same ground twice.

@jtc42
Copy link
Author

jtc42 commented Apr 28, 2020

@6by9 thanks for the updates on this. Has the updated pi3 firmware been officially released now? We're currently still using the old AWB debug mode for our microscopes, but I'm keen to move away from that ASAP.

Thanks.

@6by9
Copy link

6by9 commented Apr 28, 2020

Hexxeh/rpi-firmware@837c245
firmware: isp/tuner: Resetting to a lamp mode cancels manual_gains_used_ (master)

But also note Hexxeh/rpi-firmware@b6e327e
firmware: Switch to building from common firmware branch
so all Pi variants from that point on are now built off the same firmware tree.

@yujiayabe
Copy link

yujiayabe commented Jun 15, 2020

I checked many comments, but my Pi and camera don't work well. I can't stop AWB.
I check AWB with seeing picture(movie) using red paper covering lens on/off.
camera.exposure_mode = 'off' works well.

  • RasperryPi 4
  • PiCamera V2.1
  • Distributor ID: Raspbian
    Description: Raspbian GNU/Linux 10 (buster)
    Release: 10
    Codename: buster
  • Linux raspberrypi 5.4.45-v7l+ Allow ${srv} in the kernel cmdline #1321 SMP Wed Jun 10 17:39:20 BST 2020 armv7l GNU/Linux
  • Python 3.7.3
  • openCV 3.2.0
# -*- coding: utf-8 -*-
import cv2
import numpy as np
import picamera
import time

from picamera.array import PiRGBArray
from picamera import PiCamera

def main():
    #camera mode
    camera = PiCamera()
    camera.resolution = (832, 624)
    camera.iso = 100    
    camera.shutter_speed = 10000
    camera.exposure_mode = 'off'
    capture = PiRGBArray(camera, size=(832, 624))
    camera.awb_mode = 'off'
    camera.awb_gains = (1.8,1.8)
    
    # allow the camera to warmup
    time.sleep(0.1)

    for frame in camera.capture_continuous(capture, format="bgr", use_video_port=True):
        image = frame.array
        hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

        cv2.imshow("Image", image)
        
        key = cv2.waitKey(1) & 0xFF
        capture.truncate(0)

if __name__ == '__main__':
    main() 

Regards.

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

6 participants