Table of contents
1. Introduction
- This blog is a continuation of the previous blog on cross-compiling harfbuzz, freetype, opencv (including WITH_QT) in Ubuntu, and porting it to the Linux development board . When cross-compiling opencv before, python support was not added, but the c++ version of opencv was cross-compiled.
- For python cross-compilation of the arm-linux development board, please refer to the blog: In ubuntu, based on the Qt platform, call the python file and cross-compile it to the embedded linux development board for running .
- Because opencv supported by python requires the numpy library. To cross-compile the python third-party library numpy, you can refer to the blog: Embedded Linux Development Board, cross-compile the python third-party library numpy through crossenv .
2. Compilation process
- First add BUILD_opencv_python3.
- Then add the relevant path of the cross-compiled python in cmake. The python version I cross-compiled here is python3.6. Pay attention to deleting the related paths of python2 that comes with cmake.
- Click the Configure button.
There is a problem here : python's Libraries and installation path are not recognized.
- Find the reason by reading CMakeLists.txt of python3 in opencv:
cd /home/book/opencvarm/opencv-4.5.5/modules/python/python3
vi CMakeLists.txt
Note : Instead of using PYTHON3_ INCLUDE_ DIR to add the python3 include path , you should use PYTHON3 INCLUDE PATH . So add PYTHON3 INCLUDE PATH.
- And for python3's lib
cd /home/book/opencvarm/opencv-4.5.5/modules/python
vi common.cmake
You can see that PYTHON3 LIBRARIES should be used instead of PYTHON3 LIBRARY . So add PYTHON3 LIBRARIES.
- Configure again and the recognition is successful.
-
In addition, the error /home/book/arm-python/bin/python3.6m: Exec format error will appear during make . Because the /bin/python3 executable file here is of arm architecture, but we are operating on ubuntu, it should be replaced by the python3 executable file of x86_64 architecture. So just change it to the python3 executable file on your ubuntu. To find the python3 path, use the command:
which python3
. -
result
cd /home/book/opencvarm/opencv-4.5.5/tmp/lib/python3.6/site-packages/cv2/python-3.6