Technical Application Notes
Click an item to read from the list below.

Technical Application Notes


 

 

Getting Started with OpenCV

Subject

Technical Application Note (TAN2015011): Getting Started with OpenCV

10504

Applicable Products

  •  All FLIR machine vision cameras

Application Note Description

OpenCV is an open-source computer vision library that allows you to perform image processing on FLIR machine vision cameras. This application note provides information on how to install and use OpenCV in Visual Studio. OpenCV does not support machine vision standards such as USB3 Vision and GigE Vision, therefore it is not recommended to grab images using OpenCV functions. Instead, we recommend using FlyCapture 2 SDK or Spinnaker SDK to grab images and convert them to OpenCV images.

 

This document provides examples using OpenCV 2.4.6. It also applies to newer versions.

Preparing for Use

Before you use your camera, we recommend that you are aware of the following resources available from our Downloads page:

Getting Started Manual for the camera—provides information on installing components and software needed to run the camera.

Technical Reference for the camera—provides information on the camera’s specifications, features and operations, as well as imaging and acquisition controls.

Firmware updates—ensure you are using the most up-to-date firmware for the camera to take advantage of improvements and fixes.

Install OpenCV

This document describes the steps for OpenCV version 2.4.6, but it also applies to newer versions. For best results, download the latest version.

  1. Download the latest version of OpenCV from http://opencv.org/downloads.html.
  2. Extract OpenCV in C:\
  3. From the Start Menu, right-click on Computer and select Properties.
  4. In the System window left pane, click Advanced system settings.
  5. In the System Properties dialog, from the Advanced tab, click Environment Variables.
  6. From the System variables list, select the Variable called Path and click Edit.
  7. At the end of the Variable value field, enter
    ;C:\opencv\build\x64\vc10\bin
    For 32-bit OpenCV version, replace x64 with x86.
  8. Click OK.

Configure OpenCV in Visual Studio

Add OpenCV to Visual Studio projects to perform image processing. The steps below outline how to prepare the Visual Studio settings in order to use OpenCV with Spinnaker, FlyCapture, LadybugCapPro, or Triclops SDKs. The example used is for the FlyCapture2 SDK.

  1. Download and install the SDK, in this example FlyCapture2, available from http://www.ptgrey.com/support/downloads.
  2. Open one of the example source code solutions in Visual Studio. This document uses FlyCapture2Test with Visual Studio 2010 as an example.
  3. Ensure Debug is selected in the Solution Explorer’s configuration.
  4. Right-click on the project and select Build.
  5. Right-click on FlyCapture2Test and select Properties.
  6. In the Property Pages window, select VC++ Directories and from the Include Directories drop-down select Edit.
  7. Add C:\opencv\build\include and click OK.
  8. From the Property Pages window, from the Library Directories drop-down select Edit.
  9. Add C:\opencv\build\x64\vc10\lib and click OK.
    Note: For 32-bit systems, replace x64 with x86.
  10. From the Property Pages window, select Linker→Input, and from the Additional Dependencies drop-down select Edit.
  11. Add the following library files and click OK.
    opencv_calib3d246.lib
    opencv_contrib246.lib
    opencv_core246.lib
    opencv_features2d246.lib
    opencv_flann246.lib
    opencv_gpu246.lib
    opencv_highgui246.lib
    opencv_imgproc246.lib
    opencv_legacy246.lib
    opencv_ml246.lib
    opencv_nonfree246.lib
    opencv_objdetect246.lib
    opencv_photo246.lib
    opencv_stitching246.lib
    opencv_ts246.lib
    opencv_video246.lib
    opencv_videostab246.lib
    Note: If you are using a different OpenCV version, replace 246 with your version.
  12. Click OK to save all project settings.
  13. For FlyCapture: open FlyCapture2Test.cpp and add #include “cv.h.”
    For Spinnaker: open Spinnaker2CVMat.cpp and add #include "opencv2/highgui/highgui.hpp" and "opencv2/imgproc/imgproc.hpp".

You can now add you own OpenCV code in FlyCapture2Test.cpp or Spinnaker2CVMat.cpp.

Sample Code for OpenCV

These examples demonstrate how to convert images from FlyCapture, FlyCapture2, and Triclops to OpenCV images.

FlyCapture

FlyCap_to_IplImage.cpp provides the function to convert from FlyCaptureImage to IplImage.

Applicable: All FLIR machine vision cameras except Gazelle and Cricket.

FlyCapture2

FlyCap2_to_IplImage.cpp provides the function to grab images from your camera and convert them to IplImage using FlyCapture2 SDK.

FlyCap2_to_MatImage.cpp provides the function to grab images from your camera and convert them to Mat Image using FlyCapture2 SDK.

Applicable: All FLIR machine vision cameras except Gazelle and Cricket.

Triclops

Triclops_to_IplImage.cpp provides the function to convert from TriclopsImage to IplImage.

Applicable: All FLIR Stereo cameras.

Ladybug

FC2_Ladybug_Image_to_IplImage.cpp provides the function to convert uncompressed Ladybug images.

Applicable: Ladybug cameras

Spinnaker

Spinnaker2CVMat.cpp map the Spinnaker ImagePtr calss to OpenCV Mat container. The OpenCV version tested was 2.4.13 which has the same configuration file with dll extensions 2413. Note that imageptr to getData() method returns padding which must be taken into account when dumping data into a Mat container so the container does not overflow.

Applicable: All FLIR machine vision USB3 Vision cameras