Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opencv] opencv_contrib won't compile Freetype module #5383

Closed
unbored opened this issue Feb 16, 2019 · 11 comments
Closed

[opencv] opencv_contrib won't compile Freetype module #5383

unbored opened this issue Feb 16, 2019 · 11 comments
Assignees
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@unbored
Copy link

unbored commented Feb 16, 2019

I've installed the two packages freetype and harfbuzz which Freetype module needs.

CMakeLists.txt in Freetype module wrotes:

if(PKG_CONFIG_FOUND)
  pkg_search_module(FREETYPE freetype2)
  pkg_search_module(HARFBUZZ harfbuzz)
endif()

It won't find freetype and harfbuzz since pkg_config doesn't exist in Windows. If I change the code to what vcpkg indicated:

find_package(Freetype REQUIRED)
find_package(harfbuzz CONFIG REQUIRED)

it does find freetype, but harfbuzz is still missing.

@Cheney-W
Copy link
Contributor

I have tested this issue with vcpkg 2018.11.23-nohash and VS2017 15.9.9, I could find these two ports with following sentences in cmake project:
find_package(Freetype REQUIRED)
find_package(harfbuzz CONFIG REQUIRED)
I think this issue should be fixed, so close this issue.
If you could reproduce this issue in your side, please contact me again and provide a detailed repro steps.

@unbored
Copy link
Author

unbored commented Mar 28, 2019

I have tested this issue with vcpkg 2018.11.23-nohash and VS2017 15.9.9, I could find these two ports with following sentences in cmake project:
find_package(Freetype REQUIRED)
find_package(harfbuzz CONFIG REQUIRED)
I think this issue should be fixed, so close this issue.
If you could reproduce this issue in your side, please contact me again and provide a detailed repro steps.

@Cheney-W I don't mean that the cmake project can't find the two ports, I mean that OpenCV can't recognize the harfbuzz found.

@gansm255
Copy link

Hi,
Freetype and hdf libraries are not built in my configuration. I use opencv 3.4.1 and opencv_contrib 3.4.1. Please guide me how to enable these two modules. which files i have to change. Thanks and regards, Murugan

@gansm255
Copy link

i develop in cygwin for cross development to target aarch64-unknown-linux-gnu.

@Cheney-W Cheney-W reopened this Jun 30, 2020
@Cheney-W Cheney-W self-assigned this Jun 30, 2020
@Cheney-W Cheney-W added the category:port-bug The issue is with a library, which is something the port should already support label Jun 30, 2020
@Cheney-W
Copy link
Contributor

@unbored About harfbuzz can't find in OpenCV, please use harfbuzz_FOUND instead of HARFBUZZ_FOUND in the CMakeLists.txt of freetype.

@gansm255 Since the version of opencv3 currently provided by vcpkg is 3.4.7, are you using vcpkg to install opencv?

@gansm255
Copy link

gansm255 commented Jul 1, 2020

Hi,
Thanks for immediate help.

  1. I am not using vcpkg. I download source 4.2.0 and build under cygwin and cross compile with compiler aarch64-unknown-linux-gnu-g++.
  2. also i need to enable freetype.
  3. in your yesterday comment, you have mentioned to use harfbuzz_FOUND instead of HARBUZZ_FOUND in the CMakeList.txt file under freetype folder. This change does not make any difference.
  4. the issue is freetype and harfbuzz modules are not found ocv_check_modules .

@Cheney-W
Copy link
Contributor

Cheney-W commented Jul 2, 2020

@gansm255 I think you could submit an issue on https://github.com/opencv/opencv_contrib/issues .

@ivanshilo
Copy link

ivanshilo commented Jul 29, 2021

I have spent quite a lot of time to find this:
in ports\opencv4\portfile.cmake it will activate freetype module only if ask for opencv4[ovis] feature.
if(BUILD_opencv_ovis) string(APPEND DEPS_STRING "\nfind_dependency(Ogre)\nfind_dependency(Freetype)") endif()

This is unfortunate because [ovis] brings a lot of other libraries as dependecies which I absolutely do not need.

UPDATE
After a bit more research it turns out that ovis feature is not enough/not necessary to activate freetype.
It does not work because of incorrect package search command.
It is not directly related to vcpkg, similar issue is opened at [opencv_contrib] github itself.
opencv/opencv_contrib#1497

Seems that nobody there cares that under windows freetype is not available.
Unofficial "patches" were issued, read
https://gist.github.com/UnaNancyOwen/14c72a3f10a46d41c359ab6ea307a1d2#file-readme-md

So far exisiting workarounds are not good enough for vcpkg.
Vcpkg will overwrite any manual changes to cmake files when user starts build/upgrade.
Therefore the only way is to create a patch for cmake file and register patch in ports\opencv4\portfile.cmake file. Then if it works, to create a pull request.

@JonLiu1993 JonLiu1993 added depends:upstream-changes Waiting on a change to the upstream project and removed depends:upstream-changes Waiting on a change to the upstream project labels Jan 27, 2022
@JonLiu1993
Copy link
Member

JonLiu1993 commented Jan 27, 2022

@unbored , Thanks for posting this issue, Can you try this workaround?

the issue is in:

opencv_contrib/modules/freetype/CMakeLists.txt

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
    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_LIBRARIES} ${HARFBUZZ_LIBRARIES} WRAP python)
  ocv_include_directories(${FREETYPE_INCLUDE_DIRS} ${HARFBUZZ_INCLUDE_DIRS})
else()
  ocv_module_disable(freetype)
endif()

@netcorefan1
Copy link

netcorefan1 commented Mar 8, 2023

Someone could tell me what is the right patch for Windows? I opened an issue and I've been told that I need to do some modifications. This issue seems to reappear over the years and very difficult to fix from vcpkg side in a reliable way, therefore I'm afraid I'm better off to patch opencv_contrib/modules/freetype/CMakeLists.txt.

In the workaround link posted from @JonLiu1993 there are two versions. The main one (the one just above the pic) does not work. When applied I get plenty of warnings and versions are not detected (seems there is also some duplicated stuff to mess up things):

-- Found Freetype: optimized;C:/dev/vcpkg/installed/x64-windows/lib/freetype.lib;debug;C:/dev/vcpkg/installed/x64-windows/debug/lib/freetyped.lib (found version "2.12.1")
-- Found HARFBUZZ: C:/dev/vcpkg/installed/x64-windows/lib/harfbuzz.lib
-- freetype2:   YES
-- harfbuzz:   YES
-- Julia not found. Not compiling Julia Bindings.
-- Module opencv_ovis disabled because OGRE3D was not found
-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
-- Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
-- Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
-- Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
-- Tesseract:   YES (ver 5.3.0)
-- Module opencv_python3 disabled because opencv_python_bindings_generator dependency can't be resolved!
-- Assume that non-module dependency is available: optimized (for module opencv_freetype)
-- Assume that non-module dependency is available: debug (for module opencv_freetype)
-- Assume that non-module dependency is available: optimized (for module opencv_freetype)
-- Assume that non-module dependency is available: debug (for module opencv_freetype)
-- Allocator metrics storage type: 'long long'
-- Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': C:/dev/OpenCv/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- opencv_dnn: filter out cuda4dnn source code
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp
-- freetype2:   YES
-- harfbuzz:   YES
CMake Warning at cmake/OpenCVUtils.cmake:1699 (message):
  Unexpected CMake generator expression:
  $<$<NOT:$<CONFIG:DEBUG>>:C:/dev/vcpkg/installed/x64-windows/lib/freetype.lib>
Call Stack (most recent call first):
  CMakeLists.txt:1186 (ocv_get_all_libs)


CMake Warning at cmake/OpenCVUtils.cmake:1699 (message):
  Unexpected CMake generator expression:
  $<$<CONFIG:DEBUG>:C:/dev/vcpkg/installed/x64-windows/debug/lib/freetyped.lib>
Call Stack (most recent call first):
  CMakeLists.txt:1186 (ocv_get_all_libs)


CMake Warning at cmake/OpenCVUtils.cmake:1699 (message):
  Unexpected CMake generator expression:
  $<$<NOT:$<CONFIG:DEBUG>>:C:/dev/vcpkg/installed/x64-windows/lib/freetype.lib>
Call Stack (most recent call first):
  CMakeLists.txt:1186 (ocv_get_all_libs)


CMake Warning at cmake/OpenCVUtils.cmake:1699 (message):
  Unexpected CMake generator expression:
  $<$<CONFIG:DEBUG>:C:/dev/vcpkg/installed/x64-windows/debug/lib/freetyped.lib>
Call Stack (most recent call first):
  CMakeLists.txt:1186 (ocv_get_all_libs)

Below there is another one, but seems for Linux and although I don't get warnings when applied, harfbuzz is not even showed:

-- Module opencv_alphamat disabled because the following dependencies are not found: Eigen
-- Found Freetype: optimized;C:/dev/vcpkg/installed/x64-windows/lib/freetype.lib;debug;C:/dev/vcpkg/installed/x64-windows/debug/lib/freetyped.lib (found version "2.12.1")
-- Found HARFBUZZ: C:/dev/vcpkg/installed/x64-windows/lib/harfbuzz.lib
-- freetype2:   YES
-- Julia not found. Not compiling Julia Bindings.

The posted fixes are 7 years old. I would appreciate if someone could post a patch that remains reliable over the time with each new release.
I also tried the recent one posted here, but results are not encouraging:

-- Found ZLIB: zlib (found version "1.2.13")
-- freetype2:   YES (ver )
-- harfbuzz:    YES (ver )
-- Julia not found. Not compiling Julia Bindings.

@JonLiu1993
Copy link
Member

Fixed by PR #27343.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

No branches or pull requests

6 participants