opencv - CascadeClassifier::detectMultiScale doesn't work with C++ -
i'm using opencv , cascadeclassifier::detectmultiscale
facial detection. problem seems cause memory corruption on output vector<rect>
. vector correctly filled rects, causes crash when vector deallocated.
this occurs when compiling debug build. error message debug assertion failed, makes me wonder if there problem occurs in release build, , assert isn't checked.
could bug opencv? or i'm doing wrong how handle vectors?
the following code snippet shows example code reproduce bug:
#include <opencv2/opencv.hpp> using namespace cv; int main(array<system::string ^> ^args) { videocapture video(0); mat frame; cascadeclassifier classifier("haarcascade_frontalface_default.xml"); while (waitkey(1000 / 30) != 'q') { video >> frame; vector<rect> faces; classifier.detectmultiscale(frame, faces); (int = 0; < faces.size(); i++) rectangle(frame, faces[i], scalar(255, 255, 255)); imshow("camera", frame); } // <<< crash occurs here when faces vector released }
i following error message:
debug assertion failed!
program: myprogram.exe file: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp line: 892
expression: is_block_type_valid(header->_block_use)
i had same issue. solved passing dereferenced global pointer function.
i.e.
std::vector<cv::rect>* faces = nullptr; void init() { faces = new std::vector<cv::rect>; //never call delete whatever } void findsomefaces() { cascade->detectmultiscale(image_source, *faces); }
Comments
Post a Comment