Skip to content

Optional DNN dependency causes Python bindings to fail #27250

@abhishek-gola

Description

@abhishek-gola

System Information

OpenCV version: 5.0.0-pre
Operating System / Platform: Ubuntu 24.04
Compiler & compiler version: GCC 14.2.0

Detailed description

When a module optionally depends on the opencv_dnn module, and CV_WRAP functions are conditionally defined using #ifdef HAVE_OPENCV_DNN, the Python binding generator ignores these conditionals and generates bindings for all CV_WRAP functions regardless of the presence of the DNN module. This leads to build errors when the DNN module is not available.

Example:Module definition:

ocv_define_module(objdetect
    opencv_core
    opencv_imgproc
    opencv_3d
    OPTIONAL
        opencv_dnn
    WRAP
        python
        java
        objc
        js
)

Conditional function definition:

#ifdef HAVE_OPENCV_DNN
    /**
     * @brief Set the net which will be used to find the approximate
     * bounding boxes for the color charts.
     * @param net the neural network.
     */
    CV_WRAP static Ptr<CCheckerDetector> create(const dnn::Net &net);
#endif

Current Behavior:

  • Python binding generator ignores #ifdef HAVE_OPENCV_DNN.
  • Generates bindings for the CV_WRAP function unconditionally.
  • Build fails due to missing opencv_dnn.

Expected Behavior:

  • Python binding generator should respect conditional compilation (#ifdef HAVE_OPENCV_DNN) and only generate bindings if the opencv_dnn module is present.

Steps to reproduce

Build the objdetect module with Python bindings solely (without DNN) in branch 5.x

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions