lgm42
Posts: 13
Joined: Mon Jan 07, 2013 3:50 pm

Reading AWB values of camera

Wed Jun 14, 2017 1:34 pm

When I start my C++ software, i configure the picam to go into AWB mode OFF and gains to Red : 0, Blue : 5

After do that, sometimes the camera get only green pictures, there is no other colors.

So I decided to read the AWB mode and gains that are really in camera.

I succeed in reading AWB mode with taht piece of code

Code: Select all

	MMAL_PARAMETER_AWBMODE_T awbMode;
	awbMode.hdr.id = MMAL_PARAMETER_AWB_MODE;
	awbMode.hdr.size = sizeof(awbMode);
	status = mmal_port_parameter_get(m_cameraComponent->control, &awbMode.hdr);

	if (status == MMAL_SUCCESS)
	{
		LOG_INFORMATION_F("AWB mode: %u", (unsigned)awbMode.value);
	}
	else
	{
		LOG_WARNING("Unable to get AWB mode parameter");
	}
but unfortunately I can't manage to read gains with that similar code :

Code: Select all

	MMAL_PARAMETER_AWB_GAINS_T awbGains;
	awbGains.hdr.id = MMAL_PARAMETER_CUSTOM_AWB_GAINS;
	awbGains.hdr.size = sizeof(awbGains);
	status = mmal_port_parameter_get(m_cameraComponent->control, &awbGains.hdr);

	if (status == MMAL_SUCCESS)
	{
		LOG_INFORMATION_F("AWB gains: B: %d/%d R:%d/%d", awbGains.b_gain.num, awbGains.b_gain.den, awbGains.r_gain.num, awbGains.r_gain.den);
	}
	else
	{
		LOG_WARNING_F("Unable to get AWB gains parameter: %u", (unsigned)status);
	}
On the second code, the status always return MMAL_EINVAL

Any Idea why my picture is green ? And why I can't read gains ?

lgm42
Posts: 13
Joined: Mon Jan 07, 2013 3:50 pm

Re: Reading AWB values of camera

Tue Jun 20, 2017 12:58 pm

I'm sorry to make an "up" but no one has an idea ?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9069
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Reading AWB values of camera

Tue Jun 20, 2017 1:25 pm

MMAL_PARAMETER_CUSTOM_AWB_GAINS / OMX_IndexConfigCustomAwbGains sets CUSTOM gains. You should be able to read back the custom value set (I missed the read case), but it would be the CUSTOM values, not the live values.

For live values you need MMAL_PARAMETER_CAMERA_SETTINGS returning a MMAL_PARAMETER_CAMERA_SETTINGS_T

Code: Select all

typedef struct MMAL_PARAMETER_CAMERA_SETTINGS_T
{
   MMAL_PARAMETER_HEADER_T hdr;

   uint32_t exposure;
   MMAL_RATIONAL_T analog_gain;
   MMAL_RATIONAL_T digital_gain;
   MMAL_RATIONAL_T awb_red_gain;
   MMAL_RATIONAL_T awb_blue_gain;
   uint32_t focus_position;
} MMAL_PARAMETER_CAMERA_SETTINGS_T;
Red gain of 0 and blue gain of 5? MMAL_PARAMETER_CUSTOM_AWB_GAINS takes MMAL_RATIONAL_T's, so what denominator are you setting?
Green will be at x1 gain, so it sounds like you're effectively turning off the red and blue channels and leaving just the green.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

lgm42
Posts: 13
Joined: Mon Jan 07, 2013 3:50 pm

Re: Reading AWB values of camera

Tue Jun 20, 2017 1:32 pm

To set my gains I use RaspiCamControl.c

Code: Select all

RASPICAM_CAMERA_PARAMETERS cameraParameters;
raspicamcontrol_set_defaults(&cameraParameters);
//make it twice to be sure to be applied
raspicamcontrol_set_all_parameters(m_cameraComponent, &cameraParameters);
I have modified RaspiCamControl.c to have these parameters :
params->awb_gains_r = 0; // Only have any function if AWB OFF is used.
params->awb_gains_b = 5;
It computes rational with 65536 base.
What is the range values for gain ? 5 is to high ?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9069
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Reading AWB values of camera

Tue Jun 20, 2017 2:07 pm

lgm42 wrote:To set my gains I use RaspiCamControl.c

Code: Select all

RASPICAM_CAMERA_PARAMETERS cameraParameters;
raspicamcontrol_set_defaults(&cameraParameters);
//make it twice to be sure to be applied
raspicamcontrol_set_all_parameters(m_cameraComponent, &cameraParameters);
We can't mind read, and particularly as you were writing your own library making guesses is almost certainly going to be wrong.
lgm42 wrote:I have modified RaspiCamControl.c to have these parameters :
params->awb_gains_r = 0; // Only have any function if AWB OFF is used.
params->awb_gains_b = 5;
It computes rational with 65536 base.
What is the range values for gain ? 5 is to high ?
What's the scene content?
Internally the numbers get converted through a couple of formats, but eventually end up as a allowing up to x256 gain. In reality that will saturate the values so it's pretty redundant to go up that high.

The values returned through MMAL_PARAMETER_CAMERA_SETTINGS should be valid even with custom gains applied, so what values are you getting back?
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

lgm42
Posts: 13
Joined: Mon Jan 07, 2013 3:50 pm

Re: Reading AWB values of camera

Tue Jun 20, 2017 3:18 pm

I run following code :

Code: Select all

        if (setAWBMode(m_cameraComponent, MMAL_PARAM_AWBMODE_OFF) != MMAL_SUCCESS)
		LOG_ERROR("Unable to set camera AWB mode OFF");

	if (raspicamcontrol_set_awb_gains(m_cameraComponent, 1, 1) != 0)
		LOG_ERROR("Unable to set camera AWB gain");

        MMAL_STATUS_T status;
	MMAL_PARAMETER_CAMERA_SETTINGS_T cameraSettings;

	cameraSettings.hdr.id = MMAL_PARAMETER_CAMERA_SETTINGS;
	cameraSettings.hdr.size = sizeof(cameraSettings);
	status = mmal_port_parameter_get(m_cameraComponent->control, &cameraSettings.hdr);

	if (status != MMAL_SUCCESS)
		throw Poco::Exception("Unable to read camera settings");

	LOG_INFORMATION_F("AWB R=%d/%d, B=%d/%d", cameraSettings.awb_red_gain.num, cameraSettings.awb_red_gain.den,
											  cameraSettings.awb_blue_gain.num, cameraSettings.awb_blue_gain.den);
	LOG_INFORMATION_F("exposure : %u", cameraSettings.exposure);
	LOG_INFORMATION_F("focus_position : %u", cameraSettings.focus_position);
	LOG_INFORMATION_F("analog_gain : %d/%d", cameraSettings.analog_gain.num, cameraSettings.analog_gain.den);
	LOG_INFORMATION_F("digital_gain : %d/%d", cameraSettings.digital_gain.num, cameraSettings.digital_gain.den);

And I got result :
00:36:43'603 : : [Information] : AWB R=0/256, B=0/256
00:36:43'603 : : [Information] : exposure : 0
00:36:43'603 : : [Information] : focus_position : 0
00:36:43'603 : : [Information] : analog_gain : 0/256
00:36:43'603 : : [Information] : digital_gain : 0/256
So my command to set AWB gain seems to be not taken into account, but it's the original raspicamcontrol method.
Any idea ?

lgm42
Posts: 13
Joined: Mon Jan 07, 2013 3:50 pm

Re: Reading AWB values of camera

Tue Jun 20, 2017 3:36 pm

When I run the command

Code: Select all

sudo vcdbg log msg
I got the error line:
mmalsrv: send_buffer_to_host: tx failed:size 292 st -1
Maybe a clue ?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9069
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Reading AWB values of camera

Tue Jun 20, 2017 3:54 pm

Was the camera actually streaming images when you requested the settings? The algorithms can't run without images.
Seeing as exposure is reported as 0 I'd suspect not.
lgm42 wrote:
mmalsrv: send_buffer_to_host: tx failed:size 292 st -1
Maybe a clue ?
No, just means that you hit control-C at a point where MMAL was trying to deliver a buffer.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

lgm42
Posts: 13
Joined: Mon Jan 07, 2013 3:50 pm

Re: Reading AWB values of camera

Wed Jun 21, 2017 7:19 am

Effectively, the camera wasn't streaming when I write / read configuration.
The last thing that make an error forme is timing.
I was writing values an immediately reading for it and I got old values.

Now I wait for a second after configuration and before reading configuration, and values are now ok !!

Thanks alot for all these informations !

Return to “Camera board”