Build flag for `CascadeClassifier`

Hi,

As a hobbyist developer, I made an small app in Python that uses Willow/OpenCV to detect faces in pictures. I am now trying to package my app with Flatpak, so I want to build OpenCV with the minimal set of functionalities.

I first tried the following build flags:

"-DBUILD_EXAMPLES=OFF"
"-DBUILD_TESTS=OFF"
"-DBUILD_DOCS=OFF"
"-DBUILD_PERF_TESTS=OFF"
"-DBUILD_NEW_PYTHON_SUPPORT=ON"
"-DBUILD_ZLIB=OFF"
"-DOPENCV_BUILD_3RDPARTY_LIBS=OFF"
"-DINSTALL_C_EXAMPLES=OFF"
"-DINSTALL_PYTHON_EXAMPLES=OFF"
"-DBUILD_opencv_core=ON"
"-DBUILD_opencv_imgproc=ON"
"-DBUILD_opencv_imgcodecs=ON"
"-DBUILD_opencv_objdetect=ON"
"-DBUILD_opencv_calib3d=OFF"
"-DBUILD_opencv_features2d=ON"
"-DBUILD_opencv_flann=ON"
"-DBUILD_opencv_dnn=ON"
"-DBUILD_opencv_photo=OFF"
"-DBUILD_opencv_java=OFF"
"-DBUILD_opencv_java_bindings_generator=OFF"
"-DBUILD_opencv_js=OFF"
"-DBUILD_opencv_python2=OFF"
"-DBUILD_opencv_python3=ON"
"-DBUILD_opencv_python_bindings_generator=ON"
"-DBUILD_opencv_shape=OFF"
"-DBUILD_opencv_highgui=OFF"
"-DBUILD_opencv_superres=OFF"
"-DBUILD_opencv_stitching=OFF"
"-DBUILD_opencv_videostab=OFF"
"-DBUILD_opencv_videoio=OFF"
"-DBUILD_opencv_video=OFF"
"-DBUILD_opencv_apps=OFF"
"-DBUILD_opencv_gapi=OFF"
"-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.9.so"
"-DWITH_PROTOBUF=ON"
"-DWITH_1394=OFF"
"-DWITH_VTK=OFF"
"-DWITH_DIRECTX=OFF"
"-DWITH_DSHOW=OFF"
"-DWITH_EIGEN=OFF"
"-DWITH_FFMPEG=OFF"
"-DWITH_GSTREAMER=OFF"
"-DWITH_GTK=OFF"
"-DWITH_IPP=OFF"
"-DWITH_JASPER=OFF"
"-DWITH_JPEG=ON"
"-DWITH_MATLAB=OFF"
"-DWITH_OPENJPEG=OFF"
"-DWITH_OPENEXR=OFF"
"-DWITH_OPENNI=OFF"
"-DWITH_OPENMP=OFF"
"-DWITH_PNG=OFF"
"-DWITH_PVAPI=OFF"
"-DWITH_WIN32UI=OFF"
"-DWITH_QT=OFF"
"-DWITH_QUICKTIME=OFF"
"-DWITH_QT_OPENGL=OFF"
"-DWITH_TBB=OFF"
"-DWITH_TIFF=OFF"
"-DWITH_UNICAP=OFF"
"-DWITH_V4L=OFF"
"-DWITH_VFW=OFF"
"-DWITH_VIDEOINPUT=OFF"
"-DWITH_XINE=OFF"
"-DWITH_VA_INTEL=OFF"
"-DWITH_GPHOTO2=OFF"
"-DWITH_WEBP=OFF"
"-DWITH_IMGCODEC_HDR=OFF"
"-DWITH_IMGCODEC_SUNRASTER=OFF"
"-DWITH_IMGCODEC_PXM=OFF"
"-DWITH_CUDA=OFF"
"-DWITH_CUFFT=OFF"
"-DWITH_CUBLAS=OFF"
"-DWITH_NVCUVID=OFF"
"-DWITH_OPENCL=OFF"
"-DWITH_OPENCL_SVM=OFF"
"-DWITH_OPENCLAMDFFT=OFF"
"-DWITH_OPENCLAMDBLAS=OFF"
"-DWITH_OPENJPEG=OFF"
"-DCV_ENABLE_INTRINSICS=OFF"
"-DCV_DISABLE_OPTIMIZATION=ON"

But when I ran my software it failed with the following error: module 'cv2' has no attribute 'CascadeClassifier'.

I then built OpenCv with all flags ON and my program worked. Could someone tell me which flag needs to be ON so that CascadeClassifier is available but without having all the bells and whistles? Also, do not hesitate if you think I should toggle other build flags.

Regards,
Yvan

is probably the most important one here
(the objdetect module contains the CascadeClassifier)

that said, if you switch both WITH_FFMPEG and WITH_GSTREAMER off, you wont be able to play video files

Hi @berak,

-DBUILD_opencv_objdetect was already enabled, so there is something OFF that needs to be ON, but which one(s)?

And sorry I forgot to mention that my software only opens JPEG files, so no video here.

I finally found it: the missing parameter was -DBUILD_opencv_calib3d.

1 Like