Ive been building a sort of "Raspberry Pi GoPro" device that hooks onto the end glass of a hockey rink and records the action on the ice so I can go over video from my skates and work on technique. For the most part its worked great, the video quality is much better than I could get from most USB webcams, but the lighting used in the rink is playing havoc with the colour of the output.

You can see a really good example of the issue in this sequence here, as the overall colour of the shot cycles rapidly from normal to bright white, to a orangey-yellow tint, and back to bright white within 15 seconds. I suspect the colour of the players jerseys coming in and out of frame seems to drive these wild swings in how the camera perceives the colour of whats in front of it.

I did some reading on rink lighting and the picamera class that is doing the recording. Ice rinks apparently use a specialized kind of metal-halide light to brightly illuminate the large surface of the rink, but it doesnt appear to be as true to colour as natural light (sunlight) would be. The current setting of the PiCamera class in my project is a default of 'auto', which is clearly not adapting to the current situation correctly. Besides the default, PiCamera.awb_mode can also be set to a few settings that appear to be intended for natural light ('shade', 'sunlight', 'cloudy',... etc.), and a few for more conventional lighting sources ('fluorescent', 'tungsten', 'incandescent',...)

Im unsure of what setting for the auto white balance best matches this situation, as my reading seemed to indicate that HID metal-halide lamps werent classified as fluorescent or incandescent. Can anyone more familiar with the pi camera and/or lighting issues recording in rinks help me out?

1 Answer 1


I suspect the major issue here is that the firmware is concentrating too much on the centre of the image to determine white balance and exposure. Have a look specifically at 43:52 and 43:59 when a player in a dark jersey wanders into the centre of the frame, the firmware takes that as its cue to brighten the scene. As soon as they're out of the centre, it darkens again (how wide the area is that it's using I don't know, you'd have to ask the firmware devs, but it's presumably fairly wide as a similar effect is observed when the goalie strays near the centre of the frame).

Hence, the first thing I'd try is leaving the AWB and exposure on auto, but trying a different meter mode like 'matrix' or even 'backlit' (which should hopefully widen the area it's looking at). I doubt it'll cure it entirely (the firmware will still be seeing lots of variation as blobs of black and white move around), but it might be enough.

If it's not, then you need to look into fixing AWB and/or exposure. I've mostly used this with timelapse photography where one wants consistent exposure and white-balance across all shots so the resulting video doesn't "flicker" in brightness, but it's slightly risky because if the initial settings are no good then all shots will look off.

The capturing consistent images recipe covers the basics but you probably want to tweak it a bit for hockey. Probably a higher ISO setting (which'll fix the gain a bit higher allowing the camera to use shorter exposure times; preferable for shooting sports), and perhaps one of the metering modes mentioned above, e.g.:

from time import sleep
from picamera import PiCamera

camera = PiCamera(resolution=(1280, 720), framerate=30)
# Set ISO and meter mode to the desired value
camera.iso = 400
camera.meter_mode = 'matrix'
# Wait for the automatic gain control to settle
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'off'
camera.awb_gains = g
print("Fixing AWB at %r", g)
# Record the match! (2 hours? I've no idea how long a match is :)
camera.wait_recording(120 * 60 * 60)

You may also want to look at which AWB gains look sensible and just hard-code them in the script instead of having the camera measure them. But, if you're fixing exposure mode always leave a delay before setting exposure_mode to 'off' otherwise the gains can be fixed at 0 and you'll recording nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.