Poor performance of cv::text
I need to locate all letters on this screenshot:
Tried https://github.com/opencv/opencv_cont...
(playing with params of NMSBoxes didn't give me any good result)
and this one: https://github.com/opencv/opencv_cont...
(also played with different parameters several hours with no luck).
However trivial operations with tresholding and connected components can give relatively good results (code taken from stackoverflow):
Mat large = imread(INPUT_FILE);
Mat rgb;
pyrDown(large, rgb);
Mat small;
cvtColor(rgb, small, CV_BGR2GRAY);
Mat grad;
Mat morphKernel = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
morphologyEx(small, grad, MORPH_GRADIENT, morphKernel);
imshow("grd", grad);
imshow("sml", small);
Mat bw;
threshold(grad, bw, 0.0, 255.0, THRESH_BINARY | THRESH_OTSU);
Mat connected;
morphKernel = getStructuringElement(MORPH_RECT, Size(9, 1));
morphologyEx(bw, connected, MORPH_CLOSE, morphKernel);
imshow("xx", connected);
Mat mask = Mat::zeros(bw.size(), CV_8UC1);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(connected, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
for (int idx = 0; idx >= 0; idx = hierarchy[idx][0]) {
Rect rect = boundingRect(contours[idx]);
Mat maskROI(mask, rect);
maskROI = Scalar(0, 0, 0);
drawContours(mask, contours, idx, Scalar(255, 255, 255), CV_FILLED);
double r = (double)countNonZero(maskROI) / (rect.width*rect.height);
if (r > .45
&&
(rect.height > 8 && rect.width > 8)
) {
rectangle(rgb, rect, Scalar(0, 255, 0), 2);
}
}
imshow("res",rgb);
so what is wrong with samples from cv::text?