Top |
ArvCamera is a class for the generic control of cameras. It hides the complexity of the genicam interface by providing a simple API, with the drawback of not exposing all the available features. See ArvDevice and ArvGc for a more advanced use of the Aravis library.
Example 1. Example use of the ArvCamera API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
#include <arv.h> #include <stdlib.h> #include <signal.h> #include <stdio.h> typedef struct { GMainLoop *main_loop; int buffer_count; } ApplicationData; static gboolean cancel = FALSE; static void set_cancel (int signal) { cancel = TRUE; } static void new_buffer_cb (ArvStream *stream, ApplicationData *data) { ArvBuffer *buffer; buffer = arv_stream_try_pop_buffer (stream); if (buffer != NULL) { if (arv_buffer_get_status (buffer) == ARV_BUFFER_STATUS_SUCCESS) data->buffer_count++; /* Image processing here */ arv_stream_push_buffer (stream, buffer); } } static gboolean periodic_task_cb (void *abstract_data) { ApplicationData *data = abstract_data; printf ("Frame rate = %d Hz\n", data->buffer_count); data->buffer_count = 0; if (cancel) { g_main_loop_quit (data->main_loop); return FALSE; } return TRUE; } static void control_lost_cb (ArvGvDevice *gv_device) { /* Control of the device is lost. Display a message and force application exit */ printf ("Control lost\n"); cancel = TRUE; } int main (int argc, char **argv) { ApplicationData data; ArvCamera *camera; ArvStream *stream; int i; data.buffer_count = 0; /* Mandatory glib type system initialization */ arv_g_type_init (); /* Instantiation of the first available camera */ camera = arv_camera_new (NULL); if (camera != NULL) { void (*old_sigint_handler)(int); gint payload; /* Set region of interrest to a 200x200 pixel area */ arv_camera_set_region (camera, 0, 0, 200, 200); /* Set frame rate to 10 Hz */ arv_camera_set_frame_rate (camera, 10.0); /* retrieve image payload (number of bytes per image) */ payload = arv_camera_get_payload (camera); /* Create a new stream object */ stream = arv_camera_create_stream (camera, NULL, NULL); if (stream != NULL) { /* Push 50 buffer in the stream input buffer queue */ for (i = 0; i < 50; i++) arv_stream_push_buffer (stream, arv_buffer_new (payload, NULL)); /* Start the video stream */ arv_camera_start_acquisition (camera); /* Connect the new-buffer signal */ g_signal_connect (stream, "new-buffer", G_CALLBACK (new_buffer_cb), &data); /* And enable emission of this signal (it's disabled by default for performance reason) */ arv_stream_set_emit_signals (stream, TRUE); /* Connect the control-lost signal */ g_signal_connect (arv_camera_get_device (camera), "control-lost", G_CALLBACK (control_lost_cb), NULL); /* Install the callback for frame rate display */ g_timeout_add_seconds (1, periodic_task_cb, &data); /* Create a new glib main loop */ data.main_loop = g_main_loop_new (NULL, FALSE); old_sigint_handler = signal (SIGINT, set_cancel); /* Run the main loop */ g_main_loop_run (data.main_loop); signal (SIGINT, old_sigint_handler); g_main_loop_unref (data.main_loop); /* Stop the video stream */ arv_camera_stop_acquisition (camera); g_object_unref (stream); } else printf ("Can't create stream thread (check if the device is not already used)\n"); g_object_unref (camera); } else printf ("No camera found\n"); return 0; } |
ArvCamera *
arv_camera_new (const char *name
);
Creates a new ArvCamera. If name
is null, it will instantiate the
first available camera.
Since: 0.2.0
ArvStream * arv_camera_create_stream (ArvCamera *camera
,ArvStreamCallback callback
,void *user_data
);
Creates a new ArvStream for video stream handling. See ArvStreamCallback for details regarding the callback function.
camera |
||
callback |
a frame processing callback. |
[scope call][allow-none] |
user_data |
user data for |
[closure][allow-none] |
Since: 0.2.0
ArvDevice *
arv_camera_get_device (ArvCamera *camera
);
Retrieves the ArvDevice object for more complete access to camera features.
Since: 0.2.0
const char *
arv_camera_get_vendor_name (ArvCamera *camera
);
Since: 0.2.0
const char *
arv_camera_get_model_name (ArvCamera *camera
);
Since: 0.2.0
void arv_camera_get_sensor_size (ArvCamera *camera
,gint *width
,gint *height
);
Since: 0.2.0
void arv_camera_set_region (ArvCamera *camera
,gint x
,gint y
,gint width
,gint height
);
Defines the region of interest which will be transmitted in the video stream.
Since: 0.2.0
void arv_camera_get_region (ArvCamera *camera
,gint *x
,gint *y
,gint *width
,gint *height
);
Retrieves the current region of interest.
camera |
||
x |
x offset. |
[out] |
y |
y_offset. |
[out] |
width |
region width. |
[out] |
height |
region height. |
[out] |
Since: 0.2.0
void arv_camera_get_height_bounds (ArvCamera *camera
,gint *min
,gint *max
);
Retrieves the valid range for image height.
Since: 0.2.0
void arv_camera_get_width_bounds (ArvCamera *camera
,gint *min
,gint *max
);
Retrieves the valid range for image width.
Since: 0.2.0
void arv_camera_set_binning (ArvCamera *camera
,gint dx
,gint dy
);
Defines binning in both directions. Not all cameras support this feature.
Since: 0.2.0
void arv_camera_get_binning (ArvCamera *camera
,gint *dx
,gint *dy
);
Retrieves binning in both directions.
Since: 0.2.0
void arv_camera_set_pixel_format (ArvCamera *camera
,ArvPixelFormat format
);
Defines pixel format.
Since: 0.2.0
ArvPixelFormat
arv_camera_get_pixel_format (ArvCamera *camera
);
Since: 0.2.0
const char *
arv_camera_get_pixel_format_as_string (ArvCamera *camera
);
Retuns: pixel format as string, NULL on error.
Since: 0.2.0
void arv_camera_set_pixel_format_from_string (ArvCamera *camera
,const char *format
);
Defines pixel format described by a string.
Since: 0.2.0
gint64 * arv_camera_get_available_pixel_formats (ArvCamera *camera
,guint *n_pixel_formats
);
Retrieves the list of all available pixel formats.
a newly allocated array of ArvPixelFormat.
[array length=n_pixel_formats][transfer container]
Since: 0.2.0
const char ** arv_camera_get_available_pixel_formats_as_display_names (ArvCamera *camera
,guint *n_pixel_formats
);
Retrieves the list of all available pixel formats as display names. In general, these human-readable strings cannot be used as settings.
a newly allocated array of string constants.
[array length=n_pixel_formats][transfer container]
Since: 0.2.0
const char ** arv_camera_get_available_pixel_formats_as_strings (ArvCamera *camera
,guint *n_pixel_formats
);
Retrieves the list of all available pixel formats as strings.
Since: 0.2.0
void
arv_camera_start_acquisition (ArvCamera *camera
);
Starts video stream acquisition.
Since: 0.2.0
void
arv_camera_stop_acquisition (ArvCamera *camera
);
Stops video stream acquisition.
Since: 0.2.0
void
arv_camera_abort_acquisition (ArvCamera *camera
);
Aborts video stream acquisition.
Since: 0.4.0
void arv_camera_set_acquisition_mode (ArvCamera *camera
,ArvAcquisitionMode value
);
ArvAcquisitionMode
arv_camera_get_acquisition_mode (ArvCamera *camera
);
Since: 0.2.0
gboolean
arv_camera_is_frame_rate_available (ArvCamera *camera
);
Since: 0.2.0
void arv_camera_set_frame_rate (ArvCamera *camera
,double frame_rate
);
Configures a fixed frame rate mode. Once acquisition start is triggered, the video stream will be acquired with the given frame rate.
Since: 0.2.0
void arv_camera_get_frame_rate_bounds (ArvCamera *camera
,double *min
,double *max
);
Retrieves allowed range for framerate.
Since 0.2.2
void arv_camera_set_trigger (ArvCamera *camera
,const char *source
);
Configures the camera in trigger mode. Typical values for source are "Line1" or "Line2". See the camera documentation for the allowed values. Activation is set to rising edge. It can be changed by accessing the underlying device object.
Source can also be "Software". In this case, an acquisition is triggered
by a call to arv_camera_software_trigger()
.
Since: 0.2.0
void arv_camera_set_trigger_source (ArvCamera *camera
,const char *source
);
Sets the trigger source. This function doesn't check if the camera is configured to actually use this source as a trigger.
Since: 0.2.0
const char *
arv_camera_get_trigger_source (ArvCamera *camera
);
Gets the trigger source. This function doesn't check if the camera is configured to actually use this source as a trigger.
Since: 0.2.0
void
arv_camera_software_trigger (ArvCamera *camera
);
Sends a software trigger command to camera
. The camera must be previously
configured to use a software trigger, using
.arv_camera_set_trigger()
Since: 0.2.0
gboolean
arv_camera_is_exposure_time_available (ArvCamera *camera
);
Since: 0.2.0
gboolean
arv_camera_is_exposure_auto_available (ArvCamera *camera
);
Since: 0.2.0
void arv_camera_set_exposure_time (ArvCamera *camera
,double exposure_time_us
);
Sets exposure time. User should take care to set a value compatible with the desired frame rate.
Since: 0.2.0
double
arv_camera_get_exposure_time (ArvCamera *camera
);
Since: 0.2.0
void arv_camera_get_exposure_time_bounds (ArvCamera *camera
,double *min
,double *max
);
Retrieves exposure time bounds, in µs.
Since: 0.2.0
void arv_camera_set_exposure_time_auto (ArvCamera *camera
,ArvAuto auto_mode
);
Configures automatic exposure feature.
Since: 0.2.0
ArvAuto
arv_camera_get_exposure_time_auto (ArvCamera *camera
);
Since: 0.2.0
gboolean
arv_camera_is_gain_available (ArvCamera *camera
);
Since: 0.2.0
gboolean
arv_camera_is_gain_auto_available (ArvCamera *camera
);
Since: 0.2.0
void arv_camera_set_gain (ArvCamera *camera
,double gain
);
Sets the gain of the ADC converter.
Since: 0.2.0
void arv_camera_get_gain_bounds (ArvCamera *camera
,double *min
,double *max
);
Retrieves gain bounds.
Since: 0.2.0
void arv_camera_set_gain_auto (ArvCamera *camera
,ArvAuto auto_mode
);
Configures automatic gain feature.
Since: 0.2.0
guint
arv_camera_get_payload (ArvCamera *camera
);
Retrieves the size needed for the storage of an image. This value is used for the creation of the stream buffers.
Since: 0.2.0
gint
arv_camera_gv_get_n_stream_channels (ArvCamera *camera
);
Since: 0.4.0
void arv_camera_gv_select_stream_channel (ArvCamera *camera
,gint channel_id
);
Select the current stream channel.
Since: 0.4.0
int
arv_camera_gv_get_current_stream_channel
(ArvCamera *camera
);
Since: 0.4.0
gint64
arv_camera_gv_get_packet_delay (ArvCamera *camera
);
Since: 0.4.0
void arv_camera_gv_set_packet_delay (ArvCamera *camera
,gint64 delay_ns
);
Configure the inter packet delay to insert between each packet for the current stream channel. This can be used as a crude flow-control mechanism if the application or the network infrastructure cannot keep up with the packets coming from the device.
Since: 0.4.0
gint
arv_camera_gv_get_packet_size (ArvCamera *camera
);
Since: 0.4.0
void arv_camera_gv_set_packet_size (ArvCamera *camera
,gint packet_size
);
Specifies the stream packet size, in bytes, to send on the selected channel for a GVSP transmitter or specifies the maximum packet size supported by a GVSP receiver.
This does not include data leader and data trailer and the last data packet which might be of smaller size (since packet size is not necessarily a multiple of block size for stream channel).
Since: 0.4.0
gboolean
arv_camera_get_chunk_mode (ArvCamera *camera
);
Check wether chunk data mode is active. Please see arv_camera_set_chunk_mode()
.
Since: 0.4.0
gboolean arv_camera_get_chunk_state (ArvCamera *camera
,const char *chunk
);
Gets state of chunk data. Chunk data are be embedded in ArvBuffer only
if chunk mode is active. Please see arv_camera_set_chunk_mode()
.
Since: 0.4.0
void arv_camera_set_chunk_mode (ArvCamera *camera
,gboolean is_active
);
Controls wether chunk data mode is active. When active, chunk data are appended to image data in ArvBuffer. A ArvChunkParser must be used in order to extract chunk data.
Since: 0.4.0
void arv_camera_set_chunk_state (ArvCamera *camera
,const char *chunk
,gboolean is_enabled
);
Sets state of a chunk data. Chunk data are be embedded in ArvBuffer only
if chunk mode is active. Please see arv_camera_set_chunk_mode()
.
Since: 0.4.0
void arv_camera_set_chunks (ArvCamera *camera
,const char *chunk_list
);
Convenience function for enabling a set of chunk data. Chunk mode is activated, or deactivated
if chunk_list
is NULL
or empty. All chunk data not listed are disabled.
Since: 0.4.0
ArvChunkParser *
arv_camera_create_chunk_parser (ArvCamera *camera
);
Creates a new ArvChunkParser object, used for the extraction of chunk data from ArvBuffer.
Since: 0.4.0
const char *
arv_acquisition_mode_to_string (ArvAcquisitionMode value
);
ArvAcquisitionMode
arv_acquisition_mode_from_string (const char *string
);
“device”
property“device” ArvDevice *
the device associated with this camera.
Flags: Read / Write / Construct Only