ArjnJ
Posts: 12
Joined: Wed Oct 15, 2014 3:30 pm

Remove metering

Fri Jan 16, 2015 4:01 pm

Hi,

I'm trying to use the camera (amongst other things) as a light meter using a Raspivid based program outputting YUV data. It's important that the sensitivity of the sensor does not change and that there is no software compensation to the image.
I feel the easiest way to do this is to remove the automatic MMAL metering. There are however only four options for metering: Average, spot, backlit and matrix. Also, setting the exposure mode to 'OFF' gives a black image, as the gain comes from the GPU, from what I've read.

I've manually set ISO, saturation, brightness, contrast and exposure compensation.

How do I remove the metering or give every pixel a constant gain? Is there an easier way to stop the camera automatically exposing in video?

Thanks

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

Re: Remove metering

Fri Jan 16, 2015 4:29 pm

Set the exposure mode to OFF, but also set the exposure time and ISO.
It sounds like you've not set exposure time (aka shutter speed), hence it is using the default shutter speed which I seem to recall is very short. "-ss" on the raspivid command line.
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.

ArjnJ
Posts: 12
Joined: Wed Oct 15, 2014 3:30 pm

Re: Remove metering

Mon Jan 19, 2015 1:52 pm

Thanks for the reply.

I've attached the code which corresponds to the settings of the camera, however the sensor does not seem to respond to light when exposure mode is on OFF. Have I called the settings correctly?

Code: Select all

        MMAL_PARAMETER_CAMERA_CONFIG_T cam_config = {
            { MMAL_PARAMETER_CAMERA_CONFIG, sizeof (cam_config)},
            .max_stills_w = x,
            .max_stills_h = y,
            .stills_yuv422 = 0,
            .one_shot_stills = 1,
            .max_preview_video_w = x,
            .max_preview_video_h = y,
            .num_preview_video_frames = 3,
            .stills_capture_circular_buffer_height = 0,
            .fast_preview_resume = 0,
            .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RESET_STC
        };
        
        mmal_port_parameter_set(camera->control, &cam_config.hdr);
        
        // ISO
        int iso = 100;
                mmal_port_parameter_set_uint32(camera->control, MMAL_PARAMETER_ISO, iso);
        
        //EXPOSURE (SET TO SPOT)
        MMAL_PARAMETER_EXPOSUREMETERINGMODE_T meter_mode = {
                        {MMAL_PARAMETER_EXP_METERING_MODE,sizeof(meter_mode)},
             MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT
        };
                mmal_port_parameter_set(camera->control, &meter_mode.hdr);
        
        //EXPOSURE MODE (SET TO NONE)
        MMAL_PARAMETER_EXPOSUREMODE_T expose_mode = {
                        {MMAL_PARAMETER_EXPOSURE_MODE,sizeof(expose_mode)},
                        MMAL_PARAM_EXPOSUREMODE_OFF
                };
                mmal_port_parameter_set(camera->control, &expose_mode.hdr);
        
        //BRIGHTNESS   
        MMAL_RATIONAL_T bright = {40, 100};                                              
                mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_BRIGHTNESS, bright);
                
        //EV COMPENSATION (SET TO ZERO)
                int exp_comp = 0;
                mmal_port_parameter_set_int32(camera->control, MMAL_PARAMETER_EXPOSURE_COMP , exp_comp);
                
         //SATURATION
                MMAL_RATIONAL_T saturation = {0, 100};
                mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_SATURATION, saturation);
                
         //CONSTRAST
                MMAL_RATIONAL_T contrast = {0, 100};
                mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_CONTRAST, contrast);
                
         //EXPOSURE TIME
                int speed = 100000;
                mmal_port_parameter_set_uint32(camera->control, MMAL_PARAMETER_SHUTTER_SPEED, speed);

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

Re: Remove metering

Mon Jan 19, 2015 2:47 pm

Exposure mode off means that the automatic algo won't touch anything, but it sounds like the manual setting is getting lost too.
This may be a sequencing issue. Does raspistill send the ISO and manual shutter speed values after having enabled the component? That may well be the difference here.
MMAL_PARAMETER_CAMERA_CONFIG has to be set before enabling the component though.
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.

ArjnJ
Posts: 12
Joined: Wed Oct 15, 2014 3:30 pm

Re: Remove metering

Tue Jan 20, 2015 10:47 am

I'm afraid that didn't work either. It doesn't seem to be losing all of the manual settings however, as changing brightness does affect the blank preview. Is there any other place where the camera parameters are set? I've attached the whole of my main function:

Code: Select all

int main(int argc, char** argv) {
    MMAL_COMPONENT_T *camera = 0;
    MMAL_COMPONENT_T *preview = 0;
    MMAL_ES_FORMAT_T *format;
    MMAL_STATUS_T status;
    MMAL_PORT_T *camera_preview_port = NULL, *camera_video_port = NULL, *camera_still_port = NULL;

        //DAC starts HERE
        printf("Setting up DAC\n");
        if ((fd = open(device, O_RDWR)) < 0) exit_on_error ("Can't open SPI device");


        if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) == -1) exit_on_error ("Can't set Max Speed");
        // Set SPI mode
        if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) exit_on_error ("Can't set SPI mode");
        
        
        //DAC ends HERE

    MMAL_CONNECTION_T *camera_preview_connection = 0;

    printf("Running...\n");


    bcm_host_init();

    status = mmal_component_create(MMAL_COMPONENT_DEFAULT_CAMERA, &camera);
    if (status != MMAL_SUCCESS) {
        printf("Error: create camera %x\n", status);
        return -1;
    }

    camera_preview_port = camera->output[MMAL_CAMERA_PREVIEW_PORT];
    camera_video_port = camera->output[MMAL_CAMERA_VIDEO_PORT];
    camera_still_port = camera->output[MMAL_CAMERA_CAPTURE_PORT];

    {   
                
        MMAL_PARAMETER_CAMERA_CONFIG_T cam_config = {
            { MMAL_PARAMETER_CAMERA_CONFIG, sizeof (cam_config)},
            .max_stills_w = x,
            .max_stills_h = y,
            .stills_yuv422 = 0,
            .one_shot_stills = 1,
            .max_preview_video_w = x,
            .max_preview_video_h = y,
            .num_preview_video_frames = 3,
            .stills_capture_circular_buffer_height = 0,
            .fast_preview_resume = 0,
            .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RESET_STC
        };
        
        mmal_port_parameter_set(camera->control, &cam_config.hdr);

    }
    

        
    // Setup camera preview port format 
    format = camera_preview_port->format;

    format->encoding = MMAL_ENCODING_OPAQUE;
    format->encoding_variant = MMAL_ENCODING_I420;

    format->es->video.width = x;
    format->es->video.height = y;
    format->es->video.crop.x = 0;
    format->es->video.crop.y = 0;
    format->es->video.crop.width = x;
    format->es->video.crop.height = y;

    status = mmal_port_format_commit(camera_preview_port);

    if (status != MMAL_SUCCESS) {
        printf("Error: camera viewfinder format couldn't be set\n");
        return -1;
    }

    //Setup camera video port format
    mmal_format_copy(camera_video_port->format, camera_preview_port->format);

    format = camera_video_port->format;

    format->encoding = MMAL_ENCODING_I420;
    format->encoding_variant = MMAL_ENCODING_I420;

    format->es->video.width = x;
    format->es->video.height = y;
    format->es->video.crop.x = 0;
    format->es->video.crop.y = 0;
    format->es->video.crop.width = x;
    format->es->video.crop.height = y;
    format->es->video.frame_rate.num = framerate; // HERE WE DEFINE FPS RATE
    format->es->video.frame_rate.den = 1;


    camera_video_port->buffer_size = camera_video_port->buffer_size_recommended;
    camera_video_port->buffer_num = 2;

    status = mmal_port_format_commit(camera_video_port);

    printf(" camera video buffer_size = %d\n", camera_video_port->buffer_size);
    printf(" camera video buffer_num = %d\n", camera_video_port->buffer_num);
    if (status != MMAL_SUCCESS) {
        printf("Error: unable to commit camera video port format (%u)\n", status);
        return -1;
    }

    // create pool form camera video port
    camera_video_port_pool = (MMAL_POOL_T *)mmal_port_pool_create(camera_video_port, camera_video_port->buffer_num, camera_video_port->buffer_size);
    camera_video_port->userdata = (struct MMAL_PORT_USERDATA_T *) camera_video_port_pool;

    status = mmal_port_enable(camera_video_port, video_buffer_callback);
    if (status != MMAL_SUCCESS) {
        printf("Error: unable to enable camera video port (%u)\n", status);
        return -1;
    }

    status = mmal_component_enable(camera);
    
       //EXPOSURE MODE (SET TO NONE)
                         MMAL_PARAMETER_EXPOSUREMODE_T expose_mode = {
                         {MMAL_PARAMETER_EXPOSURE_MODE,sizeof(expose_mode)},
                         MMAL_PARAM_EXPOSUREMODE_OFF
                };
                mmal_port_parameter_set(camera->control, &expose_mode.hdr);

        // ISO
        int iso = 400;
                mmal_port_parameter_set_uint32(camera->control, MMAL_PARAMETER_ISO, iso);
        
    //EXPOSURE (SET TO SPOT)
                        MMAL_PARAMETER_EXPOSUREMETERINGMODE_T meter_mode = {
                        {MMAL_PARAMETER_EXP_METERING_MODE,sizeof(meter_mode)},
             MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT
        };
                mmal_port_parameter_set(camera->control, &meter_mode.hdr);
        
        
    //BRIGHTNESS   
                MMAL_RATIONAL_T bright = {50, 100};                                              
                mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_BRIGHTNESS, bright);
                
                //EV COMPENSATION (SET TO ZERO)
                int exp_comp = 0;
                mmal_port_parameter_set_int32(camera->control, MMAL_PARAMETER_EXPOSURE_COMP , exp_comp);
                
                //SATURATION
                MMAL_RATIONAL_T saturation = {20, 100};
                mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_SATURATION, saturation);
                
                //CONSTRAST
                MMAL_RATIONAL_T contrast = {20, 100};
                mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_CONTRAST, contrast);
                
                //EXPOSURE TIME
                int speed = 100000;
                mmal_port_parameter_set_uint32(camera->control, MMAL_PARAMETER_SHUTTER_SPEED, speed);
                
        


    status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_RENDERER, &preview);
    if (status != MMAL_SUCCESS) {
        printf("Error: unable to create preview (%u)\n", status);
        return -1;
    }

    preview_input_port = preview->input[0];
    {
        MMAL_DISPLAYREGION_T param;
        param.hdr.id = MMAL_PARAMETER_DISPLAYREGION;
        param.hdr.size = sizeof (MMAL_DISPLAYREGION_T);
        param.set = MMAL_DISPLAY_SET_LAYER;
        param.layer = 0;
        param.set |= MMAL_DISPLAY_SET_FULLSCREEN;
        param.fullscreen = 4;
        status = mmal_port_parameter_set(preview_input_port, &param.hdr);
        if (status != MMAL_SUCCESS && status != MMAL_ENOSYS) {
            printf("Error: unable to set preview port parameters (%u)\n", status);
            return -1;
        }
    }
    mmal_format_copy(preview_input_port->format, camera_video_port->format);

    format = preview_input_port->format;

    format->encoding = MMAL_ENCODING_I420;
    format->encoding_variant = MMAL_ENCODING_I420;

    format->es->video.width = x;
    format->es->video.height = y;
    format->es->video.crop.x = 0;
    format->es->video.crop.y = 0;
    format->es->video.crop.width = x;
    format->es->video.crop.height = y;
     format->es->video.frame_rate.num = framerate; // HERE WE DEFINE FPS RATE
    format->es->video.frame_rate.den = 1;

    preview_input_port->buffer_size = camera_video_port->buffer_size_recommended;
    preview_input_port->buffer_num = 4;

    printf(" preview buffer_size = %d\n", preview_input_port->buffer_size);
    printf(" preview buffer_num = %d\n", preview_input_port->buffer_num);
    
    status = mmal_port_format_commit(preview_input_port);

    preview_input_port_pool = (MMAL_POOL_T *)mmal_port_pool_create(preview_input_port, preview_input_port->buffer_num, preview_input_port->buffer_size);

    preview_input_port->userdata = (struct MMAL_PORT_USERDATA_T *) preview_input_port_pool;
    status = mmal_port_enable(preview_input_port, preview_buffer_callback);
    if (status != MMAL_SUCCESS) {
        printf("Error: unable to enable preview input port (%u)\n", status);
        return -1;
    }

    /*
    status = mmal_connection_create(&camera_preview_connection, camera_preview_port, preview_input_port, MMAL_CONNECTION_FLAG_TUNNELLING | MMAL_CONNECTION_FLAG_ALLOCATION_ON_INPUT);
    if (status != MMAL_SUCCESS) {
        printf("Error: unable to create connection (%u)\n", status);
        return -1;
    }

    status = mmal_connection_enable(camera_preview_connection);
    if (status != MMAL_SUCCESS) {
        printf("Error: unable to enable connection (%u)\n", status);
        return -1;
    }
     */ 
    if (1) {
        // Send all the buffers to the encoder output port
        int num = mmal_queue_length(camera_video_port_pool->queue);
        int q;

        for (q = 0; q < num; q++) {
            MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(camera_video_port_pool->queue);

            if (!buffer)
                printf("Unable to get a required buffer %d from pool queue\n", q);

            if (mmal_port_send_buffer(camera_video_port, buffer) != MMAL_SUCCESS)
               printf("Unable to send a buffer to encoder output port (%d)\n", q);
        }


    }

    if (mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) {
        printf("%s: Failed to start capture\n", __func__);
    }

    while (1);

    return 0;
}

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

Re: Remove metering

Tue Jan 20, 2015 12:14 pm

Brightness (and contrast, saturation) is done by a much later block in the ISP that is unaffected by exposure metering.
Shutter speed and ISO are directed at the sensor. If the sensor isn't streaming when you set them, then I can see there being an omission where they don't then get set correctly when it is started.

There is example code in the form of raspistill that should allow this set of options via -iso and -ss. AFAIK those work, so please check whether that is correct for you, and then duplicate it.
There was a patch that I mentioned back in http://www.raspberrypi.org/forums/viewt ... 25#p592263 that was setting digital gain to x1.0 if exposure mode was set to OFF before starting streaming, so I am fairly confident that it does work. Please confirm that you are using a relatively recent firmware.
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.

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

Re: Remove metering

Tue Jan 20, 2015 12:38 pm

Additionally, white balance can change the exposure. It can still increase or decrease brightness, by setting the red and blue gains. Please fix these gains. You should check the values by using MMAL_EVENT_PARAMETER_CHANGED in the camera control callback. Have a look at the raspivid source code. Which values are then reported for the gains and the shutterspeed?

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

Re: Remove metering

Tue Jan 20, 2015 1:21 pm

6by9 wrote: There is example code in the form of raspistill that should allow this set of options via -iso and -ss. AFAIK those work, so please check whether that is correct for you, and then duplicate it.
There was a patch that I mentioned back in http://www.raspberrypi.org/forums/viewt ... 25#p592263 that was setting digital gain to x1.0 if exposure mode was set to OFF before starting streaming, so I am fairly confident that it does work. Please confirm that you are using a relatively recent firmware.
-iso and -ss should work as expected, but MMAL_PARAM_EXPOSUREMODE_OFF is not in the exposure_map.

I just tried to add '{"off", MMAL_PARAM_EXPOSUREMODE_OFF} ' to the exposure_map.
For raspistill it works(partial). The preview is black, with digital gain=0, and when the mode is changed to the still capture the digital gain is set to 1. So the saved image is fine.
For raspivid there is no change of mode, and the digital gain keeps to be 0. So the patch only works for raspistill.

BMS Doug
Posts: 4422
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Remove metering

Tue Jan 20, 2015 1:38 pm

ethanol100 wrote:
6by9 wrote: Please confirm that you are using a relatively recent firmware.
-iso and -ss should work as expected, but MMAL_PARAM_EXPOSUREMODE_OFF is not in the exposure_map.

I just tried to add '{"off", MMAL_PARAM_EXPOSUREMODE_OFF} ' to the exposure_map.
For raspistill it works(partial). The preview is black, with digital gain=0, and when the mode is changed to the still capture the digital gain is set to 1. So the saved image is fine.
For raspivid there is no change of mode, and the digital gain keeps to be 0. So the patch only works for raspistill.
You should note the last line of 6by9's post as you haven't replied to that point.

If you are using an old firmware version then 6by9's advice won't be able to help you (as it is based on the assumption that your firmware is up to date).
Doug.
Building Management Systems Engineer.

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

Re: Remove metering

Tue Jan 20, 2015 2:00 pm

ethanol100 wrote:-iso and -ss should work as expected, but MMAL_PARAM_EXPOSUREMODE_OFF is not in the exposure_map.

I just tried to add '{"off", MMAL_PARAM_EXPOSUREMODE_OFF} ' to the exposure_map.
For raspistill it works(partial). The preview is black, with digital gain=0, and when the mode is changed to the still capture the digital gain is set to 1. So the saved image is fine.
For raspivid there is no change of mode, and the digital gain keeps to be 0. So the patch only works for raspistill.
Hmm, not sure how I was testing then (August was a long time ago). The logic is simply that if the digital gain is 0 when checking at the start of frame and AGC is off, then set it to x1.0.

@ethanol100 - thanks for your testing. If you do set iso and ss, and then monitor with -set, do the analogue and digital gain vary, or are they locked? If they don't vary, then we don't actually need to worry about the exposure mode anyway. I have a sneaky recollection though that setting ISO still allowed a little variation during preview, even if the capture was locked.
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.

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

Re: Remove metering

Tue Jan 20, 2015 2:02 pm

BMS Doug wrote:You should note the last line of 6by9's post as you haven't replied to that point.

If you are using an old firmware version then 6by9's advice won't be able to help you (as it is based on the assumption that your firmware is up to date).
I trust ethanol100 to be on a recent firmware, and his testing shows anomalies too. Whether the OP is on recent firmware is another matter...
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.

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

Re: Remove metering

Tue Jan 20, 2015 2:35 pm

6by9 wrote: @ethanol100 - thanks for your testing. If you do set iso and ss, and then monitor with -set, do the analogue and digital gain vary, or are they locked? If they don't vary, then we don't actually need to worry about the exposure mode anyway. I have a sneaky recollection though that setting ISO still allowed a little variation during preview, even if the capture was locked.
It still varies, I have used "./raspivid -ISO 100 -ss 10000 -t 60000 -set -o test.h264". If I change the lighting(flash light and paper to block most of the light, the values are still changing in the interval from analog gain 256/256 to 2016/256, and the digital gain from 256/256 to 882/256.

It is different for raspistill, here it seems to be fixed to 256/256 and 256/256 for the still captures, but the values for the preview vary in the same range as in the raspvid case. The command used was "./raspistill -tl 2000 -t 60000 --ISO 100 -ss 10000 -set -o img%04d.jpg".

Just for reference, there is still a pull request https://github.com/raspberrypi/userland/pull/171 for adding exp=off, with some discussions.
Last edited by ethanol100 on Tue Jan 20, 2015 2:49 pm, edited 1 time in total.

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

Re: Remove metering

Tue Jan 20, 2015 2:45 pm

Thanks. I'll add it as another thing on my list of things for when I find some spare time.

I probably had been testing against the V4L2 driver before, and raspistill may do different things just due to sequencing. I don't quite see why my change from August doesn't set digital gain to x1.0 - hopefully 5mins with a debugger (if it works this time) will show something obvious.
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.

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

Re: Remove metering

Tue Jan 20, 2015 4:15 pm

It is not a very important issue. There is still a way to fix the gains(but not always to one specific value). Start with some reference,i.e. just a bright light. Start the camera with exposure auto, and before setting "mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1) ". Add something similar to this:

Code: Select all

mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 0);
vcos_sleep(5000);
MMAL_PARAMETER_EXPOSUREMODE_T exp_mode = {{MMAL_PARAMETER_EXPOSURE_MODE,sizeof(exp_mode)}, MMAL_PARAM_EXPOSUREMODE_OFF};
mmal_port_parameter_set(state.camera_component->control, &exp_mode.hdr);
This will adjust it's exposure for 5 sec, while not recording anything(if it is bright enough both gains will be 1). Then it fixes its exposure mode, and the normal program can continue.

@6by9 Good luck for the debugging! Would be nice to have this fixed.

ArjnJ
Posts: 12
Joined: Wed Oct 15, 2014 3:30 pm

Re: Remove metering

Thu Jan 22, 2015 5:03 pm

I used your get around, ethanol100 and it works. However as you say there is no way to explicitly set the gains, which is quite important for my application - I'm heating silica fibre with a laser and using the RPi-camera combination for PID temperature control. With the variation in gain, my desired temperature pixel-value keeps changing, making it impossible to tune the system.

I appreciate that there is apparently no direct access to the gain, but could you tell me where it is controlled and why access is restricted?

Thanks.

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

Re: Remove metering

Thu Jan 22, 2015 5:54 pm

ArjnJ wrote:I appreciate that there is apparently no direct access to the gain, but could you tell me where it is controlled and why access is restricted?
The Video Processing Core of the BCM2835 has a build in ISP(Image Sensor Pipeline) and hardware video and image decoder and encoder. The camera data lines are directly connected to the ISP which takes the raw image data and process it. The firmware, which includes the programming of the ISP, is closed source and is the intellectual property of Broadcom. The ISP will perform several task to process the camera data, and to control the settings of the camera and will set the gains in a process of finding the right exposure. Only few people have access to the source and could implement the manual gain control(i.e. 6by9), but the programming seems to be complicated and the chances to get access to set the gains are very low. But if 6by9 finds some time in his spare time(he is not working for Broadcom any more, but different story...http://www.raspberrypi.org/forums/viewt ... 22#p589522) he could try to fix the -ex off or tell us how it should be used.

ArjnJ
Posts: 12
Joined: Wed Oct 15, 2014 3:30 pm

Re: Remove metering

Fri Jan 23, 2015 10:53 am

Thanks for the info, I'll wait in anticipation!

Joan Carles
Posts: 23
Joined: Fri Jun 13, 2014 10:22 am

Re: Remove metering

Wed Jun 10, 2015 8:34 pm

Hi!

I am getting a bit crazy :)

I need to make every values fixed on configuration of the PiCam in video mode, I guess as you guys. Could you confirm my assumptions please? I am using userland drivers.

For taking off every auto values I have to set:
params->sharpness = 0;
params->contrast = 0;
params->brightness = 10;
params->saturation = 0;
params->ISO = 400; //for example, but never 0 (auto)
params->videoStabilisation = 0;
params->exposureCompensation = 0;
params->exposureMode = MMAL_PARAM_EXPOSUREMODE_OFF;
params->exposureMeterMode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
params->awbMode = MMAL_PARAM_AWBMODE_OFF;
params->awb_gains_r = 1; // Only have any function if AWB OFF is used.
params->awb_gains_b = 1;
params->imageEffect = MMAL_PARAM_IMAGEFX_NONE;
params->colourEffects.enable = 0;
params->colourEffects.u = 128;
params->colourEffects.v = 128;
params->rotation = 0;
params->hflip = params->vflip = 0;
params->roi.x = params->roi.y = 0.0;
params->roi.w = params->roi.h = 1.0;
params->shutter_speed = 100000; //for example but never 0 (auto)

I have add:
{"off", MMAL_PARAM_EXPOSUREMODE_OFF} ' to the exposure_map
to:
https://github.com/benjamn/offgrid-came ... mControl.c

And last but not least MMAL_PARAM_EXPOSUREMODE_OFF is not declared in driver, so I need to add the next code into 'control.c'
(https://github.com/raspberrypi/linux/bl ... ols.c#L347)

if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
shutter_speed = dev->manual_shutter_speed;

ret = vchiq_mmal_port_parameter_set(dev->instance,
control,
MMAL_PARAMETER_SHUTTER_SPEED,
&shutter_speed,
sizeof(shutter_speed));
ret += vchiq_mmal_port_parameter_set(dev->instance,
control,
MMAL_PARAMETER_EXPOSURE_MODE,
&exp_mode,
sizeof(u32));

But... Where is control.c? Which folder is in?

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

Re: Remove metering

Wed Jun 10, 2015 10:30 pm

I think you mix the v4l2 driver and the userland tools. The programs like raspivid and raspistill are using mmal to "talk" to the camera and no kernel driver(control.c is part of the v4l2 module). For me it is unclear, which source you want to use. And why you think that MMAL_PARAM_EXPOSUREMODE_OFF is not declared? It is a parameter defined in
"interface/mmal/mmal_parameters_camera.h" and set when the function "raspicamcontrol_set_all_parameters" is called. Could you explain, which program you try to compile and what changes you want to include?

Joan Carles
Posts: 23
Joined: Fri Jun 13, 2014 10:22 am

Re: Remove metering

Thu Jun 11, 2015 8:40 am

Yes, I am mixing them, I am in an intermediate level :oops: Thanks, because all you can tell me it helps me :)

I am using userland tools, a modification of this program:
http://www.cheerfulprogrammer.com/downl ... am_gpu.zip
(In this site: http://robotblogging.blogspot.co.uk/201 ... i-for.html)

Everything is working well, except MMAL_PARAM_EXPOSUREMODE_OFF which when I set it I get black screen (with the configuration I wrote in the other message). (I set shutter_speed to 100000... like the message before)

Time ago I have solved a problem with MMAL_PARAM_AWBMODE_OFF as well.

My aim is to remove the automatic parameters in acquisition.

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

Re: Remove metering

Thu Jun 11, 2015 10:34 am

Joan Carles wrote: Everything is working well, except MMAL_PARAM_EXPOSUREMODE_OFF which when I set it I get black screen (with the configuration I wrote in the other message). (I set shutter_speed to 100000... like the message before)
Yes this is the reason, why the parameter MMAL_PARAM_EXPOSUREMODE_OFF was removed.
It will not work. The digital gain is set to 0 and the picture will be black. You should look for a different way to fix the exposure mode.
I.e. setting iso to 100 and the exposure compensation ev to -24. Or setting the exp mode to "auto" and switch to "off" after some time.

Joan Carles
Posts: 23
Joined: Fri Jun 13, 2014 10:22 am

Re: Remove metering

Thu Jun 11, 2015 12:35 pm

Sorry to be persistent (it's important) :D

If I do what you say:
You should look for a different way to fix the exposure mode.
I.e. setting iso to 100 and the exposure compensation ev to -24. Or setting the exp mode to "auto" and switch to "off" after some time.
{
params->exposureMode = MMAL_PARAM_EXPOSUREMODE_OFF;
params->exposureCompensation = -24;
params->ISO = 100;
}

Will 'EXPOSUREMODE' be invariable (not AUTO)?

Sorry, but it is complicated (or I don't know how) to check?

Thank you so much!!!

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

Re: Remove metering

Thu Jun 11, 2015 1:40 pm

Joan Carles wrote:Will 'EXPOSUREMODE' be invariable (not AUTO)?
Yes.
EXPOSURE_MODE sets up how the AGC tuner tries to adapt the scene from that point on. OFF means "don't change it". The other modes mean "change it within set of parameters X".
The issue is that "Don't change it" means exactly that, and the default isn't totally useful (mainly digital gain = x0.0). If it has run in auto mode for a few frames, then all settings will have been initialised, and OFF will just lock everything at those settings, never to change again until you tell it otherwise.

I will try to find a few minutes to see why my previous fix for setting digital gain to x1.0 if not initialised isn't working any more. I do remember it wasn't a trivial one to set up. I wonder if it is because you are setting ISO and that is changing the code path (it is slightly spaghetti like in there).
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.

Joan Carles
Posts: 23
Joined: Fri Jun 13, 2014 10:22 am

Re: Remove metering

Thu Jun 11, 2015 6:45 pm

I will try to find a few minutes to see why my previous fix for setting digital gain to x1.0 if not initialised isn't working any more.
It would be great!!

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

Re: Remove metering

Fri Jun 12, 2015 5:01 pm

Ahem. From my firmware patch:

Code: Select all

         gain_params.gain = 256;
         (*state->isp->get_gain)(state->isp_handle, &gain_params, 0);
A one character typo there by the looks of it - is there much difference between get and set?! Don't ask me how it was working before, although adding userland handling for "-exp off" seems to indicate there is race hazard as to whether I saw the problem or not. (Component is enabled before all the parameters are set, so the first frame may go through before AGC gets locked, in which case all is good).
I'm testing with

Code: Select all

raspistill -ex off -ss 10000 -t 20000 -set
and adding in "-ISO 100" to check if that makes a difference (I'll check -ISO 800 later - not 100% certain how that will work if AGC is locked).
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.

Return to “Camera board”