Reputation: 1362
read the image in
Mat img=imread("i000qa-fn.jpg",CV_LOAD_IMAGE_COLOR);
try to find objects...
faces = cvHaarDetectObjects(img,cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, Size(0, 0));
and walla...
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /media/Data/sdks/OpenCV-2.4.2/modules/core/src/array.cpp, line 2482
when I do imshow, the image is there as it should be.
Upvotes: 2
Views: 4565
Reputation: 30152
cvHaarDetectObjects
expects IplImage
or CvMat
but you are passing cv::Mat
object.
So you need a conversion like this:
IplImage img1 = img;
faces = cvHaarDetectObjects(&img1, cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, Size(0, 0));
Upvotes: 3
Reputation: 12554
No, Andrey (@AndreyKamaev), you need a different function instead:
#include <opencv2/core/core.hpp>
#include <opencv2/objdetect/objdetect.hpp>
using namespace cv;
Mat img = imread(img_path);
CascadeClassifier haar_cascade.load(path);
vector<Rect> detection_rois;
haar_cascade.detectMultiScale(img, detection_rois, 1.2, 2,
0|CV_HAAR_DO_CANNY_PRUNING);
That is how Haar detector is used in C++ since Opencv 2.3.1 that is since Aug. 2011. Also let me attach a documentation.
Here is a proof, below. :) I did a Haar_detector wrapper around this cv::CascadeClassifier -- which is really an Adaboost cascade classifier with Haar-like features, therefore the name.
Upvotes: 2