You are here: Start » Usage Tips » Interfacing with Other Libraries

Interfacing with Other Libraries

Adaptive Vision Library contains the avl::Image class which represents an image. This article describes how to create an avl::Image object with raw data acquired from cameras, and how to convert it to image structures specific to other libraries.

Adaptive Vision Library provides a set of sample converters. To use it in your program you should include a specific header file which is available in Adaptive Vision Library include directory (e.g. AVLConverters/AVL_OpenCV.h). The list below presents all the available converters:

  • Euresys
  • MFC
  • MvAcquire
  • OpenCV
  • Pylon
  • QT
  • SynView

An example of using MFC converters can be found in the Adaptive Vision Library directory in My Documents (Examples\MFC Examples). Below is shown also an OpenCV converter example.

Example: Converting Between avl::Image and OpenCV Mat

It is also possible to convert avl::Image to image structures from common libraries. The example code snippets below show how to convert an avl::Image object to other structures.

#include <opencv2/opencv.hpp> 
#include "AVLConverters/AVL_OpenCV.h"

#include "AVL.h"

avl::Image inputImage, processedImage;
cv::Mat cvImage;

int thresholdValue, rotateAngle;

//image processing
void ProcessImage()
	avl::Image image1;
	avl::ThresholdImage( inputImage, atl::NIL, (float)thresholdValue, atl::NIL, 0.0, image1 );
	avl::RotateImage( image1, (float)rotateAngle, avl::RotationSizeMode::Fit, 
		avl::InterpolationMethod::Bilinear, false, processedImage );

// callback
void on_trackbar( int, void* )

	avl::AvlImageToCVMat_Linked( processedImage, cvImage );
	cv::imshow( "CV Result Window", cvImage );

int main( void )
	// Load AVL image
	avl::Image monoImage, rgbImage;
	avl::TestImage( TestImageId::Lena, rgbImage, monoImage );
	avl::DownsampleImage( monoImage, 1, inputImage );
	thresholdValue = 128;
	rotateAngle = 0;

	// Create OpenCV Gui
	cv::namedWindow("Settings Window", 1);
	cv::resizeWindow("Settings Window", 300, 80);
	cv::createTrackbar( "Threshold", "Settings Window", &thresholdValue, 255, on_trackbar );
	cv::createTrackbar( "Rotate", "Settings Window", &rotateAngle, 360, on_trackbar );

	// set trackbar
	on_trackbar(0, 0);

	return 0;

Example: avl::Image from pointer to image data

It is also possible to create an avl::Image object using a pointer to image data, without copying memory blocks. This, however, requires compatible memory representations of images and proper information about the image being created has to be provided.

The constructor shown below should be used for this operation:

Image::Image( int width, int height, int pitch, PlainType::Type type, int depth, void* data );

Please note that all of the XxxToXxx_Linked functions do not copy data and the user has to take care of freeing such data. See also the usage example in OpenCV converter above. Functions AvlImageToCVMat_Linked and CVMatToAvlImage_Linked do not copy data.

Displaying Images Directly on WinAPI/MFC Device Context (HDC)

For convenience, there is also a function that directly displays an image on a WinAPI device context (HDC). This function is defined in the header "AVLConverters/AVL_Winapi.h" as:

void DisplayImageHDC(HDC inHdc, avl::Image& inImage, float inZoomX = 1.0, float inZoomY = 1.0);

For sample program showing how to use this function, please refer to the official example in the "06 WinAPI tutorial" directory.

Previous: Usage Tips Next: Loading Adaptive Vision Studio Files (AVDATA)