[aravis] compiling an example program

  • From: Sol Pedre <solpedre@xxxxxxxxx>
  • To: aravis@xxxxxxxxxxxxx
  • Date: Thu, 10 Apr 2014 15:19:06 -0300

Hello,

I have succesfully installed aravis and used the arv-viewer to see the
input from a DFK 23GM021 The Imaging Source Gige camera.

Now I am trying to use this camera from a C/C++ code that process images.
To start, i am reading the aravis reference manual, and i am trying to
compile the example in the ArvCamera reference page (I paste it below).

However, i am finding several errors, i guess i am missing some library
bindings and others. The first two errors are:

Invalid arguments ' Candidates are: void arv_camera_set_region(_ArvCamera
*, ?, ?, ?, ?)

and

Invalid arguments '
Candidates are: void arv_stream_set_emit_signals(_ArvStream *, ?)


These both functions take gint as parameters, and the code passes gint, but
it does not work.

Please tell me which libraries i should be linking with and where they
should be, and also any light you can shed in those errors...

Thank you very much!!
Sol


---------------

Code:


#include <arv.h>
#include <glib.h>
#include <glib-object.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 (buffer->status == 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 = (ApplicationData*)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;
    ArvBuffer *buffer;
    int i;

    data.buffer_count = 0;

    /* Mandatory glib type system initialization */
    //arv_g_type_init();
    g_type_init();
    /* Instantiation of the first available camera */
    camera = arv_camera_new (NULL);

    if (camera != NULL) {
        void (*old_sigint_handler)(int);
        gint payload;
        guint software_trigger_source = 0;

        /* Set region of interrest to a 200x200 pixel area */
        arv_camera_set_region(camera, (gint)0, (gint)0, (gint)200,
(gint)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;
}

Other related posts: