Using OpenCV with Arena SDK on Windows

Using OpenCV with Arena SDK on Windows

OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. The following instructions describe how to configure Lucid Vision GigE cameras with OpenCV on Windows 10.

System Specifications

  • Windows 10 Pro 64-bit, version 1709, build 16299.64
  • OpenCV 3.4.0
  • CMake 3.10.2

Building the OpenCV Libraries using CMake and CMake GUI

The following steps illustrate building OpenCV with Microsoft Visual Studio 2015.

  1. Extract your OpenCV download to your desired location. These steps will assume the files get extracted to C:\opencv.
  2. Install CMake for Windows. The latest version can be found on the CMake website.
  3. Launch CMake from the Start Menu and Choose your source and build directories and click Configure. In this process, the source directory will be C:\opencv\sources\ and the build directory is C:\opencv\build.

opencv1-cmake-windows

  1. Select the Visual Studio 2015 compiler and click Finish to begin configuration for Visual Studio 2015. These steps will assume 64-bit libraries will be built.

opencv2-cmake-windows

  1. Choose the OpenCV components to be generated and click Generate. The default options will be used for this process. Additional components that may be desired if not already included are BUILD_EXAMPLES, BUILD_DOCS, and ENABLE_SOLUTION_FOLDERS.

The GigE Vision SDK that can be included with OpenCV in the WITH_GIGEAPI component is not compatible with cameras from LUCID Vision Labs.

  1. Open the generated Visual Studio 2015 solution file by clicking Open Project in CMake. You can also find this solution file in C:\opencv\build.
  2. Build the OpenCV libraries in Debug and Release This will place your OpenCV library files in C:\opencv\build\lib\ and your binary files in C:\opencv\build\bin.

After building the OpenCV solution in Debug and Release configurations, you can also build the INSTALL project which will collect all of the Release binaries and place them into the C::\opencv\build\install\ folder.

Using OpenCV

  1. Add the location of your OpenCV binaries to your system path. Using the steps in the previous section, the path is C:\opencv\build\bin\Debug\ for the Debug libraries and C:\opencv\build\bin\Release\ for the Release libraries.

opencv4-windows

  1. Add the location of your OpenCV include files to your Visual Studio project in C/C++ -> General -> Additional Include Directories. Using the steps in the previous section, the path is C:\opencv\build\include.

opencv5-windows

  1. Add the location and library files of the OpenCV libraries you used to your Visual Studio project in Linker → General → Additional Include Directories. Using the steps in the previous section, the path for a Debug project C:\opencv\build\lib\Debug\ and the path for a Release project is C:\opencv\build\lib\Release. This process will use a Debug configuration.

opencv windows vs2015 libraries directory

Example Code

The following C++ code demonstrates using Arena SDK to grab the image from the camera, converting the image to an OpenCV Mat, and displays the image for 10 seconds. This sample assumes the attached camera is imaging in Mono8 pixel format.

#include "opencv2\opencv.hpp"
#include "opencv2\highgui.hpp"

// [...]

GenApi::INodeMap *pNodeMap = pDevice->GetNodeMap();
GenICam::gcstring windowName = Arena::GetNodeValue<GenICam::gcstring>(pNodeMap, "DeviceModelName") + " (" + Arena::GetNodeValue(pNodeMap, "DeviceSerialNumber") + ")";

Arena::IImage *pImage;
cv::Mat img;

int framesPerSecond = (int)Arena::GetNodeValue<double>(pNodeMap, "AcquisitionFrameRate");
int numberOfSeconds = 10;

GenApi::CFloatPtr pExposureTimeNode = pNodeMap->GetNode("ExposureTime");
const int64_t getImageTimeout_ms = static_cast<int64_t>(pExposureTimeNode->GetMax() / 1000 * 2);

std::cout << "Starting stream." << std::endl;
pDevice->StartStream();

for (int i = 0; i < framesPerSecond * numberOfSeconds; i++)
{
	pImage = pDevice->GetImage(getImageTimeout_ms);
	img = cv::Mat((int)pImage->GetHeight(), (int)pImage->GetWidth(), CV_8UC1, (void *)pImage->GetData());

	cv::imshow(windowName.c_str(), img);
	cv::waitKey(1);
	pDevice->RequeueBuffer(pImage);
}
cv::destroyAllWindows();

// Stop stream
std::cout << "Stopping stream." << std::endl;
pDevice->StopStream();

For the above code, the libraries to link are opencv_core and opencv_highgui in Linker → Input → Additional Dependencies.

opencv7-windows

The opencv_imgproc library contains functions that can be used to demonstrate debayering images.