参考原文和实现效果见下帖:
https://blog.csdn.net/jkjj2015/article/details/87160291
效果如下:
该博主用的是Java,我这仿写了C#的,代码如下:
private void ReduceBackGround(Image<Bgr,byte> tempImage)
{
Mat src = tempImage.Mat;
CvInvoke.CvtColor(src, src,ColorConversion.Bgr2Gray);
src.ConvertTo(src,DepthType.Cv32F, 1.0 / 255);
Mat dst3=ReduceBackGroundAlgorithm(src,0);
CvInvoke.GaussianBlur(dst3, dst3, new Size(1, 1), 0, 0,BorderType.Default); //Size(width, heigth),width,heigth参数可调,两个参数相同,默认值1,调节范围1-9(需为奇数);
//dst3 = ColorGradation(dst3);
CvInvoke.AdaptiveThreshold(dst3,dst3,255,0,0,31,13);//去除背景色后再进一步二值化,C参数可调,默认值30,调节范围1-50;
this.imageBox2.Imag