-
Notifications
You must be signed in to change notification settings - Fork 18
OpenCV on Yocto Image
This page helps you to install OpenCV and compile an application on Yocto.
Add the packages necessary for OpenCV into the core-image-aesd.bb file. The opencv, libopencv-core and libopencv-imgproc are sufficient for running most OpenCV based applications.
IMAGE_INSTALL:append = " opencv libopencv-core libopencv-imgproc"
The OpenCV application will vary based on your final project. An example implementation for the project at MotionSense can be found at opencv_application_code with recipe at recipe. This application is designed to accept video feed from Gstreamer and run a motion detection algorithm by finding the difference between video frames. The application also pushes a messsage using MQTT to a Mosquitto Broker.
The steps below outline the changes to build your custom Yocto OpenCV application.
- Yocto requires package config within the recipe to be able to successfully compile the OpenCV application. Add this using the
inherit
,DEPENDS
andRDEPENDS_${PN}
variables. Include any otherRDEPENDS
libraries as you seem fit based on your application.
inherit pkgconfig
DEPENDS = "pkgconfig opencv"
RDEPENDS_${PN} = "libopencv-core libopencv-imgproc libopencv-highgui libopencv-videoio libopencv-imgcodecs libopencv-gapi"
- Add the Target LDFLAGS required for the compilation of your program into the recipe.
TARGET_LDFLAGS += "-pthread -lrt -L/usr/lib -lopencv_core -lopencv_flann -lopencv_video -lrt -lstdc++fs -lstdc++ -lopencv_gapi"
- Modify do_compile section of the recipe to use pkg config to add the required libraries for compilation.
do_compile () {
${CXX} ${CXXFLAGS} ${LDFLAGS} ${S}/aesd_opencv_file.cpp `pkg-config --cflags opencv4` `pkg-config --libs opencv4` -o aesd_opencv_file
}
The installation of OpenCV on the target for the built Yocto image was tested using print(cv2.__version__)
.
The aesd_opencv_file was tested to run on Raspberry Pi 3B+ on the built Yocto Image.