1 | initial version |
The dilate function needs the kernel not a empty Mat() and 12 iterations, it is better to increase the kernel size for better performance.
You initialize areas with contours.size. Later on you push the found box so the first part of areas is empty
findContours wants a thresholded image e.g. 0 = background and everything else is object. so you need to feed a threshold image to this function.
Don't use auto (it can be very confusing what the compiler makes from the auto)
One other option it could be the .lib and .dll are not matching with each other or with the compiler you use to compile this.
I have tested below modified code in VS2015 with opencv 3.4.1 ant it works without crashing.
std::vector<cv::RotatedRect> findTextAreas(cv::Mat image)
{
Mat kernel = getStructuringElement(MORPH_CROSS, Size(3, 3));
Mat dilated;
dilate(image, dilated, kernel, cv::Point(-1, -1), 3);
imshow("Dilated", dilated);
waitKey(1000);
std::vector<std::vector<cv::Point> > contours;
waitKey(1000);
findContours(dilated, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
std::vector<cv::RotatedRect> areas;
for (int i = 0; i < (int)contours.size(); i++)
{
cv::RotatedRect box = minAreaRect(contours[i]);
if (box.size.width < 20 || box.size.height < 20)
continue;
double prop = box.angle < -45 ? box.size.height / box.size.width : box.size.width / box.size.height;
if (prop < 2)
continue;
areas.push_back(box);
}
return areas;
}