Linux development board, when cross-compiling opencv, add python support

1. Introduction

  1. 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.
  2. 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 .
  3. 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

  1. First add BUILD_opencv_python3.

Insert image description here

  1. 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.

Insert image description here

  1. Click the Configure button.

Insert image description here

There is a problem here : python's Libraries and installation path are not recognized.

  1. 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

Insert image description here

Note : Instead of using PYTHON3_ INCLUDE_ DIR to add the python3 include path , you should use PYTHON3 INCLUDE PATH . So add PYTHON3 INCLUDE PATH.

Insert image description here

  1. And for python3's lib
cd /home/book/opencvarm/opencv-4.5.5/modules/python
vi common.cmake

Insert image description here

You can see that PYTHON3 LIBRARIES should be used instead of PYTHON3 LIBRARY . So add PYTHON3 LIBRARIES.

  1. Configure again and the recognition is successful.

Insert image description here

  1. 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.

  2. result

cd /home/book/opencvarm/opencv-4.5.5/tmp/lib/python3.6/site-packages/cv2/python-3.6

Insert image description here

Guess you like

Origin blog.csdn.net/m0_43443861/article/details/128637170