Skip to content

[OpenCV 4.x] Can't build OpenCV with python bindings w/o DNN module #27064

Closed

Description

@AsyaPronina

System Information

For C++ user of OpenCV 4.x, Platform: Windows 10

Detailed description

Hello Dear OpenCV developers!
Could I please ask your advise/knowledge on how to fix the following situation.

After given commit: ae25c31, opencv_video module begun to use opencv_dnn API under #ifdef clause.
However, it seems that Python bindings generator doesn't handle #ifdef clause and tries to generate bindings for newly introduced create(const dnn::Net&...) methods even if we build with -DBUILD_opencv_dnn=OFF

This ends up with following generator warning:

Traceback (most recent call last):
  File "C:\apronina\opencv\modules\python\src2\typing_stubs_generator.py", line 49, in wrapped_func
    ret_type = func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\apronina\opencv\modules\python\src2\typing_stubs_generator.py", line 148, in _generate
    generate_typing_stubs(self.cv_root, output_path)
  File "C:\apronina\opencv\modules\python\src2\typing_stubs_generation\generation.py", line 90, in generate_typing_stubs
    root.resolve_type_nodes()
  File "C:\apronina\opencv\modules\python\src2\typing_stubs_generation\nodes\namespace_node.py", line 106, in resolve_type_nodes
    raise TypeResolutionError(
typing_stubs_generation.nodes.type_node.TypeResolutionError: Failed to resolve "cv2" namespace against "None". Errors:
['Failed to resolve "cv2.TrackerGOTURN" class against "cv2". Errors: [\'Failed to resolve "cv2.TrackerGOTURN.create" function against "cv2".
Errors: [0]: Failed to resolve "model" argument: Failed to resolve "dnn_Net" exposed as "dnn_Net"\']',
'Failed to resolve "cv2.TrackerDaSiamRPN" class against "cv2". Errors:[\'Failed to resolve "cv2.TrackerDaSiamRPN.create" function against "cv2".
Errors: [0]: Failed to resolve "siam_rpn" argument: Failed to resolve "dnn_Net" exposed as "dnn_Net", [1]: Failed to resolve "kernel_cls1" argument:
Failed to resolve "dnn_Net" exposed as "dnn_Net", [2]: Failed to resolve "kernel_r1" argument: Failed to resolve "dnn_Net" exposed as "dnn_Net"\']',
'Failed to resolve "cv2.TrackerNano" class against "cv2". Errors: [\'Failed to resolve "cv2.TrackerNano.create" function against "cv2".
Errors: [0]: Failed to resolve "backbone" argument: Failed to resolve "dnn_Net" exposed as "dnn_Net", [1]: Failed to resolve "neckhead" argument:
Failed to resolve "dnn_Net" exposed as "dnn_Net"\']', 'Failed to resolve "cv2.TrackerVit" class against "cv2". Errors: [\'Failed to resolve
"cv2.TrackerVit.create" function against "cv2". Errors: [0]: Failed to resolve "model" argument: Failed to resolve "dnn_Net" exposed as "dnn_Net"\']']

Warning log shows that all resolutions failed starting from right these create(const dnn::Net&...) methods, that are tried to be resolved against dnn_Net (instead of dnn::Net, that should be generated with DNN module turned ON, as I understood).

Here is also log of the build error:

C:\apronina\opencv\build\modules\python_bindings_generator\pyopencv_generated_types_content.h(24899,5):
error C2065: 'dnn_Net': undeclared identifier [C:\apronina\opencv\build\modules\python3\opencv_python3.vcxproj]
C:\apronina\opencv\build\modules\python_bindings_generator\pyopencv_generated_types_content.h(24899,13):
error C2146: syntax error: missing ';' before identifier 'siam_rpn' [C:\apronina\opencv\build\modules\python3\opencv_python3.vcxproj]
C:\apronina\opencv\build\modules\python_bindings_generator\pyopencv_generated_types_content.h(24899,13):
error C2065: 'siam_rpn': undeclared identifier [C:\apronina\opencv\build\modules\python3\opencv_python3.vcxproj]
C:\apronina\opencv\build\modules\python_bindings_generator\pyopencv_generated_types_content.h(24901,5):
error C2065: 'dnn_Net': undeclared identifier [C:\apronina\opencv\build\modules\python3\opencv_python3.vcxproj]

Steps to reproduce

cmake -DBUILD_opencv_dnn=OFF <path-to-opencv>
cmake --build . --target instal --config Release

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Activity

  1. added this to the 4.12.0 milestone on Mar 14, 2025
  2. asmorkalov commented on Mar 14, 2025

    @asmorkalov
    Contributor

    We are working on #ifdef handling in header parser to cover HAVE_XXX macros at least. I'll notify you, when it's ready.

  3. AsyaPronina commented on Mar 14, 2025

    @AsyaPronina
    ContributorAuthor

    Thanks a lot! it is not critical though!

  4. torabshaikh commented on Apr 29, 2025

    @torabshaikh

    Hi @asmorkalov , @VadimLevin , If it is still pending, I would like to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions