Difference between revisions of "Librraew 1.0"

From RidgeRun Developer Connection
Jump to: navigation, search
(Created page with '= Overview = == Auto white balance == The librraew supports several AWB algorithms: ;Gray World :The Gray World algorithm is based on the assumption that given an image with suf...')
 
Line 172: Line 172:
 
</pre>
 
</pre>
  
The first command will chain the ipiped using an existing script. The second one will start the auto-white balance and the auto-exposure algorithms for an image size of 640x480 pixels and a minimum frame rate of 30fps (See [https://www.ridgerun.com/developer/wiki/index.php?title=RidgeRun_Auto_exposure/Auto_white_balance_library&action=submit#Controlling_librraew_with_ipipe Controlling librraew with ipipe] section for more details).
+
The first command will chain the ipiped using an existing script. The second one will start the auto-white balance and the auto-exposure algorithms for an image size of 640x480 pixels and a minimum frame rate of 30fps (See [https://www.ridgerun.com/developer/wiki/index.php/Librraew_1.0#Controlling_librraew_with_ipipe Controlling librraew with ipipe] section for more details).
  
 
Once you have the ipiped and the AEW algorithms running you can run any image/video capture GStreamer pipeline to test it.
 
Once you have the ipiped and the AEW algorithms running you can run any image/video capture GStreamer pipeline to test it.
Line 196: Line 196:
 
</pre>
 
</pre>
  
The first command will chain the ipiped using an existing script. The second one will start the auto-white balance and the auto-exposure algorithms for an image size of 640x480 pixels and a minimum frame rate of 30fps (See [https://www.ridgerun.com/developer/wiki/index.php?title=RidgeRun_Auto_exposure/Auto_white_balance_library&action=submit#Controlling_librraew_with_ipipe Controlling librraew with ipipe] section for more details).
+
The first command will chain the ipiped using an existing script. The second one will start the auto-white balance and the auto-exposure algorithms for an image size of 640x480 pixels and a minimum frame rate of 30fps (See [https://www.ridgerun.com/developer/wiki/index.php/Librraew_1.0#Controlling_librraew_with_ipipe Controlling librraew with ipipe] section for more details).
  
 
Once you have the ipiped and the AEW algorithms running you can run any image/video capture GStreamer pipeline to test it.
 
Once you have the ipiped and the AEW algorithms running you can run any image/video capture GStreamer pipeline to test it.

Revision as of 15:12, 26 July 2011

Overview

Auto white balance

The librraew supports several AWB algorithms:

Gray World
The Gray World algorithm is based on the assumption that given an image with sufficient amount of color variation, the average reflectance of the scene is achromatic(gray). To be achromatic, the mean of the red, green, and blue channels in a given scene should be roughly equal. If the scene has a color that dominates, the results of the algorithm may not be satisfactory.
White Patch
The White Patch algorithm assumes that the maximum response in an image is caused by a perfect reflector, that represents the color of the illumination. White balancing attempts to equalize the maximum value of the three channels to produce a white patch. This algorithm must be used on scenes that ensure the captured image does not include saturated pixels.
White Patch 2
This variation of the White Patch algorithm aims to resolve the problems with the saturated pixels. White Patch 2 ses an average of local maximums instead of an absolute maximum. The results can change depending of the number of sample windows used in processing the image.

Auto exposure

Librraew includes one AE algorithm that can use five brightness metering methods. The algorithm uses an electronic-centric approach based on the mid-tone idea. This algorithm uses metrics gotten for the sensor capture image as light metering. Calculates the required exposure time to get an optimal image brightness, using an expression that relates actual scene brightness, actual exposure time and the defined optimal image brightness. The optimal image brightness is defined as the value of the mid-tone.

All the metering systems define a pixel brightness as the average of the red, blue and green component. Bellow a brief description of the brightness metering methods is presented:

Partial
Averages the brightness of the pixels in a portion in the center of the frame, the rest of the frame is ignored. It is generally used when very bright or very dark areas on the edges of the frame would otherwise influence on a bad way the scene illumination.
Center weighted
Average the light information coming from the entire frame. Get brightness average of to regions: the pixels in a portion in the center and the pixels in the rest of the frame (background). The total brightness is calculated with emphasis placed on the center area. 75% of the total brightness is given by the center brightness and 30% by the background. This algorithm can be used when you want that the whole scene be well illuminated and not be affected for the small edges brightness variations. The subjects of the picture must be at the center of the image. But, if a back light is present into the scene the central part results darker than the rest of the scene and unpleasant underexposed foreground is produced.
Segmented
This algorithm is designed for scenes that have a principal object in backlighting condition. Emphasize the luminance of the main object according to the degree of backlighting. Divides the frame on 6 pieces and weighting them.
Average
Average the light information coming from the entire frame without weighting any particular portion of the metered area. This algorithm can be used on scenes that not have a principal object and you want an average illumination. If the scene has a high contrast, the algorithm cause under or over exposure of parts of the scene.

The center area for all the metering system is defined by a percentage of the image size and can be set by a librraew parameter.

Implementation Details

Three applications are used to support the auto exposure and auto white-balance (AEW) adjustments in the RidgeRun's SDK:

  • Ipiped, a D-Bus server for controlling and configuring the camera sensor, the dm365 video processor and the aew library.
  • librraew, a library that includes auto white balance and auto exposure algorithms.
  • Ipipe-client, an D-Bus client that can be used to invoke any of the methods supported by the Ipiped.

Running Ipiped

Ipiped must run in background. If you are using RidgeRun's SDK and enabled ipiped it will be setup to start automatically when the system boots.

 ipiped &

Ipiped registers with D-Bus and waits until ipipe-client requests to execute a method.

Running Ipipe-client

Ipipe-client is a Dbus client that use commands to invoke methods of the ipiped, so ipiped must be running to use ipipe-client. A command can required arguments depending of the functionality. Ipipe-client has two operation modes, you can ask to execute a single command or you can open an interactive console to execute a group of commands.

To execute a single command, you can use the following command line syntax

 ipipe-client <command> <argument 1> ... <argument n>

To get into the interactive console, you have to run ipipe-client without any command. Then to execute a command you only need to use the command and the required arguments.

ipipe-client
ipipe-client$ <command 1> <argument 1> ... <argument n>
ipipe-client$ <command 2> <argument 1> ... <argument n>

To quit the interactive console you can use quit or exit.

In order to know the commands that are available run:

ipipe-client help

or get into the interactive console and execute help.

This shows a description of each command, as follows:

Command                         Description

help                    Displays the help text for all the possible commands or a specific command.
set-debug               Enable/Disable debug messages.
init-aew                Initialize AEW algorithms.
stop-aew                End AEW algorithm.
shell                   Execute a shell command(shell_cmd) using interactive console.
ping                    Show if ipipe-daemon is alive.
quit                    Quit from the interactive console.
exit                    Exit from the interactive console.
get-video-processor     Show the video processor that is being used.
get-sensor              Show the sensor that is being used.
run-config-script       Execute a group of ipipe-client commands.
set-previewer-mode      Configure previewer on continuous or one-shot mode.
set-bayer-pattern       Sets R/Gr/Gb/B color pattern to the previewer.
set-digital-gain        Sets red (R), green (G) and blue gains (G) on the ipipe.
get-digital-gain        Returns the gain value for each color component(RGB).
set-luminance           Brightness(Br) and contrast(C) adjustment.
get-luminance           Returns the value of the Brightness(Br) and contrast(C) adjustment.
flip-vertical           Flips the image vertically(on the sensor).
flip-horizontal         Flips the image horizontally (on the sensor).
set-exposure            Sets the effective shutter time  of the sensor for the light integration.
get-exposure            Gets the exposure time of the sensor in us.
set-sensor-gain         Sets red(R), green(G) and blue(B) gain directly on the sensor.
get-sensor-gain         Gets sensor red(R), green(G) and blue(B).

If you want more detailed information about a command execute:

ipipe-client help <command> 

Controlling librraew with ipipe

Auto exposure and auto white balance adjustments can be started with an ipipe-client's command called init-aew. Init-aew requires some arguments to define the algorithms and other parameters. To see the arguments required you can request for help that show you the list as follows:

Command: init-aew
Syntax: init-aew <WB> <AE> <G> <EM> <T[us]> <fps> <seg> <width> <height>
Description: Initialize AEW algorithms                                  
Arguments:
        WB: white balance algorithm, the options are:
                G -for gray world algorithm
                W -for retinex algorithm
                W2 -for variant of retinex algorithm
                N -for none
        AE: auto exposure algorithm, the options are
                EC -for electronic centric
                N -for none
        G: gain type, the options are:
                S -to use the sensor gain
                D -to use the digital
        EM: exposure metering method, the options are:
                P -for partial metering that take into account the light
                information of a portion in the center and the rest of
                the frame is ignored. The size  of the center depends of
                of the parameter center_percentage
                C -for center weighted metering that take into account
                the light information coming from the entire frame with
                emphasis placed on the center area
                A -for average metering that take into account the light
                information from the entire frame without weighting
                SG -for segmented metering that divides the frame
                on 6 pieces and weighting them to avoid backlighting
        T: wait time in us, specifies the time between
                algorithm adjustments, max value=1s=1000000us
        fps: minimum frame rate
        seg: frame segmentation factor, each frame is segmented into
                regions, this factor represents the percentage of the
                maximum number of possible regions
        width: captured video/image horizontal size
        height: captured video/image vertical size
        center_percentage: defines the percentage of the image width
                and height to be used as the center size


Also you can stop automatic adjustments with the command stop-aew

Some of the init-aew arguments need to be explained in more detail:

  • T: the time between interactions defines how fast the algorithm can adjust the scene parameters. If you don't need fast changes you can use a greater time to get less CPU usage.
  • seg: this factor is related with the amount of CPU usage and the auto-adjustments precision. If you use a high segmentation percentage you will have greater CPU usage but you will get more precision on the adjustments.

Using librraew with other software rather than ipiped

librraew is a plain C library and can be re-used and integrated with any custom application. Please contact RidgeRun for the documentation of the librraew API.

Using the demo version of librraew

You can request a demo version of librraew in order to test the auto-white balance and auto-exposure algorithms before you decide to buy it. This library will allow you to use all the features that comes with the full version of the librraew but with the following limitations:

  • The algorithm will be darken the image periodically.
  • After a while the algorithm will stop working and the image capturing will be done with the last values calculated by the library. In order to test the library again you will need to restart the algorithm.

Basic example of use

In this section it will be shown a basic example of use of the ipiped and the librraew library.

JPEG capture for 640x480 pixels image

Once your board has started run the following commands:

ipipe-client run-config-script dm365_mt9p031_config
ipipe-client init-aew G EC S C 200000 30 50 640 480 50

The first command will chain the ipiped using an existing script. The second one will start the auto-white balance and the auto-exposure algorithms for an image size of 640x480 pixels and a minimum frame rate of 30fps (See Controlling librraew with ipipe section for more details).

Once you have the ipiped and the AEW algorithms running you can run any image/video capture GStreamer pipeline to test it.

As an example it was used the pipeline shown below which captures 30 images from the camera module and encodes them to JPEG format in order to get 30 different JPEG images.

gst-launch -e v4l2src always-copy=false num-buffers=30 chain-ipipe=false ! video/x-raw-yuv,format=\(fourcc\)UYVY, \
width=640, height=480 !  dmaienc_jpeg ! queue !  multifilesink location=image%0d.jpeg

The images 1 and 2 show the difference between an image captured with and without the AEW algorithm, respectively. As it is possible to see, the AEW algorithm provides a better image quality controlling the brightness and the exposure time.

Figure 1. Image taken using the AEW algorithm.
Figure 2. Image taken without the AEW algorithm.

JPEG capture for 1280x720 (720P) pixels image

Once your board has started run the following commands:

ipipe-client run-config-script dm365_mt9p031_config
ipipe-client init-aew G EC S C 200000 30 50 1280 720 50

The first command will chain the ipiped using an existing script. The second one will start the auto-white balance and the auto-exposure algorithms for an image size of 640x480 pixels and a minimum frame rate of 30fps (See Controlling librraew with ipipe section for more details).

Once you have the ipiped and the AEW algorithms running you can run any image/video capture GStreamer pipeline to test it.

As an example it was used the pipeline shown below which captures 30 images from the camera module and encodes them to JPEG format in order to get 30 different JPEG images.

gst-launch -e v4l2src always-copy=false num-buffers=30 chain-ipipe=false ! video/x-raw-yuv,format=\(fourcc\)UYVY, \
width=1280, height=720 !  dmaienc_jpeg ! queue !  multifilesink location=image%0d.jpeg

The images 3 and 4 show the difference between an image captured with and without the AEW algorithm, respectively. As it is possible to see, the AEW algorithm provides a better image quality controlling the brightness and the exposure time.

Figure 3. 720P image taken using the AEW algorithm.
Figure 4. 720P image taken without the AEW algorithm.