在ubuntu中,交叉编译harfbuzz,freetype,opencv,并移植到arm开发板所遇到的问题
时间:1年前 阅读:5782
因为录像时要用到opencv在图像上输出中文,但是opencv不支持,需要编译额外的第三方模块,记录一下编译的时候遇到的问题
主要参考csdn上的一篇博客进行交叉编译的:https://blog.csdn.net/m0_43443861/article/details/128099511
这篇博客写的挺详细的,但是有一些问题,记录一下:
1:交叉编译libpng时遇到的问题:libpng.so: undefined reference to `png_do_expand_palette_neon_rgba'会有这个错误,编译opencv时也会遇到,修改方法如下:
找到libpng源码里的头文件pngpriv.h,第130行注释掉, 修改为131行,
/* # if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \ */ # if defined(PNG_ARM_NEON) && (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \ defined(PNG_ALIGNED_MEMORY_SUPPORTED) # define PNG_ARM_NEON_OPT 2 # else # define PNG_ARM_NEON_OPT 0 # endif #endif
2:下载opencv_contrib(https://github.com/opencv/opencv_contrib),把opencv_contrib/modules文件夹下的freetype文件夹复制到opencv-4.5.4/modules文件夹下,
修改opencv-4.5.4/modules/freetype文件夹下的CMakeLists.txt文件,修改如下:
set(the_description "FreeType module. It enables to draw strings with outlines and mono-bitmaps/gray-bitmaps.") if(APPLE_FRAMEWORK) ocv_module_disable(freetype) endif() ocv_check_modules(FREETYPE freetype2) ocv_check_modules(HARFBUZZ harfbuzz) #if(OPENCV_INITIAL_PASS) # if(NOT FREETYPE_FOUND) # message(STATUS "freetype2: NO") # else() # message(STATUS "freetype2: YES (ver ${FREETYPE_VERSION})") # endif() # if(NOT HARFBUZZ_FOUND) # message(STATUS "harfbuzz: NO") # else() # message(STATUS "harfbuzz: YES (ver ${HARFBUZZ_VERSION})") # endif() #endif() #if(FREETYPE_FOUND AND HARFBUZZ_FOUND) ocv_define_module(freetype opencv_core opencv_imgproc WRAP python) ocv_target_link_libraries(${the_module} ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES}) ocv_include_directories( ${FREETYPE_INCLUDE_DIRS} ${HARFBUZZ_INCLUDE_DIRS} ) #else() # ocv_module_disable(freetype) #endif()
如果不修改的话,无法编译freetype。
3:记录几个编译时的configure命令:
#第一次编译harfbuzz,不用g=freetype ./configure --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc --prefix=/home/shiqi/opencv/acvins --with-freetype=no --with-icu=yes --with-cairo=no --with-fontconfig=yes --with-glib=no CPPFLAGS=-I/home/shiqi/opencv/acvins/include LDFLAGS=-L/home/shiqi/opencv/acvins/lib
#编译freetype,用到harfbuzz ./configure CC=arm-linux-gnueabihf-gcc --host=arm-linux-gnueabihf --with-zlib=yes --with-bzip2=yes --with-png=yes --with-harfbuzz=yes ZLIB_CFLAGS=-I/home/shiqi/opencv/acvins/include ZLIB_LIBS=-L/home/shiqi/opencv/acvins/lib BZIP2_CFLAGS=-I/home/shiqi/opencv/acvins/include BZIP2_LIBS=-L/home/shiqi/opencv/acvins/lib LIBPNG_CFLAGS=-I/home/shiqi/opencv/acvins/include LIBPNG_LIBS=-L/home/shiqi/opencv/acvins/lib HARFBUZZ_CFLAGS=-I/home/shiqi/opencv/acvins/include/harfbuzz HARFBUZZ_LIBS=-L/home/shiqi/opencv/acvins/lib --prefix=/home/shiqi/opencv/acvins
#第二次编译harfbuzz,用到freetype,因为他们相互依赖只好这样编译 ./configure --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc --prefix=/home/shiqi/opencv/acvins --with-freetype=yes --with-icu=yes --with-cairo=no --with-glib=no CPPFLAGS=-I/home/shiqi/opencv/acvins/include LDFLAGS=-L/home/shiqi/opencv/acvins/lib FREETYPE_CFLAGS=-I/home/shiqi/opencv/acvins/include/freetype2 FREETYPE_LIBS="-L/home/shiqi/opencv/acvins/lib -lfreetype -lbz2 -lz -lpng"
4:记录编译opencv-mobile的configure的命令:
cmake -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release `cat ../../opencv4_cmake_options.txt` -DBUILD_opencv_world=OFF -DFREETYPE_INCLUDE_DIRS=/home/shiqi/opencv/acvins/include/freetype2 -DFREETYPE_LIBRARIES=/home/shiqi/opencv/acvins/lib/libfreetype.a -DHARFBUZZ_INCLUDE_DIRS=/home/shiqi/opencv/acvins/include/harfbuzz -DHARFBUZZ_LIBRARIES=/home/shiqi/opencv/acvins/lib/libharfbuzz.so ..
加入了freetype和harfbuzz库依赖!
最后上一张编译好使用的图片:
微信扫码关注
更新实时通知
网友评论