When I used the HOGDetector to do my pedestrain detection, the program was interrupted (it can run at the beginning) and told me that "Debug Assertion Failed" "Expression: _CrtIsValidHeapPointer(pUserData)" . The environment is VS2012+OpenCV 2.4.3. And this is my code. The attaachment is the picture that I used.
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include "iostream" using namespace cv; using namespace std; int main() { Mat img;
vector<rect> found, found_filtered;
string namepic="street.png"; img = imread(namepic);
HOGDescriptor hog; hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
namedWindow("people detector", 1); cout<<namepic<<endl; fflush(stdout);="" <="" p="">
// run the detector with default parameters. to get a higher hit-rate // (and more false alarms, respectively), decrease the hitThreshold and // groupThreshold (set groupThreshold to 0 to turn off the grouping completely). hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);
size_t i, j; for( i = 0; i < found.size(); i++ ) { Rect r = found[i]; for( j = 0; j < found.size(); j++ ) if( j != i && (r & found[j]) == r) break; if( j == found.size() ) found_filtered.push_back(r); } for( i = 0; i < found_filtered.size(); i++ ) { Rect r = found_filtered[i]; // the HOG detector returns slightly larger rectangles than the real objects. // so we slightly shrink the rectangles to get a nicer output. r.x += cvRound(r.width0.1); r.width = cvRound(r.width0.8); r.y += cvRound(r.height0.07); r.height = cvRound(r.height0.8); rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 3); } imshow("people detector", img); return 0; }