OpenCV with CUDA - no data folder

Hi,

Maybe there is someone here that can help me fixing this issue: I am using Windows 10 64-bit, Visual Studio 2022, CMake 2.23.1, Anaconda with Python 3.9.7, and opencv-4.5.5 and opencv_contrib-4.5.5.

I have tried to set up OpenCV with CUDA-Support through this installation guide:
https://medium.com/analytics-vidhya/build-opencv-from-source-with-cuda-for-gpu-access-on-windows-5cd0ce2b9b37

It worked that CUDA-module is available and computation works with CUDA support with my NVIDIA GPU - so far, everything is fine. But once I was trying to use the CascadeClassifier provided by OpenCV, it says:

import cv2

faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
video_capture = cv2.VideoCapture(0)

frame_number = 0

Error message:


AttributeError Traceback (most recent call last)
Input In [4], in <cell line: 3>()
1 import cv2
----> 3 faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + ‘haarcascade_frontalface_default.xml’)
4 video_capture = cv2.VideoCapture(0)
6 frame_number = 0

AttributeError: module ‘cv2’ has no attribute ‘data’

To this error, I have found this: https://stackoverflow.com/questions/65357932/cv2-has-no-attribute-data

I have checked the “opencv”-folder in “site-packages” as well, there is no data folder inside. I have tried it now several times, and it seems that the “data”-folder in “opencv-x.x.x”-folder won’t get copied when configuring and building OpenCV with CUDA support.

Any advice to resolve this issue?

(I can post the build logs if you need it. CUDA works, I just don’t know how to implement to data folder with OpenCV CUDA)

afaik, only the pip version installs a “data” folder
(not copied in “normal” local builds)

even if, it would not help with cuda, which would require “old style” cascades from the 2.4 branch

afaik, only the pip version installs a “data” folder
(not copied in “normal” local builds)

Thanks, good to know. Do you know why? Is there a specific reason that the data folder won’t be copied or is it a bug?

even if, it would not help with cuda, which would require “old style” cascades from the 2.4 branch

Yeah, it does not copy the “data” folder, where haarcascades_GPU is included as well

Do you know any workaround to fix this issue?

i’d call it a service :wink:

Yeah, it does not copy the “data” folder, where haarcascades_GPU is included as well

it’s even worse, the haarcascades_GPU data does not exist on current 3.x or 4.x branches. you must explicitly checkout the 2.4 branch to see or copy them

not really.
however, what i would like to see here, would be updated docs for the cuda classifier, and maybe a small tutorial / script, how to dl those cascades

1 Like

it’s even worse, the haarcascades_GPU data does not exist on current 3.x or 4.x branches. you must explicitly checkout the 2.4 branch to see or copy them

Phew… okay, I see - thanks.

however, what i would like to see here, would be updated docs for the cuda classifier, and maybe a small tutorial / script, how to dl those cascades

Yeah, I absolutely agree. Apart from that, even the CUDA support for OpenCV is quite difficult to be set up from my pov as a user. I think it would be way easier if CUDA support would be auto-integrated into OpenCV and detected if there is a supported GPU detected (e.g., like it works in TensorFlow 2.x).