Merge pull request #20363 from SentToDevNull:master

Updated To Modern Version of Aravis USB 3 Vision Protocol Library

* updated aravis backend to support aravis-0.8

* bugfix for aravis-0.8 support
pull/21451/head
Lukas Yoder 3 years ago committed by GitHub
parent 8768a80242
commit 9592537840
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      modules/videoio/cmake/detect_aravis.cmake
  2. 82
      modules/videoio/src/cap_aravis.cpp

@ -1,6 +1,6 @@
# --- Aravis SDK --- # --- Aravis SDK ---
if(NOT HAVE_ARAVIS_API AND PKG_CONFIG_FOUND) if(NOT HAVE_ARAVIS_API AND PKG_CONFIG_FOUND)
ocv_check_modules(ARAVIS aravis-0.6 QUIET) ocv_check_modules(ARAVIS aravis-0.8 QUIET)
if(ARAVIS_FOUND) if(ARAVIS_FOUND)
set(HAVE_ARAVIS_API TRUE) set(HAVE_ARAVIS_API TRUE)
endif() endif()
@ -9,9 +9,9 @@ endif()
if(NOT HAVE_ARAVIS_API) if(NOT HAVE_ARAVIS_API)
find_path(ARAVIS_INCLUDE "arv.h" find_path(ARAVIS_INCLUDE "arv.h"
PATHS "${ARAVIS_ROOT}" ENV ARAVIS_ROOT PATHS "${ARAVIS_ROOT}" ENV ARAVIS_ROOT
PATH_SUFFIXES "include/aravis-0.6" PATH_SUFFIXES "include/aravis-0.8"
NO_DEFAULT_PATH) NO_DEFAULT_PATH)
find_library(ARAVIS_LIBRARY "aravis-0.6" find_library(ARAVIS_LIBRARY "aravis-0.8"
PATHS "${ARAVIS_ROOT}" ENV ARAVIS_ROOT PATHS "${ARAVIS_ROOT}" ENV ARAVIS_ROOT
PATH_SUFFIXES "lib" PATH_SUFFIXES "lib"
NO_DEFAULT_PATH) NO_DEFAULT_PATH)

@ -51,8 +51,8 @@
#include <arv.h> #include <arv.h>
// //
// This file provides wrapper for using Aravis SDK library to access GigE Vision cameras. // This file provides wrapper for using Aravis SDK library to access GigE and USB 3 Vision cameras.
// Aravis library (version 0.4 or 0.6) shall be installed else this code will not be included in build. // Aravis library (version 0.8) shall be installed else this code will not be included in build.
// //
// To include this module invoke cmake with -DWITH_ARAVIS=ON // To include this module invoke cmake with -DWITH_ARAVIS=ON
// //
@ -151,10 +151,6 @@ protected:
bool softwareTriggered; // Flag if the camera is software triggered bool softwareTriggered; // Flag if the camera is software triggered
bool allowAutoTrigger; // Flag that user allowed to trigger software triggered cameras automatically bool allowAutoTrigger; // Flag that user allowed to trigger software triggered cameras automatically
gint64 *pixelFormats;
guint pixelFormatsCnt;
int num_buffers; // number of payload transmission buffers int num_buffers; // number of payload transmission buffers
ArvPixelFormat pixelFormat; // pixel format ArvPixelFormat pixelFormat; // pixel format
@ -225,7 +221,7 @@ bool CvCaptureCAM_Aravis::create( int index )
if(!getDeviceNameById(index, deviceName)) if(!getDeviceNameById(index, deviceName))
return false; return false;
return NULL != (camera = arv_camera_new(deviceName.c_str())); return NULL != (camera = arv_camera_new(deviceName.c_str(), NULL));
} }
bool CvCaptureCAM_Aravis::init_buffers() bool CvCaptureCAM_Aravis::init_buffers()
@ -234,7 +230,7 @@ bool CvCaptureCAM_Aravis::init_buffers()
g_object_unref(stream); g_object_unref(stream);
stream = NULL; stream = NULL;
} }
if( (stream = arv_camera_create_stream(camera, NULL, NULL)) ) { if( (stream = arv_camera_create_stream(camera, NULL, NULL, NULL)) ) {
if( arv_camera_is_gv_device(camera) ) { if( arv_camera_is_gv_device(camera) ) {
g_object_set(stream, g_object_set(stream,
"socket-buffer", ARV_GV_STREAM_SOCKET_BUFFER_AUTO, "socket-buffer", ARV_GV_STREAM_SOCKET_BUFFER_AUTO,
@ -245,7 +241,7 @@ bool CvCaptureCAM_Aravis::init_buffers()
"packet-timeout", (unsigned) 40000, "packet-timeout", (unsigned) 40000,
"frame-retention", (unsigned) 200000, NULL); "frame-retention", (unsigned) 200000, NULL);
} }
payload = arv_camera_get_payload (camera); payload = arv_camera_get_payload (camera, NULL);
for (int i = 0; i < num_buffers; i++) for (int i = 0; i < num_buffers; i++)
arv_stream_push_buffer(stream, arv_buffer_new(payload, NULL)); arv_stream_push_buffer(stream, arv_buffer_new(payload, NULL));
@ -260,25 +256,23 @@ bool CvCaptureCAM_Aravis::open( int index )
{ {
if(create(index)) { if(create(index)) {
// fetch properties bounds // fetch properties bounds
pixelFormats = arv_camera_get_available_pixel_formats(camera, &pixelFormatsCnt); arv_camera_get_width_bounds(camera, &widthMin, &widthMax, NULL);
arv_camera_get_height_bounds(camera, &heightMin, &heightMax, NULL);
arv_camera_get_width_bounds(camera, &widthMin, &widthMax); arv_camera_set_region(camera, 0, 0, widthMax, heightMax, NULL);
arv_camera_get_height_bounds(camera, &heightMin, &heightMax);
arv_camera_set_region(camera, 0, 0, widthMax, heightMax);
if( (fpsAvailable = arv_camera_is_frame_rate_available(camera)) ) if( (fpsAvailable = arv_camera_is_frame_rate_available(camera, NULL)) )
arv_camera_get_frame_rate_bounds(camera, &fpsMin, &fpsMax); arv_camera_get_frame_rate_bounds(camera, &fpsMin, &fpsMax, NULL);
if( (gainAvailable = arv_camera_is_gain_available(camera)) ) if( (gainAvailable = arv_camera_is_gain_available(camera, NULL)) )
arv_camera_get_gain_bounds (camera, &gainMin, &gainMax); arv_camera_get_gain_bounds (camera, &gainMin, &gainMax, NULL);
if( (exposureAvailable = arv_camera_is_exposure_time_available(camera)) ) if( (exposureAvailable = arv_camera_is_exposure_time_available(camera, NULL)) )
arv_camera_get_exposure_time_bounds (camera, &exposureMin, &exposureMax); arv_camera_get_exposure_time_bounds (camera, &exposureMin, &exposureMax, NULL);
// get initial values // get initial values
pixelFormat = arv_camera_get_pixel_format(camera); pixelFormat = arv_camera_get_pixel_format(camera, NULL);
exposure = exposureAvailable ? arv_camera_get_exposure_time(camera) : 0; exposure = exposureAvailable ? arv_camera_get_exposure_time(camera, NULL) : 0;
gain = gainAvailable ? arv_camera_get_gain(camera) : 0; gain = gainAvailable ? arv_camera_get_gain(camera, NULL) : 0;
fps = arv_camera_get_frame_rate(camera); fps = arv_camera_get_frame_rate(camera, NULL);
softwareTriggered = (strcmp(arv_camera_get_trigger_source(camera), "Software") == 0); softwareTriggered = (strcmp(arv_camera_get_trigger_source(camera, NULL), "Software") == 0);
return startCapture(); return startCapture();
} }
@ -295,7 +289,7 @@ bool CvCaptureCAM_Aravis::grabFrame()
int max_tries = 10; int max_tries = 10;
int tries = 0; int tries = 0;
if (softwareTriggered && allowAutoTrigger) { if (softwareTriggered && allowAutoTrigger) {
arv_camera_software_trigger (camera); arv_camera_software_trigger (camera, NULL);
} }
for(; tries < max_tries; tries ++) { for(; tries < max_tries; tries ++) {
arv_buffer = arv_stream_timeout_pop_buffer (stream, 200000); arv_buffer = arv_stream_timeout_pop_buffer (stream, 200000);
@ -402,7 +396,7 @@ void CvCaptureCAM_Aravis::autoExposureControl(IplImage* image)
if( ng < gain ) { if( ng < gain ) {
// priority 1 - reduce gain // priority 1 - reduce gain
arv_camera_set_gain(camera, (gain = ng)); arv_camera_set_gain(camera, (gain = ng), NULL);
return; return;
} }
} }
@ -411,7 +405,7 @@ void CvCaptureCAM_Aravis::autoExposureControl(IplImage* image)
// priority 2 - control of exposure time // priority 2 - control of exposure time
if(std::fabs(exposure - ne) > 2) { if(std::fabs(exposure - ne) > 2) {
// we have not yet reach the max-e level // we have not yet reach the max-e level
arv_camera_set_exposure_time(camera, (exposure = ne) ); arv_camera_set_exposure_time(camera, (exposure = ne), NULL);
return; return;
} }
} }
@ -420,12 +414,12 @@ void CvCaptureCAM_Aravis::autoExposureControl(IplImage* image)
if(exposureAvailable) { if(exposureAvailable) {
// exposure at maximum - increase gain if possible // exposure at maximum - increase gain if possible
if(ng > gain && ng < gainMax && ne >= maxe) { if(ng > gain && ng < gainMax && ne >= maxe) {
arv_camera_set_gain(camera, (gain = ng)); arv_camera_set_gain(camera, (gain = ng), NULL);
return; return;
} }
} else { } else {
// priority 3 - increase gain // priority 3 - increase gain
arv_camera_set_gain(camera, (gain = ng)); arv_camera_set_gain(camera, (gain = ng), NULL);
return; return;
} }
} }
@ -435,7 +429,7 @@ void CvCaptureCAM_Aravis::autoExposureControl(IplImage* image)
if(gainAvailable && autoGain && exposureAvailable) { if(gainAvailable && autoGain && exposureAvailable) {
if(gain > gainMin && exposure < maxe) { if(gain > gainMin && exposure < maxe) {
exposure = CLIP( ne * 1.05, exposureMin, maxe); exposure = CLIP( ne * 1.05, exposureMin, maxe);
arv_camera_set_exposure_time(camera, exposure ); arv_camera_set_exposure_time(camera, exposure, NULL);
} }
} }
} }
@ -461,25 +455,25 @@ double CvCaptureCAM_Aravis::getProperty( int property_id ) const
case CV_CAP_PROP_EXPOSURE: case CV_CAP_PROP_EXPOSURE:
if(exposureAvailable) { if(exposureAvailable) {
/* exposure time in seconds, like 1/100 s */ /* exposure time in seconds, like 1/100 s */
return arv_camera_get_exposure_time(camera) / 1e6; return arv_camera_get_exposure_time(camera, NULL) / 1e6;
} }
break; break;
case CV_CAP_PROP_FPS: case CV_CAP_PROP_FPS:
if(fpsAvailable) { if(fpsAvailable) {
return arv_camera_get_frame_rate(camera); return arv_camera_get_frame_rate(camera, NULL);
} }
break; break;
case CV_CAP_PROP_GAIN: case CV_CAP_PROP_GAIN:
if(gainAvailable) { if(gainAvailable) {
return arv_camera_get_gain(camera); return arv_camera_get_gain(camera, NULL);
} }
break; break;
case CV_CAP_PROP_FOURCC: case CV_CAP_PROP_FOURCC:
{ {
ArvPixelFormat currFormat = arv_camera_get_pixel_format(camera); ArvPixelFormat currFormat = arv_camera_get_pixel_format(camera, NULL);
switch( currFormat ) { switch( currFormat ) {
case ARV_PIXEL_FORMAT_MONO_8: case ARV_PIXEL_FORMAT_MONO_8:
return MODE_Y800; return MODE_Y800;
@ -517,8 +511,8 @@ bool CvCaptureCAM_Aravis::setProperty( int property_id, double value )
case CV_CAP_PROP_AUTO_EXPOSURE: case CV_CAP_PROP_AUTO_EXPOSURE:
if(exposureAvailable || gainAvailable) { if(exposureAvailable || gainAvailable) {
if( (controlExposure = (bool)(int)value) ) { if( (controlExposure = (bool)(int)value) ) {
exposure = exposureAvailable ? arv_camera_get_exposure_time(camera) : 0; exposure = exposureAvailable ? arv_camera_get_exposure_time(camera, NULL) : 0;
gain = gainAvailable ? arv_camera_get_gain(camera) : 0; gain = gainAvailable ? arv_camera_get_gain(camera, NULL) : 0;
} }
} }
break; break;
@ -531,13 +525,13 @@ bool CvCaptureCAM_Aravis::setProperty( int property_id, double value )
/* exposure time in seconds, like 1/100 s */ /* exposure time in seconds, like 1/100 s */
value *= 1e6; // -> from s to us value *= 1e6; // -> from s to us
arv_camera_set_exposure_time(camera, exposure = CLIP(value, exposureMin, exposureMax)); arv_camera_set_exposure_time(camera, exposure = CLIP(value, exposureMin, exposureMax), NULL);
break; break;
} else return false; } else return false;
case CV_CAP_PROP_FPS: case CV_CAP_PROP_FPS:
if(fpsAvailable) { if(fpsAvailable) {
arv_camera_set_frame_rate(camera, fps = CLIP(value, fpsMin, fpsMax)); arv_camera_set_frame_rate(camera, fps = CLIP(value, fpsMin, fpsMax), NULL);
break; break;
} else return false; } else return false;
@ -546,7 +540,7 @@ bool CvCaptureCAM_Aravis::setProperty( int property_id, double value )
if ( (autoGain = (-1 == value) ) ) if ( (autoGain = (-1 == value) ) )
break; break;
arv_camera_set_gain(camera, gain = CLIP(value, gainMin, gainMax)); arv_camera_set_gain(camera, gain = CLIP(value, gainMin, gainMax), NULL);
break; break;
} else return false; } else return false;
@ -574,7 +568,7 @@ bool CvCaptureCAM_Aravis::setProperty( int property_id, double value )
} }
if(newFormat != pixelFormat) { if(newFormat != pixelFormat) {
stopCapture(); stopCapture();
arv_camera_set_pixel_format(camera, pixelFormat = newFormat); arv_camera_set_pixel_format(camera, pixelFormat = newFormat, NULL);
startCapture(); startCapture();
} }
} }
@ -606,7 +600,7 @@ bool CvCaptureCAM_Aravis::setProperty( int property_id, double value )
void CvCaptureCAM_Aravis::stopCapture() void CvCaptureCAM_Aravis::stopCapture()
{ {
arv_camera_stop_acquisition(camera); arv_camera_stop_acquisition(camera, NULL);
if(stream) { if(stream) {
g_object_unref(stream); g_object_unref(stream);
@ -617,8 +611,8 @@ void CvCaptureCAM_Aravis::stopCapture()
bool CvCaptureCAM_Aravis::startCapture() bool CvCaptureCAM_Aravis::startCapture()
{ {
if(init_buffers() ) { if(init_buffers() ) {
arv_camera_set_acquisition_mode(camera, ARV_ACQUISITION_MODE_CONTINUOUS); arv_camera_set_acquisition_mode(camera, ARV_ACQUISITION_MODE_CONTINUOUS, NULL);
arv_camera_start_acquisition(camera); arv_camera_start_acquisition(camera, NULL);
return true; return true;
} }

Loading…
Cancel
Save