How to load old format cascade on OpenCV 2.4.10?

asked 2017-06-16 08:08:50 -0500

678098 gravatar image

I am currently trying to use cv::ocl::OclCascadeClassifier, but It uses oldCascade only which is NULL (so I got invalid cascade cv exception).

Method isOldFormatCascade() returns false, method load() returns true.

If I use cv::CascadeClassifier, all works fine (because there are 2 branches in its implementation: for old format and for new format cascades).

cv::Mat image = cv::Mat::zeros(cv::Size(2000, 700), CV_8UC1);
cv::ocl::oclMat image_igpu;
image_igpu.upload(image);
cv::Size min_size(50, 10);
cv::Size max_size(100, 20);

cv::CascadeClassifier cascade_cpu;
cv::ocl::OclCascadeClassifier cascade_igpu;
cascade_cpu.load("cascade.xml");
cascade_igpu.load("cascade.xml");

std::cout << cascade_igpu.isOldFormatCascade() << std::endl;//prints 0 (false), same as cascade_cpu.isOldFormatCascade()


std::vector<cv::Rect> objs;
cascade_cpu.detectMultiScale(image, objs, 1.1, 0, 0, min_size, max_size);//works fine
cascade_igpu.detectMultiScale(image_igpu, objs, 1.1, 0, 0, min_size, max_size);//OpenCV Error: Null pointer (Invalid classifier cascade) in oclHaarDetectObjects
edit retag flag offensive close merge delete

Comments

which cascade file is it ? (you indeed have to use old-format cascades for ocl or cuda)

if it is one of the prebuild opencv cascades, you could try one of those

berak gravatar imageberak ( 2017-06-16 08:53:25 -0500 )edit

I used my custom cascade, which has been trained about 2 years ago. I don't even remember where the training data is.

By the way, I successfully launched ocl cascade with old-format cascades from opencv distribution.

And I found in cv version 3 sources cascades converter from old to new: https://github.com/opencv/opencv/blob/master/modules/objdetect/src/cascadedetect_convert.cpp

So the questions is: is converter from new to old format needed?

678098 gravatar image678098 ( 2017-06-19 05:35:04 -0500 )edit

yes, from new to old is needed for ocl/cuda.

unfortunately, the converter tool in opencv3 works the other way, you cannot use it.

berak gravatar imageberak ( 2017-06-19 05:57:09 -0500 )edit