std::vector crashes on deallocation
After downloading the latest version of OpenCV, I'm having a problem where using certain functions that output values to a std::vector crashes when the vector destructor is called. For example, the following snippet crashes at at the end of the code as x
falls out of scope:
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
int size = 512;
std::vector<Point> x;
Mat m(1, size, CV_8U, Scalar(128));
findNonZero(m, x);
}
Interestingly, if size
is less than 512, everything works fine.
Now, I suppose maybe findNonZero
should output to a Mat
instead of a vector, but this code worked in the past. Furthermore, I'm seeing similar effects with CascadeClassifier::detectMultiScale
which expects to output to a vector<Rect>
.
The error messages indicate an access violation. When running in a Debug configuration, I get assert fail errors. Everything happens in the vector destructor.
I've tried running with different architectures and various other settings. I will try reinstalling OpenCV by building it from the source. It's just I've been at this bug for a whole day, and I would greatly appreciate if anyone could give me some insight about what to do.
Thanks.
now, that you changed your question / usage significantly, please check, if you accidentally mix opencv debug/release libs. you have to strictly use one type with one built. failing to do so usually produces errors like yours.
Hi!
Did you solve this issue or figured out whe it happens? I'm having the same problem when using std::Vector<cv::point> vec and similar code to yours.
A workaround I found is to use reserve with a larger size before calling the findNonZero() function and than there is no crash.
@[email protected]">@[email protected] , please do not post answers here, if you have a question or a comment, thank you.