Reputation: 210
I am using a function like this;
Mat large = imread(path+name);
Mat rgb;
if (large.rows > 2500 || large.cols > 1250)
{
pyrDown(large, rgb);
}
else
{
rgb = large.clone();
}
cv::Mat smallx;
cvtColor(rgb, smallx, CV_BGR2GRAY);
Mat grad,connected,bw;
Mat morphKernel = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
cv::morphologyEx(smallx, grad, MORPH_GRADIENT, morphKernel);
cv::threshold(grad, bw, 100, 255, THRESH_BINARY + THRESH_OTSU);
morphKernel = getStructuringElement(MORPH_RECT, Size(9, 1));
cv::morphologyEx(bw, connected, MORPH_CLOSE, morphKernel);
Mat mask = Mat::zeros(bw.size(), CV_8UC1);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
cv::findContours(connected, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
Some input images prompt exception when function returns, it throws me to "_Mybase::deallocate(_Ptr, _Count);" code block in xmemory0 class. I must catch this kind of errors and prevent this process from unexpected suspensions
--------------ERROR DETAILS--------------
I tried that code block with 30 different input but it gave error in a few image. after findcontours it thrown an exception break and show me this message.
Unhandled exception at 0x74477fb2 (ucrtbase.dll) in ImageRecognizer.exe: 0xC0000409: 0xc0000409.
in that time , "vector" class opening in my Visual Studio with these lines ;
~vector() _NOEXCEPT
{ // destroy the object
_Tidy();
}
or "xmemory" class opening with these lines;
void deallocate(pointer _Ptr, size_type _Count)
{ // deallocate object at _Ptr, ignore size
_Mybase::deallocate(_Ptr, _Count);
}
Upvotes: 0
Views: 371
Reputation: 210
I tried to OpenCV 2.4.13 instead of OpenCV 2.4.12 and problem solved by itself. It wasn't an algorithm or logical error. It was a library bug.
Upvotes: 0
Reputation: 314
It seems that number of counters your method finds exceeds 50000. Try not to use magic numbers. It is always a bad practice.
Upvotes: 1