Opencv combination with Aravis

according to this

I try to render video real time on opencv window
I try following code by adding only std::cout<<buffer_size<<std::endl to above code

IplImage* Camera::readFrameIPL(){
   ArvBuffer* _buffer;
   IplImage* src;
   size_t buffer_size;
   // get buffer data
  _buffer = arv_stream_pop_buffer(stream);
  if (_buffer != NULL){
     // copy buffer data
     framebuffer = (void*)arv_buffer_get_data(_buffer, &buffer_size);
     std::cout<<buffer_size<<std::endl;/// i add this line
     arv_stream_push_buffer(stream, _buffer);
     // create IplImage
     src = cvCreateImage( cvSize(1280, 960), IPL_DEPTH_8U, 1);
     cvInitImageHeader(src, cvSize(1280, 960), IPL_DEPTH_8U, 1, IPL_ORIGIN_TL, 4);
     cvSetData(src, framebuffer, src->widthStep);
     return src;
 return NULL;

and on main use this

   IplImage* image;
   image = cam.readFrameIPL();
       cv::Mat matimage = cv::cvarrToMat(image,false);
      imshow("video",matimage );
       std::cout<<"error to read frame";

now i have some question

  1. on std::cout<<buffer_size<<std::endl in Camera::readFrameIPL() method
    print 5308416 continuously (2592 * 2048) that seems it is GreyScale because RGB should
    be(2592 * 2048 * 3) not 2592 * 2048 =5308416
  2. on Opencv window the full noisy image without any recognizable video content is shown continuously !!!
  3. why use this size cvSize(1280, 960) on output video


It looks like the code never try to ensure the OpenCV buffer is consistent with the content of the ArvBuffer.

Either you configure the camera to output an image with a known dimension and pixel format, or when you create on OpenCV image, you use the ArvBuffer properties in order to correctly initialize the OpenCV image.

Please refer to the Aravis 0.6 documentation here: and

i use your link
and copy and paste your Example use of the ArvCamera API code to my main i built it with g++ and its work fine
i know in avrviewer for bayertorgb you use Gstreamer instead of opencv but the avrviewer code (combination of aravis+gstreamer +gtk) is too complicate for me would you you please give me any help or link or everything to understand your develop avrviewer more easily.
best regards

Using opencv Bayer to rgb convert in new_buffer_cb is time consuming and lead to frame rate become 8 per second

I’m not sure how easier it could be. If you want to display a video, you have to deal with a toolkit, and a library that can convert from the camera pixel format to the display pixel format.

Is Bayer the only pixel format your device can stream ? Debayerisation will always be time consuming.

yes bayer is only format
i should try Debayerisation with cuda
thank you for response

Hi everyone,

First of all, thanks for this proyect. I have been working with the project for several months and now i’m doing it with Aravis 0.8 and I have a problem.
I try to use opencv combination with Aravis, and the problem is Meson. I have changed several files to work with the opencv library modifying then into .cpp files (several tests of basic opencv programs or even with arv-tool and it works well) but the problem is that I am not able to introduce this library to use it with the arv_viewer, changing the arvviewer.c to .cpp Meson produces a compilation error with GtkApplicationClass ArvViewerClass. I don’t know if the problem is Meson or C++ and my question is… Is there any way to work with opencv in a .c file or is it necessary to modify the in viewer and arvviewer.c to .cpp just like the other files to get it?



I’m no sure arvviewer can be compiled by a C++ compiler. I guess it would be better to have your own cpp file that binds the OpenCV C++ API you need to use.


Thanks for your quick response Emmanuel, I’ll try it with my own .cpp I hope to get the most out of the library with the Aravis project. I am going to try to load the OpenCv buffer in the ArvBuffer as it was discussed in a previous thread.