OpenCv-freetype模块的编译(⽀持中⽂输出到图⽚)opencv的函数putText⽆法正确显⽰中⽂。⽤freetype模块可以加载字体,⽀持中⽂显⽰。
在opencv-contrib⾥模块有freetype,但是在window系统⾥直接⽤cmake编译,⽆法显⽰出freetype模块。
⽹上查询资料好多都在MAC和Linux上配置。查询了内外⽹,终于到⽅法,可以在Window上编译通过。
朋友们,如果没有编译成功,评论我把编译好的共享。
1.编译安装freetype
下载地址:
默认Configure,Generate,OpenProject.  需要⽣成Debug和Release. 记得ALL_BUILD后INSTALL.
系统变量添加变量FREETYPE_DIR,⽬录为C:/Program Files/freetype
2.编译安装harfbuzz
仓库地址:
初次Configure后,钩选HB_HAVE_FREETYE,再次Configure.
设置好如下值
系统变量添加变量HARFBUZZ_DIR,⽬录为C:/Program Files/harfbuzz
3.修改modules/
替换如下内容
set(the_description "FreeType module. It enables to draw strings with outlines and mono-bitmaps/gray-bitmaps.")
find_package(Freetype REQUIRED)
# find_package(HarfBuzz) is not included in cmake
set(HARFBUZZ_DIR "$ENV{HARFBUZZ_DIR}" CACHE PATH "HarfBuzz directory")
find_path(HARFBUZZ_INCLUDE_DIRS
NAMES hb-ft.h PATH_SUFFIXES harfbuzz
HINTS ${HARFBUZZ_DIR}/include)
find_library(HARFBUZZ_LIBRARIES
NAMES harfbuzz
include中文HINTS ${HARFBUZZ_DIR}/lib)
find_package_handle_standard_args(HARFBUZZ
DEFAULT_MSG HARFBUZZ_LIBRARIES HARFBUZZ_INCLUDE_DIRS)
if(NOT FREETYPE_FOUND)
message(STATUS "freetype2:  NO")
else()
message(STATUS "freetype2:  YES")
endif()
if(NOT HARFBUZZ_FOUND)
message(STATUS "harfbuzz:  NO")
else()
message(STATUS "harfbuzz:  YES")
endif()
if(FREETYPE_FOUND AND HARFBUZZ_FOUND)
ocv_define_module(freetype opencv_core opencv_imgproc PRIVATE_REQUIRED ${FREETYPE_LIB
RARIES} ${HARFBUZZ_LIBRARIES} WRAP python)  ocv_include_directories(${FREETYPE_INCLUDE_DIRS} ${HARFBUZZ_INCLUDE_DIRS})
else()
ocv_module_disable(freetype)
endif()
4.编译安装OpenCv
初次Configure后,选择contrib模块路径,同时把模块集合在opencv_world上,可以如下勾选。
再次Configure.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。