public static List<Boundary> GetImgBoundaryList(Image img, ref Bitmap _bmp, bool is4Chars,int charWidth=10)
{
List<Boundary> list = new List<Boundary>();
Bitmap bmp = new Bitmap(img);
int startY = 0;
int endY = 0;
int startX = 0;
int endX = 0;
try
{
for (int i = 0; i < 10; i++)
{
startY = GetStartBoundaryY(img, startY);
if (startY >= 0)
{
endY = GetEndBoundaryY(img, startY + 1);
//标记
startX = GetStartBoundaryX(img, startY, endY);
int _startX = startX;
bool flag = false;
while (!flag && _startX < img.Height)
{
endX = GetEndBoundaryX(img, _startX, startY, endY);
flag = endX - _startX >=5;//最小高度
_startX = _startX + 1;
}
if (endX > 0 && endX - startX >= 5)//最小高度
{
list.Add(new Boundary { EndY = endY, EndX = endX, StartY = startY, StartX = startX });
}
startY = endY;
}
else
{
break;
}
}
if (is4Chars&&list.Count!=4)
{
list = NotFourChars(img, out _bmp, list,charWidth);
}
else
{
_bmp = bmp;
}
List<Boundary> tempBdList = list;
for (int i = 0; i < tempBdList.Count; i++)
{
if (
!((tempBdList[i].EndY - tempBdList[i].StartY >= charWidth) &&//最小宽度比较
(tempBdList[i].EndX - tempBdList[i].StartX >= 5)))//最小高度
{
list.Remove(tempBdList[i]);
}
}
}
catch (Exception ex)
{
throw;
}
return list;
}
/// <summary>