Using OpenCV with Arena SDK on Linux
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 a Linux system.
- Ubuntu 18.04.1 64-bit, kernel 4.15.0-29-generic
- Arena SDK for Linux x64, v.0.1.23.0
- OpenCV 3.4.3
Install the following dependencies:
$ sudo apt-get install build-essential
$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install cmake-gui
Building the OpenCV Libraries using CMake and CMake GUI
The following steps illustrate downloading and building OpenCV.
- Download the latest version of OpenCV from https://opencv.org/releases.html
$ wget https://github.com/opencv/opencv/archive/3.4.3.zip
$ git clone https://github.com/opencv/opencv.git
$ git clone https://github.com/opencv/opencv_contrib.git
- Find your OpenCV download in your desired location. These steps will assume the files are located at /home/ubuntu/opencv.
- Launch CMake-GUI (e.x. type cmake-gui from the terminal), choose your source and build directories, and click Configure. In this process, the source directory will be /home/ubuntu/opencv and the build directory will be home/ubuntu/opencv/build
- Use the Unix Makefiles option in the CMakeSetup window and click Finish to begin configuration.
- 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.
- Navigate to /home/ubuntu/opencv/build directory. Build the OpenCV libraries with make:
$ make -j7
The above command allows make to runs 7 jobs in parallel.
- Install the OpenCV libraries:
$ sudo make install
$ sudo ldconfig
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 an 8-bit 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;
Remember to include /usr/local/include in your makefile and link the to the OpenCV libraries:
INCLUDE= -I../../../include/Arena \
LDFLAGS = -L../../../lib64 \
LIBS= -larena -lsave -lgentl -lopencv_core -lopencv_highgui $
- Using the above parameters, the OpenCV include files will be installed to /usr/local/include and the binaries will be installed to /usr/local.
- If you see the following message when attempting to run OpenCV-related display code: