Problem with cuda CascadeClassifier

Hi, I have trained my own haar cascade classifier using opencv version 3.2 and after checking its performance I tried to use the cuda functions to perform some tests, however I encountered the following error:

terminate called after throwing an instance of 'cv::Exception'what():  OpenCV(4.4.0) /tmp/build_opencv/opencv_contrib/modules/cudalegacy/src/cuda/NCVHaarObjectDetection.cu:2079: error: (-215:Assertion failed) haar.ClassifierSize.height > 0 && haar.ClassifierSize.width > 0 in function 'loadFromXML'

I am currently using opencv version 4.4 and applying the detectMultiScale function as follows:

         cv::cuda::GpuMat gframe, obj;
         std::vector<cv::Rect> rect;
         std::string cascadePath = "./cascade.xml"
         Ptr<cuda::CascadeClassifier> cascade = cv::cuda::CascadeClassifier::create(cascadePath);

         cascade->setScaleFactor(1.8);
         cascade->setMinNeighbors(10);
         cascade->setMinObjectSize(cv::Size(Tmin,Tmin));
         cascade->setMinObjectSize(cv::Size(Tmax,Tmax));
         cascade->detectMultiScale(gframe, obj);
         cascade->convert(obj, rect);

I appreciate any information.

file can’t be found. most common cause.

if you use relative paths, pay attention to the “current working directory” of your process.

I have the .xml file in the same working directory and read it as follows:

     cv::cuda::GpuMat gframe, obj;
     std::vector<cv::Rect> rect;
     std::string cascadePath = "./cascade.xml"
     Ptr<cuda::CascadeClassifier> cascade = cv::cuda::CascadeClassifier::create(cascadePath);

It has worked for me on other occasions. Could it be generating the problem?

does the code succeed if that file has some other, known good, content? (put a different file there)

note that “current working directory” is a property of the operating system process structure.

just use an absolute path. if that works, it was the CWD issue.

I tried with an absolute path and other .xml files and the result was the same.
I have also tried the code without the cuda functions and the same .xml file and it works without problems.
Is it possible that there is a formatting problem between the .xml files generated by opencv_traincascade or cascade trainer GUI and what cuda::CascadeClasiffier is looking for?

Thank you very much for your answers.

okay that’s good but now I’m out of ideas. your suspicion, the cuda version being somehow different, sounds plausible. I hope someone with more experience with the CUDA modules will see the issue.

I come back to say that I have solved the problem. It appears to be a compatibility problem. I used opencv version 3.4 and the opencv_traincascade function with its -baseFormatSave argument to train with the old .xml format and it worked.

However, when comparing this classifier in its cpu version (with cv::detectMultiScale) versus gpu (with cv::cuda::detectMultiScale), the detection results are very different between them.