Technical Blog

Switch camera with the AR.Drone SDK

The AR.Drone has two cameras, but we can only use one at a time. Therefore, we can need to change the camera whose images are sent by the drone.

The different channels

The different channels are declared in ARDroneLib/Soft/Common/ardrone_api.h with the following enum:


They are 4 main values to select the video stream:




Note: images come from the Doc folder of the AR.Drone SDK.

Changing the camera

We use the following code to select the camera:

ARDRONE_TOOL_CONFIGURATION_ADDEVENT (video_channel, &channel, cb);

The cb parameter

cb is a pointer to a function called when the command is executed. It is defined in the Developer’s Guide:

The callback function type is void (*callBack)(unsigned int success). The configuration tool will call the callback function after any attempt to set the configuration, with zero as the parameter in case of failure, and one in case of success. In case of failure, the tool will automatically retry after an amount of time.

Handling the different resolutions

The vertical camera has a smaller resolution: width and height are only half of the horizontal (frontal) camera. Nevertheless, the data transmitted by the drone have the same size. Therefore, if you display the image, only a quarter of the image will be the camera’s image, and the rest will be green pixels. To create a Pixbuf structure containing only the good pixels, use the following code:

buf = gdk_pixbuf_new_from_data(pixbuf_data,
                               320 * 3,

This trick is to give as parameter the correct reduced width of 176 pixels, but to indicate that each new line starts after 320 * 3 pixels, so it will skip useless pixels. The height parameter is also reduced to 144, so the bottom of the image, filled with green pixels, is ignored.

Next, you can enlarge the image to have the same size as the horizontal camera:

pixbuf = gdk_pixbuf_scale_simple (pixbuf,
                                  GDK_INTERP_BILINEAR) ;
  • Alessandro Benini

    In which file do I need to make this modifications in order to change the camera?


  • Anonymous

    You can do this wherever you want (initialization function, button’s callback, etc.).

  • jose

    Hey, what’s up!! First I want to give you thanks because these posts about ARDrone, they are help me much. Well, I am working on my final study project and now I am trying to show the diferents channels (zaps) in my opencv window (I have the same as you post on the ‘Use OpenCV with the AR.Drone SDK’ post in my video_stage.c). When I introduce the ARDRONE_TOOL_CONFIGURATION_ADDEVENT in the ‘output_gtk_stage_open’ function or in the DEFINE_ROUTINE_THREAD of video_stage.c or even in the ‘ardrone_tool_init_custom’ it doesn’t work: it continues show the frontal camera (ZAP_CHANNEL_HORI). Do you know what I am doing wrong?

  • jose

    Well I found a solution. If I put these lines in the ‘output_gtk_stage_transform’ function, it changed to the zap I want. I don’t know why but it works xD. When I discover it I post it here

  • Mcives

    Hi again after following through this page and others I tried to rebuild the Linux examples and I end up with these errors:

    In file included from ../..//Soft/Lib/ardrone_tool/Navdata/navdata.c:6:0:
    ../..//Soft/Common/ardrone_api.h:105:53: error: expected ‘)’ before ‘&’ token
    ../..//Soft/Common/ardrone_api.h:107:1: warning: data definition has no type or storage class [enabled by default]
    ../..//Soft/Common/ardrone_api.h:107:1: warning: type defaults to ‘int’ in declaration of ‘buf’ [-Wimplicit-int]
    ../..//Soft/Common/ardrone_api.h:107:32: error: ‘pixbuf_data’ undeclared here (not in a function)
    ../..//Soft/Common/ardrone_api.h:117:1: warning: data definition has no type or storage class [enabled by default]
    ../..//Soft/Common/ardrone_api.h:117:1: warning: type defaults to ‘int’ in declaration of ‘pixbuf’ [-Wimplicit-int]
    ../..//Soft/Common/ardrone_api.h:120:35: warning: passing argument 1 of ‘gdk_pixbuf_scale_simple’ makes pointer from integer without a cast [enabled by default]
    /usr/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-transform.h:138:12: note: expected ‘const struct GdkPixbuf *’ but argument is of type ‘int’
    ../..//Soft/Common/ardrone_api.h:117:10: warning: initialization makes integer from pointer without a cast [enabled by default]
    ../..//Soft/Common/ardrone_api.h:120:35: error: initializer element is not constant
    In file included from ../..//Soft/Lib/ardrone_tool/Navdata/navdata.c:6:0:
    ../..//Soft/Common/ardrone_api.h:592:22: error: unknown type name ‘ZAP_VIDEO_CHANNEL’
    make[5]: *** [../../Soft/Build/targets_versions/ardrone_lib_PROD_MODE_ffmpeg_Intel_Linux_3.0.0-15-generic_GNU_Linux_gcc_4.6.1/ardrone_tool/Navdata/navdata.o] Error 1
    make[4]: *** [all] Error 2
    make[3]: *** [build_lib] Error 2
    make[3]: Leaving directory `/home/matthew/ARDroneAPI/ARDroneLib/VP_SDK/Build’
    make[2]: *** [all] Error 2
    make[2]: Leaving directory `/home/matthew/ARDroneAPI/ARDroneLib/Soft/Lib/Build’
    make[1]: *** [build_libs] Error 2
    make[1]: Leaving directory `/home/matthew/ARDroneAPI/ARDroneLib/Soft/Build’
    make: *** [all] Error 2

    If you have any idea on how to solve this I would be very grateful

  • Mcives


    What files should the buf and pixbuf be inserted into because when placed into ardrone_api.h they are undefined?

    and ‘ZAP_VIDEO_CHANNEL channel’ is causing errors such as the compiler is expecting ‘=’ ‘,’ ‘;’ ‘asm’?

    any ideas would be greatly appreciated

  • JT


    I need to switch the camera but I don’t understand how to manipulate the cb paramter.
    Can you show me the part of your code where you switch the camera ? Maybe it will help me to understand.

    Thank you,


  • Anonymous


    It is a pointer to a function like this one:
    void my_callback_function(unsigned int success)
    // do something
    The function is called after changing the settings, and success can be 0 (failure) or 1 (success), it’s a way to handle error for instance.

    If you don’t need it, simply use NULL as cb argument.

    This article includes a working example of code that switches the camera, which requires a function named cb in the scope. If you don’t need a callback function, you can do this way:
    ARDRONE_TOOL_CONFIGURATION_ADDEVENT (video_channel, &channel, NULL);

    Bon courage cher rennais ;-)