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.
- 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.
- Extract your OpenCV download to your desired location. These steps will assume the files get extracted to C:\opencv.
- Install CMake for Windows. The latest version can be found on the CMake website.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
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.
GenApi::INodeMap *pNodeMap = pDevice->GetNodeMap();
gcstring windowName = Arena::GetNodeValue
(pNodeMap, "DeviceModelName") + " (" + Arena::GetNodeValue (pNodeMap, "DeviceSerialNumber") + ")";
int framesPerSecond = (int)Arena::GetNodeValue
int numberOfSeconds = 10;
GenApi::CFloatPtr pExposureTimeNode = pNodeMap->GetNode("ExposureTime");
const int64_t getImageTimeout_ms = static_cast
(pExposureTimeNode->GetMax() / 1000 * 2);
std::cout << "Starting stream." << std::endl;
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());
// Stop stream
std::cout << "Stopping stream." << std::endl;
For the above code, the libraries to link are opencv_core and opencv_highgui in Linker → Input → Additional Dependencies.