Webots Reference Manual

previous page go up next page

Thanks

1.Introduction

2.Controller API

3.Webots File Format

     

2.5 Camera

camera_enable, camera_disable
camera_new_widget
camera_get_fov, camera_set_fov
camera_get_width, camera_get_height
camera_get_type
camera_get_image, camera_image_get_red, camera_image_get_green, camera_image_get_blue

camera_enable

NAME

   camera_enable, camera_disable -- enable and disable the camera measurements

SYNOPSIS

  #include <device/camera.h>

   void camera_enable (DeviceTag camera, guint16 ms);
   void camera_disable (DeviceTag camera);

DESCRIPTION

camera_enable allows the user to enable a camera measurement each ms milliseconds.

camera_disable turns the camera off, saving computation time.

camera_new_widget

NAME

   camera_new_widget -- create a GTK+ widget for displaying the camera view

SYNOPSIS

  #include <device/camera.h>

   GtkWidget *camera_new_widget (DeviceTag camera);

DESCRIPTION

camera_new_widget creates a new GTK+ widget for a camera. Creating such a widget is useful only if you want to embed it into your own graphical user interface, otherwise, if you don't create any camera widget, the controller library will do it automatically in a separate window. It is mandatory to have such a widget displayed to allow OpenGL rendering. This constraint is mainly due to 3D hardware which often cannot render an off screen image.

camera_get_fov

NAME

   camera_get_fov, camera_set_fov -- get and set field of view for a camera

SYNOPSIS

  #include <device/camera.h>

   gfloat camera_get_fov (DeviceTag camera);
   void camera_set_fov (DeviceTag camera, gfloat fov);

DESCRIPTION

These functions allow the controller to get and set the value for the field of view (fov) of a camera. The original value for this field of view is defined in the Camera node, as fieldOfView. Note however, that changing the field of view using camera_set_fov will not change the value of the fieldOfView field on the simulator side. It will only affect the controller side, making new rendered images use the specified field of view for the specified camera.

camera_get_width

NAME

   camera_get_width, camera_get_height -- get the size of the camera image

SYNOPSIS

  #include <device/camera.h>

   guint16 camera_get_width (DeviceTag camera);
   guint16 camera_get_height (DeviceTag camera);

DESCRIPTION

These functions return the width and height of a camera image as defined in the corresponding Camera node.

camera_get_type

NAME

   camera_get_type -- get the type of the camera

SYNOPSIS

  #include <device/camera.h>

   gchar camera_get_type (DeviceTag camera);

DESCRIPTION

This function returns the type of a camera as defined in the corresponding Camera node. If the type is "black and white" or "grey", then the return value is 'g', otherwise, the return value is 'c', standing for color.

camera_get_image

NAME

   camera_get_image, camera_image_get_red, camera_image_get_green, camera_image_get_blue -- get the image data from a camera

SYNOPSIS

  #include <device/camera.h>

   guint8 *camera_get_image (DeviceTag camera);
   guint8 camera_image_get_red (image, width, x, y);
   guint8 camera_image_get_green (image, width, x, y);
   guint8 camera_image_get_blue (image, width, x, y);

DESCRIPTION

The camera_get_image function allows you to read the contents of the last image grabbed by the camera. The image is coded as a series of three bytes coding for the red, green and blue levels of a pixel. Pixels are stored in lines ranging from the bottom left hand side of the image up to top right hand side. The memory chunck returned by this function doesn't need to be released, as it is handled by the camera itself. The size in bytes of this memory chunk can be computed as follow:

size = camera_width * camera_height * 3

Attempting to read outside the bounds of this chunk will cause an error.

The camera_image_get_ macros are useful helpers for accessing directly the pixel colors from the pixel coordinates. They are defined as follow:


#define camera_image_get_red(image,width,x,y)   (image[3*((y)*(width)+(x))])
#define camera_image_get_green(image,width,x,y) (image[3*((y)*(width)+(x))+1])
#define camera_image_get_blue(image,width,x,y)  (image[3*((y)*(width)+(x))+2])
    

previous page go up next page
^ page top ^

  E-mail to webmaster Last updated: Copyright © 2002 Cyberbotics Ltd.