I want to split the following characters for character recognition. How can I achieve my goal?


Should I use color clustering or any other methods, since there are four different or similar colors among characters? But I don't know how to do that.
The following code is to use kmean method to split those characters.
Mat src= imread(name);
cv::Mat reshaped_image = src.reshape(1, src.cols * src.rows);
Mat reshaped_image32f;
reshaped_image.convertTo(reshaped_image32f, CV_32FC1, 1.0 / 255.0);
cv::Mat labels;
int cluster_number = 5;
cv::TermCriteria criteria{ cv::TermCriteria::COUNT, 100, 1 };
cv::Mat centers;
cv::kmeans(reshaped_image32f, cluster_number, labels, criteria, 1, cv::KMEANS_RANDOM_CENTERS, centers);
Mat new_image;
int* clusters_p = (int*)labels.data;
Mat label(src.size(), CV_32SC1);
int* label_p = (int*)label.data;
unsigned long int size = src.cols * src.rows;
for (int i = 0; i < size; i++)
{
*label_p = *clusters_p;
label_p++;
clusters_p++;
}
double minH, maxH;
minMaxLoc(labels, &minH, &maxH);
cout << "minH = " << minH<(y, x) == p)
{
outImg.at(y, x) = colorPix[p];
break;
}
}
}
}
return outImg;
My resulting images are different in colors. I don't know whether I have done something wrong...


↧