opencv_contrib
opencv_contrib copied to clipboard
How can I cross compile OpenCV with freetype ?
- I have several target platforms to build for like in this list:
"compiler":[
"gcc",
"mips-linux-gnu-",
"arm-linux-gnueabihf-",
"aarch64-v01c01-linux-musl-",
"arm-buildroot-linux-uclibcgnueabi-"
],
- I did build freetype and harbuzz successfully with CMake and installed them to a specified directory like org-dev.
- My working directories is like:
/home
+ lance
+ work
+ opencv - tag 4.10 cloned from github
+ opencv_contrib - tag 4.10 cloned from github
+ freetype - version 2.13.0
+ harfbuzz - version 11.2.0
+ org-dev - binaries built to install to
+ mips-linux-gnu-gcc
├── bin
├── etc
├── include
├── lib
├── man
├── sbin
└── share
+ aarch64-v01c01-linux-musl-gcc
├── bin
├── etc
├── include
├── lib
├── man
├── sbin
└── share
+ arm-buildroot-linux-uclibcgnueabi-gcc
├── bin
├── etc
├── include
├── lib
├── man
├── sbin
└── share
- But when I configured opencv like the following, it failed to find freetype and harfbuzz:
mkdir build && cd build
COMPILER_PREFIX=arm-linux-gnueabihf-
INSTALL_PATH=../../org-dev/arm-linux-gnueabihf-gcc
BUILD_CONTRIB='
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules
-D BUILD_opencv_alphamat=OFF
-D BUILD_opencv_aruco=OFF
-D BUILD_opencv_bgsegm=OFF
-D BUILD_opencv_bioinspired=OFF
-D BUILD_opencv_ccalib=OFF
-D BUILD_opencv_cnn_3dobj=OFF
-D BUILD_opencv_cvv=OFF
-D BUILD_opencv_datasets=OFF
-D BUILD_opencv_dnn_objdetect=OFF
-D BUILD_opencv_dnn_superres=OFF
-D BUILD_opencv_dnns_easily_fooled=OFF
-D BUILD_opencv_dpm=OFF
-D BUILD_opencv_face=OFF
-D BUILD_opencv_freetype=ON
'
BUILD_WITH_FREETYPE="
-DFREETYPE_INCLUDE_DIRS=$INSTALL_PATH/include/freetype2
-DFREETYPE_LIBRARIES=$INSTALL_PATH/lib/libfreetype.a
-DHARFBUZZ_INCLUDE_DIRS=$INSTALL_PATH/include/harfbuzz
-DHARFBUZZ_LIBRARIES=$INSTALL_PATH/lib/libharfbuzz.so"
TOOLCHAIN_FILE=../platforms/linux/${COMPILER_PREFIX%-}.toolchain.cmake
cmake -DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH \
-DCMAKE_PREFIX_PATH=$INSTALL_PATH \
-DWITH_OPENNI2=ON \
-DWITH_GDAL=ON -DBUILD_EXAMPLES=OFF \
-DPYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 \
-DWITH_OPENCL=OFF -DBUILD_DOCS=OFF \
-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE} \
-DWITH_IPP=OFF \
-DWITH_CUDA=OFF \
${BUILD_CONTRIB} \
${BUILD_WITH_FREETYPE} ..
The output is like:
-- freetype2: NO
-- harfbuzz: NO
So, what's the problem? What should I set to let CMake know that I have freetype compiled? I know there seems a way to build with pre-built libraries from the official guide tutorial_crosscompile_with_multiarch. But is it possible to build from my sources since there are so many target platforms to build OpenCV for? Thanks!
As first, to ask something, it is better to ask at Q&A forum https://forum.opencv.org/ .
I did build freetype and harbuzz successfully with CMake and installed them to a specified directory like org-dev.
freetype module looks for freetype library and harfbuzz library in making Makefile process with CMake. There is no implementation for overriding the detected parameters.
Maybe you should add more definition parameters ( at your own risk ). See https://github.com/opencv/opencv_contrib/blob/4.x/modules/freetype/CMakeLists.txt
BUILD_WITH_FREETYPE="
+ -DFREETYPE_FOUND=ON
+ -DFREETYPE_VERSION=2.13.0
-DFREETYPE_INCLUDE_DIRS=$INSTALL_PATH/include/freetype2
-DFREETYPE_LIBRARIES=$INSTALL_PATH/lib/libfreetype.a
+ -DHARFBUZZ_FOUND=ON
+ -DHARFBUZZ_VERSION=11.2.0
-DHARFBUZZ_INCLUDE_DIRS=$INSTALL_PATH/include/harfbuzz
-DHARFBUZZ_LIBRARIES=$INSTALL_PATH/lib/libharfbuzz.so"
And it seems that static freetype library(libfreetype.a) is used. If necessary, you may add the external libraries which depended manually. ( Or it is better to build freetype library as shared library. )