Newbie help/tutorials?

Thanks for a great project, have managed to compile and get it see my GigE camera. I’ve played around with the example programs, all seem to expected, is there one that acquires a frame and saves to file? The zip one looks like it might, but it didnt seem to output a file?

Any plans for a tutorial? Documentation is extensive ut as a new user, struggling to work out which functions I need to string together to open a GigE camera source, trigger and save the frame to file. Any help much appreciated or pointers to relevant example programs.

Welcome here !

The example closest to what you need is tests/arvacquisitiontest.c . It acquires a single image, but does not save the result. Saving the buffer is just a matter of using g_file_set_contents:

But note that data in the buffer are raw pixel values, it is not in an image format like png, jpeg or whatever. If you want to generate a file that can be opened using an image editing tool like GIMP, you will have to use a third party API.

Another possibility is to build a GStreamer pipeline. In GStreamer, you will find all the elements needed to convert the aravis buffer to an image file.

There is plenty of plans, but a limited amount of free time :slight_smile:

Any contribution in improving the documentation is welcome.


Thanks for the speedy response, will give it a go, hopefully once I’ve mastered it, might be able to contribute to a short tutorial. Thanks again.

Thanks for the pointers, I’ve managed to write a simple program to acquire a test image. Needs more work to refine, but positing here, just in case it helps others. Uses Aravis Save PNG

    #include <png.h> // Requires libpng1.2
    #include <assert.h>
    #include <arv.h>
    #include <stdlib.h>
    #include <stdio.h>

    void arv_save_png(ArvBuffer * buffer, const char * filename);

    int main (int argc, char **argv)
            ArvCamera *camera;
            ArvBuffer *buffer;

            camera = arv_camera_new (argc > 1 ? argv[1] : NULL);
            buffer = arv_camera_acquisition (camera, 0);

            if (ARV_IS_BUFFER (buffer)){
                    printf ("Image successfully acquired\n");
                    FILE * fp;
                    fp=fopen("/home/pi/test.png", "r");
                    arv_save_png(buffer, "test.png");
                    printf ("Failed to acquire a single image\n");
            g_clear_object (&camera);
            g_clear_object (&buffer);

            return EXIT_SUCCESS;

    void arv_save_png(ArvBuffer * buffer, const char * filename)
            // TODO: This only works on image buffers
            assert(arv_buffer_get_payload_type(buffer) == ARV_BUFFER_PAYLOAD_TYPE_IMAGE);

            size_t buffer_size;
            char * buffer_data = (char*)arv_buffer_get_data(buffer, &buffer_size); // raw data
            int width;
            int height;
            arv_buffer_get_image_region(buffer, NULL, NULL, &width, &height); // get width/height
            int bit_depth = ARV_PIXEL_FORMAT_BIT_PER_PIXEL(arv_buffer_get_image_pixel_format(buffer)); // bit(s) per pixel
            //TODO: Deal with non-png compliant pixel formats?
            // EG: ARV_PIXEL_FORMAT_MONO_14 is 14 bits per pixel, so conversion to PNG loses data

            int arv_row_stride = width * bit_depth/8; // bytes per row, for constructing row pointers
            int color_type = PNG_COLOR_TYPE_GRAY; //TODO: Check for other types?

            // boilerplate libpng stuff without error checking (setjmp? Seriously? How many kittens have to die?)
            png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
            png_infop info_ptr = png_create_info_struct(png_ptr);
            FILE * f = fopen(filename, "wb");
            png_init_io(png_ptr, f);
            png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type,
            png_write_info(png_ptr, info_ptr);

            // Need to create pointers to each row of pixels for libpng
            png_bytepp rows = (png_bytepp)(png_malloc(png_ptr, height*sizeof(png_bytep)));
            int i =0;
            for (i = 0; i < height; ++i)
                    rows[i] = (png_bytep)(buffer_data + (height - i)*arv_row_stride);
            // Actually write image
            png_write_image(png_ptr, rows);
            png_write_end(png_ptr, NULL); // cleanup
            png_free(png_ptr, rows);
            png_destroy_write_struct(&png_ptr, &info_ptr);

Compile with (this bit confused me) on RPi 4

sudo gcc -I/home/pi/aravis-0.6.4/src -I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/ -L/home/pi/aravis-0.6.4/src/.libs/ -laravis-0.6 -lglib-2.0 -lgobject-2.0 -lpng save-png.c -o save-png3