gugahoi
Posts: 8
Joined: Wed Aug 28, 2013 7:34 am
Location: Australia

Permanently turn AWB off

Mon Oct 21, 2013 1:02 pm

Hey guys,
just wandering if anyone happens to know if there is a way to permanently get rid of auto white balance in the pi camera. It seems to affect my readings way too much.

The code i currently use can be found here: https://github.com/gugahoi/RobotDesign/ ... ryPi/camcv

It is mostly similar to the face recognition code from Pierre however I am trying to do color detection instead.

When I see blue in the frame it seems to change the entire color spectrum and makes every other color wrong so it renders the code almost useless. Any tips would be appreciated...

ethanol100
Posts: 583
Joined: Wed Oct 02, 2013 12:28 pm

Re: Permanently turn AWB off

Mon Oct 21, 2013 1:55 pm

You can set it to a fixed awb mode in RaspiCamControl.c

See the function : void raspicamcontrol_set_defaults(RASPICAM_CAMERA_PARAMETERS *params)
and change the default parameter : params->awbMode = MMAL_PARAM_AWBMODE_AUTO;
to i.e. MMAL_PARAM_AWBMODE_SUNLIGHT

The camera needs to use some model for the white balance, but if it is not set to MMAL_PARAM_AWBMODE_AUTO the white balance should be fixed.
(That is my understanding of AWB, hope it is not wrong...)
For some background see i.e. http://cpn.canon-europe.com/content/edu ... balance.do.

SnowLeopard
Posts: 106
Joined: Sun Aug 18, 2013 6:10 am

Re: Permanently turn AWB off

Mon Oct 21, 2013 3:57 pm

Set it to MMAL_PARAM_AWBMODE_OFF?

Edit: Nevermind... I'm guessing you've tried that already. I hadn't seen this other thread:
http://www.raspberrypi.org/phpBB3/viewt ... 43&t=56698

gugahoi
Posts: 8
Joined: Wed Aug 28, 2013 7:34 am
Location: Australia

Re: Permanently turn AWB off

Mon Oct 21, 2013 10:46 pm

SnowLeopard wrote:Set it to MMAL_PARAM_AWBMODE_OFF?

Edit: Nevermind... I'm guessing you've tried that already. I hadn't seen this other thread:
http://www.raspberrypi.org/phpBB3/viewt ... 43&t=56698
Yes I did try to set it to off but didnt seem to work, however if I use

Code: Select all

raspivid -t 10000 -awb off

it looked good and seemed to maintain the colors even with blue in the frame so I am confused as to why MMAL_PARAM_AWBMODE_OFF makes no difference in my code.

ethanol100 wrote:You can set it to a fixed awb mode in RaspiCamControl.c

See the function : void raspicamcontrol_set_defaults(RASPICAM_CAMERA_PARAMETERS *params)
and change the default parameter : params->awbMode = MMAL_PARAM_AWBMODE_AUTO;
to i.e. MMAL_PARAM_AWBMODE_SUNLIGHT

The camera needs to use some model for the white balance, but if it is not set to MMAL_PARAM_AWBMODE_AUTO the white balance should be fixed.
(That is my understanding of AWB, hope it is not wrong...)
For some background see i.e. http://cpn.canon-europe.com/content/edu ... balance.do.
Ok, I'll give that a shot. I have tried setting it to MMAL_PARAM_AWBMODE_OFF before but it seemed to make no difference, will try to set to something else.

gugahoi
Posts: 8
Joined: Wed Aug 28, 2013 7:34 am
Location: Australia

Re: Permanently turn AWB off

Wed Oct 23, 2013 8:25 am

I have had no luck yet. Replaced AWB AUTO everywhere in the code but nothing seemed to work. My solution for the moment is to have the camera further away from the objects, that seems to not affect it so much.

SnowLeopard
Posts: 106
Joined: Sun Aug 18, 2013 6:10 am

Re: Permanently turn AWB off

Wed Oct 23, 2013 3:46 pm

waveform80 pointed me to the picam library. I haven't had a chance to try it yet, but seems you could use to determine if the setting is taking (and other debugging).
See the last post on page 5 of the thread http://www.raspberrypi.org/phpBB3/viewt ... &start=100

Samy74
Posts: 7
Joined: Mon Oct 28, 2013 3:55 pm

Re: Permanently turn AWB off

Sat Nov 09, 2013 10:58 am

Any luck turning off the AWB? This is really a big issue for those who are trying to do some color tracking with the RPi camera...

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: Permanently turn AWB off

Sat Nov 09, 2013 12:07 pm

Did anyone try to use '-awb sun'? The goal is to get a permanent color representation where from my tests 'sun' is very close to 'off'. It might be that the random color shifts seen with 'off' do not appear with 'sun'. Just a thought, I'll change to 'sun' myself for now and see what happens.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23083
Joined: Sat Jul 30, 2011 7:41 pm

Re: Permanently turn AWB off

Sat Nov 09, 2013 12:44 pm

Off doesn't actually mean off, which I didn't know when I first wrote the code - I've since removed off from the options I think.

Off actually seems to turn it off but only for one frame - this was used for some obscure reason somewhere in the past.

Use a predefined option which should lock the AWB to a fixed value.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: Permanently turn AWB off

Sat Nov 09, 2013 12:52 pm

Hey thanks, that would explain things.

paranoidcoder
Posts: 5
Joined: Sat Nov 09, 2013 9:31 pm

Re: Permanently turn AWB off

Sat Nov 09, 2013 9:33 pm

I have found through experimentation that turning the AWB setting to something other than auto/off STILL does not fix the AWB values. So looks like we need a better fix

Has anybody found a solution at any level to solve this problem?

lingon
Posts: 117
Joined: Fri Aug 26, 2011 7:31 am

Re: Permanently turn AWB off

Sat Nov 09, 2013 10:48 pm

I have been using -awb sun to try to get more stable whitebalance. Unfortunately this does not seem to work. Even during night the white balance is fluctuating. I have seen that the color of a street light at night can fluctuate from one frame to the next.

gugahoi
Posts: 8
Joined: Wed Aug 28, 2013 7:34 am
Location: Australia

Re: Permanently turn AWB off

Sun Nov 10, 2013 12:39 am

In my tests raspivid with awb off actually looked like it worked. The colourspace was pretty constant throughout no matter what was in the frame however the program I wrote didn't seem to have the same effect even tho it used most of the code from raspivid so my only solution was to have the camera further away from the object.

I have seen some new libraries coming out tho that look very promising, you can find them here: http://www.raspberrypi.org/phpBB3/viewt ... 58#p446158

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23083
Joined: Sat Jul 30, 2011 7:41 pm

Re: Permanently turn AWB off

Sun Nov 10, 2013 9:15 am

Note that those libs cannot do anything that raspistill/vid cannot do (they al talk to the same software on the GPU) - unless they are doing their own AWB processing - which is possible but would be done on the ARM so exceptionally slow.

So if someone can check github issues list and add that the AWB doesn't seem to fix when using the predefined values that will remind me to take a look to see what is happening.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: Permanently turn AWB off

Sun Nov 10, 2013 10:49 am

added -awb issue to github

Samy74
Posts: 7
Joined: Mon Oct 28, 2013 3:55 pm

Re: Permanently turn AWB off

Sun Nov 10, 2013 9:17 pm

AWB is really a nightmare for me. I'm doing image processing in a mobile robot, image lightning is changing every time it moves...

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23083
Joined: Sat Jul 30, 2011 7:41 pm

Re: Permanently turn AWB off

Sun Nov 10, 2013 9:21 pm

Samy74 wrote:AWB is really a nightmare for me. I'm doing image processing in a mobile robot, image lightning is changing every time it moves...
Is that AWB or gain control causing the problem? First gives changing colours, second gives changing brightness. You can try a different metering mode to see if that helps.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Samy74
Posts: 7
Joined: Mon Oct 28, 2013 3:55 pm

Re: Permanently turn AWB off

Sun Nov 10, 2013 9:24 pm

How can I do that? I'm using C++ (modified raspvid) for OpenCV.

paranoidcoder
Posts: 5
Joined: Sat Nov 09, 2013 9:31 pm

Re: Permanently turn AWB off

Mon Nov 11, 2013 5:08 am

tl;dr: I think it's safe to say this camera does no support turning AWB off/static at least for the time being, unless anybody knows a library which sends the correct bit string to the camera.

this problem goes deep....

I'm using the userland library instead of the uv4l driver.

Even userland doesnt have it right yet....

Here's what i've found:
I went all the way down to the level where ioctl is called in /userland/interface/vchiq_arm/vchiq_lib.c method vchiq_queue_message, to send the message directly to the camera
the values made in structs and such DO propagate all the way down and attempt to set AWB off, however, as you can imagine, it doesn't work.
I've tried messing around with some of the bits that look like they might be useful to flip, but to no avail.

At this point, the person who made the chip would have to tell me what to do to be able to change this setting.

So this leaves a few possibilities i can think of:
1. the message does change the right value, but is changed later
2. it changes the wrong value and who knows what settings AWB off really does
3. we're sending the wrong setting over for the camera
4. camera doesnt support turning AWB off (built in)

If i'm missing something, feel free to point it out. This is my best shot at figuring out what's wrong. Looks like i'm going to have to get another camera for my mobile robot :(

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: Permanently turn AWB off

Mon Nov 11, 2013 8:02 am

It's handled on the GPU which is closed source; jamesh is the only one who can change it as he has access to the GPU code since he works for Broadcom.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23083
Joined: Sat Jul 30, 2011 7:41 pm

Re: Permanently turn AWB off

Mon Nov 11, 2013 8:59 am

paranoidcoder wrote:tl;dr: I think it's safe to say this camera does no support turning AWB off/static at least for the time being, unless anybody knows a library which sends the correct bit string to the camera.

this problem goes deep....

I'm using the userland library instead of the uv4l driver.

Even userland doesnt have it right yet....

Here's what i've found:
I went all the way down to the level where ioctl is called in /userland/interface/vchiq_arm/vchiq_lib.c method vchiq_queue_message, to send the message directly to the camera
the values made in structs and such DO propagate all the way down and attempt to set AWB off, however, as you can imagine, it doesn't work.
I've tried messing around with some of the bits that look like they might be useful to flip, but to no avail.

At this point, the person who made the chip would have to tell me what to do to be able to change this setting.

So this leaves a few possibilities i can think of:
1. the message does change the right value, but is changed later
2. it changes the wrong value and who knows what settings AWB off really does
3. we're sending the wrong setting over for the camera
4. camera doesnt support turning AWB off (built in)

If i'm missing something, feel free to point it out. This is my best shot at figuring out what's wrong. Looks like i'm going to have to get another camera for my mobile robot :(
You are correct in your analysis 4 (although I think I had posted all this before). I'm going to chat with the AWB experts today to find out what is actually supposed to happen vs what is actually happening.

You need some sort of AWB set up otherwise the pictures are generally rubbish, but what I'm not sure about is why when using a fixed mode it doesn't appear to be fixed. That's of more concern.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23083
Joined: Sat Jul 30, 2011 7:41 pm

Re: Permanently turn AWB off

Mon Nov 11, 2013 10:19 am

OK, had a word. This is how it works.....(simplistically)

The AWB uses a baysian algorithm to determine what is in the scene, and from this works out the best AWB to apply (by finding something that should be grey and making it grey). Letting the AWB have free reign is Auto mode.

In fixed modes, the Baysian search is constrained to an area around the expected scene type (tungstan etc). but there is still so room for manoeuvre, so you may get some gain changes in that range. But, and, and this is where a problem arises, IF the algorithm cannot find a match in the defined area (no grey area), it will then default to some value. IIUK, sometimes you can get oscillation between AWB working and a default value as the scene changes.

So there is an issue with the AWB in the case where it cannot find a baysian match. What we really need is for the AWB in fixed modes to have a fixed gain.

This might take some fixing. - this code is complicated. And so I will need to find someone who knows about it to either fix it or point me the the right direction so I can fix it.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: Permanently turn AWB off

Mon Nov 11, 2013 11:54 am

An old DSLR trick to counter the typical green cast of RAW data (caused by RGGB) is to apply a 40M (magenta) filter. If you could create a mode that gets the RAW data, circumvents the AWB stuff and adds the equivalent of an optical 40M filter the color should be in an acceptable range. I think ;-)

If that causes over- or underexposure we could counter it by manual exposure.

Another data point is so-called 'UniWB', which is a WB setting used on DSLRs to make the color of a jpeg exactly so that it closely represents the true exposure of each color in a RAW file. DSLRs use the color of a jpeg to show histograms, but this is altered by the cameras' WB setting. Therefore when shooting RAW without the UniWB setting the exposure of the color channels in the final RAW will not correspond with what is shown in the histogram on the camera hence channel clipping (or underexposure) can occur.

Here an example of an image color corrected in post and beneath it the as-shot version using UniWB white balance:
uniwb.jpg
UniWB example
uniwb.jpg (46.85 KiB) Viewed 11591 times

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23083
Joined: Sat Jul 30, 2011 7:41 pm

Re: Permanently turn AWB off

Mon Nov 11, 2013 12:17 pm

If you want to deal with raw go ahead - that pre everything. But in the ISP, the image is debayered early on in the pipeline, and goes through quite a few stages before getting to the AWB. (I think there are over twenty stages in the ISP....AWB being just one of them)

As I said, this won't be a quick easy fix. No such thing when talking about something this complicated.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

paranoidcoder
Posts: 5
Joined: Sat Nov 09, 2013 9:31 pm

Re: Permanently turn AWB off

Tue Nov 12, 2013 4:40 am

I'll do anything to get rid of this AWB even if it means dealing with the raw....
but....
how in the world do you get the raw?... i'm guessing the challenge of getting it to work in opencv is my own challenge

it's hard to believe we cant tell the chip to just NOT apply AWB, or just apply our own manual settings for, the camera should be able to handle that.... why cant our gpu?

Return to “Camera board”