vector<IplImage*> mycvCharSegment(IplImage* image)
{ //此函数利用OpenCV中的cvFindContours找出字符的轮廓后进行字符分割,包括汉字的合并处理,但是要求二值化的图像轮廓清晰
vector<IplImage*> characters; //存储分割出来的字符的图像头
IplImage* smoothImg = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
cvSmooth(image, smoothImg, CV_MEDIAN, 3, 3, 0, 0);
/*cvNamedWindow("Smooth", CV_WINDOW_AUTOSIZE);
cvShowImage("Smooth", smoothImg);*/
IplImage* contoursImg = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
cvCopy(smoothImg,contoursImg);
CvSeq* contours = NULL;
CvMemStorage* storage = cvCreateMemStorage(0);
int count = cvFindContours(smoothImg, storage, &contours, sizeof(CvContour), CV_RETR_EXTERNAL);
vector<CvRect> rcs;
vector<CvRect> comrcs;
for ( CvSeq* c = contours; c != NULL; c = c->h_next )
{
CvRect rect = cvBoundingRect(c, 0);
rcs.push_back(rect);
}
sort(rcs.begin(), rcs.end(), compareRect); //compareRect是自定义的一个比较函数
vector<CvRect>::ite
【OpenCV】基于轮廓的字符分割
最新推荐文章于 2025-07-08 15:56:22 发布