Answer the question
In order to leave comments, you need to log in
How to recognize number from screenshot using OpenCV?
Good day. I need to determine the number from the screenshot (it's clear and the characters are the same). How should I solve with OpenCV? I have no experience in solving problems of this kind, and searching for information on the Internet did not help. I tried using Canny + findContours to find the contours so that I can then compare with the template, but I’m already stuck on this, because the outer shadow (black) of the numbers also made the contour for me. Maybe there are some examples of such a solution to such a problem? How can I determine from these contours what this number is?
Thanks in advance for your help!
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
Canny(img_gold, canny_output, thresh, thresh * 2, 3);
findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
Mat drawing = Mat::zeros(canny_output.size(), CV_8UC3);
for (int i = 0; i< contours.size(); i++)
{
if (contourArea(contours[i]) < 100) continue;
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point());
}
imshow("zzz", drawing);
Answer the question
In order to leave comments, you need to log in
So what is wrong? findContours returns contours to you, and you filter all contours that are less than 100 in area (that is, the inner contours of the numbers will be removed), which is not correct. Yes, and canny is not needed here, it’s just worth playing around with the binarization threshold (so that only white numbers remain on a black background).
Further, we still find the connected areas and consider their characteristics (perimeter, area) and we already carry out a classification on them. Another good way to classify (and also quite simple) is by histograms. That is, we take a picture, do binarization (by the color of the numbers, or, if the colors are still not uniform, with a slight tolerance towards darker colors, you can play around here) and build a histogram that takes into account the number of white pixels for each column, so you can immediately find objects (in your example, after binarization, there will be clear gaps between each digit), that is, we take all the gaps where the number of white pixels in the column will be equal to zero. Further, according to the same histograms, classification can be carried out, for each symbol the histogram will be different.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question