mser处理文本区域


Maximal stable extremal regions 在opencv中有原型。可以用来检测文本区域。本文对比率他和SWT的结果

效果依情况而定。

int main( int argc, char** argv )
{

	char* filename = argc >= 2 ? argv[1] : (char*)"../mingpian.jpg";
	Mat img0 = imread(filename, 1);
	Mat rgb_test = imread(filename, 1);
	vector<Mat>sbgr(rgb_test.channels());
	split(rgb_test,sbgr);
	imshow("blue",sbgr[2]);
	Mat gray_img, mask_img;
	vector<vector<Point>> contours;
	cvtColor(img0,gray_img,COLOR_BGR2GRAY);
	MSER ms(5, 20,14400,
		0.25,.2,
		200, 1.01,
		0.003,5 );
	ms(sbgr[2],contours,mask_img);
	Mat wshed(gray_img.size(), CV_8UC3);
	wshed = Scalar::all(255);
	for ( int i = 0; i < contours.size(); i++ )
	{
		const Point* p = &contours[i][0];
		int n = (int)contours[i].size();
		if (contourArea(Mat(contours[i]))<((gray_img.cols*gray_img.rows)/100)){	
			Rect a = boundingRect(contours[i]);
			if(a.width/a.height<5&&a.height/a.width<5){
				for (int j = 0; j<n; j++)
				{

					Point sd = contours[i][j];
					wshed.at<Vec3b>(sd.y,sd.x) = Vec3b(0,0,0);
				}
				rectangle(img0,Point(a.x,a.y),Point(a.x+a.width,a.y+a.height),Scalar(0,255,0),-1,8,0);
			}
		}
	}

	Mat gray_wshed,m_gaussianImage ;
	cvtColor(wshed,gray_wshed,COLOR_BGR2GRAY);
	gray_wshed.convertTo(m_gaussianImage,CV_32FC3);
	m_gaussianImage/=255;
	IplImage* textimage = cvCreateImage(cvSize(wshed.cols,wshed.rows),IPL_DEPTH_8U,1);
	imshow("sdf",sbgr[1]);

	waitKey(0);
}


选择红色通道的原因是给名片在红色下对比度高,而且去处了红色背景


原图



mser处理之后处SWT处理




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值