HomeSupportVision Libraries → MathWorks MATLAB

MathWorks MATLAB

Overview

MathWorks® is the leading developer and supplier of software for technical computing and Model-Based Design.
The MATLAB® product family provides a flexible environment for solving complex imaging problems in a wide range of applications including scientific imaging, medicine and biotechnology, aerospace and defense, security, and machine vision.
Image Acquisition Toolbox™ enables users to acquire images and video directly from cameras into MATLAB and Simulink. Image Processing Toolbox™ and Computer Vision System Toolbox™ products provide algorithms and tools for building image processing, video processing, and computer vision applications.

Installation

Recent API Software Packages are fully supported and tested with Matlab versions released in the last 2 years. The backward compatibility has not been tested for all features and camera models in older Matlab versions.

Matlab R2014a and later

  1. Install Matlab software.
  2. Install the XIMEA API Software Package , which contains the XIMEA GeniCam GenTL Producer.
    Note: Installation is not needed on products with pre-installed software packages
  3. Open Matlab and install the Genicam Interface according to the guide described on the Installing the Support Packages for Image Acquisition Toolbox Adaptors Mathworks support page.
  4. Restart PC.

Matlab R2012a to R2013b

  1. Install Matlab software.
  2. Install the XIMEA API Software Package , which contains the XIMEA GeniCam GenTL Producer.
    Note: Installation is not needed on products with pre-installed software packages
  3. Open Matlab and run the installgenicam.m file from the C:\Program Files\MATLAB\R2014a\toolbox\imaq\imaqextern folder.
  4. Restart PC.

Linux support

Besides the above steps, please
  • add "export GENICAM_GENTL64_PATH=/opt/XIMEA/lib/" to your ~/.bashrc file to enable GenTL
  • or run MATLAB every time by command:
    GENICAM_GENTL64_PATH=/opt/XIMEA/lib/ ./Matlab

macOS support

*The Mathworks Image Acquisition Toolbox Support Package for GenICam Interface is currently not compatible with the GenICam interface on macOS. As a result, XIMEA cameras cannot be used with MATLAB on macOS.
For more information or assistance, please contact MathWorks directly.

Setup

The Image Acquisition Tool is a graphical interface for rapid hardware configuration, image acquisition and live video previewing.
The preview window, as shown here, reflects adjustments made to the XIMEA camera properties and provides a quick start in the development of image processing systems.

Example

The toolbox has a comprehensive set of functions for command line programming of tasks such as device connection, image data acquisition, to adjust acquisition parameters and more.
The code below shows how to connect to a XIMEA camera to acquire data:

% Access an image acquisition device
vidobj = videoinput('gentl', 1, 'BGRA8Packed');
src=getselectedsource(vidobj);
src.AEAGEnable = 'True';
% List the video input object's configurable properties.vidobj.FramesPerTrigger = 50;
% Open the preview window
preview(vidobj);
% Data acquisition
start(vidobj);
stop(vidobj);
%  Cleanup the image acquisition object and the MATLAB® workspace delete(vidobj);
clear vidobj;

Documentation

Visit the Image Acquisition Toolbox support page.

The .NET support for MATLAB

Applications in Matlab can be also developed under our .NET interface.
Since xiAPI.NET supports multiple versions of the .NET SDK, you need to:
  1. copy xiApi64.dll (or xiApi32.dll for x86 systems) from \XIMEA\API\xiAPI to the folder of the .NET version you are using (e.g. to \XIMEA\API\xiAPI.NET.Framework.4.7.2)
  2. import the xiApi.NETX64.dll (xiApi.NET.dll for x86 systems) from the same folder into Matlab (e.g. from \XIMEA\API\xiAPI.NET.Framework.4.7.2 like in the following sample)

After importing the xiAPI.NET shared library you can implement an application with the xiAPI.NET API.

.NET example

Here is a xiAPI.NET example for Matlab. Path to xiApi.NET depends on what .NET version you are using.
More extensive sample showing work with RGB or 16-bit image formats can be downloaded here: xiAPINET_Matlab_sample.m.

imaqreset;
NET.addAssembly('C:\XIMEA\API\xiAPI.NET.Framework.4.7.2\xiApi.NETX64.dll');  % Path to the xiApi.NET library

myCam=xiApi.NET.xiCam;      % Initialize camera
OpenDevice(myCam,0);
myCam.SetParam(xiApi.NET.PRM.EXPOSURE ,10000);    % Set exposure time
myCam.SetParam(xiApi.NET.PRM.IMAGE_DATA_FORMAT, xiApi.NET.IMG_FORMAT.RAW8);     % Set image format

StartAcquisition(myCam);

H=myCam.GetParam(xiApi.NET.PRM.HEIGHT);
W=myCam.GetParam(xiApi.NET.PRM.WIDTH);

myCam.SetParam(xiApi.NET.PRM.BUFFER_POLICY , xiApi.NET.BUFF_POLICY.SAFE);
NetArray=NET.createArray('System.Byte',W*H);
GetImageByteArray(myCam,NetArray,1000);
img=transpose(reshape(uint8(NetArray),W,H));

% img is ready to process as MATLAB uint8 image matrix               
imshow(img);

StopAcquisition(myCam);
CloseDevice(myCam);
delete(myCam);
clear myCam;