复制代码
- /// <summary>
- /// 重置图片的指定大小并且居中
- /// </summary>
- /// <param name="list"></param>
- /// <returns></returns>
- public List<Bitmap> ToResizeAndCenterIt(List<Bitmap> list, int w = 20, int h = 20)
- {
- List<Bitmap> resizeList = new List<Bitmap>();
- for (int i = 0; i < list.Count; i++)
- {
- //反转一下图片
- list[i] = new Invert().Apply(list[i]);
- int sw = list[i].Width;
- int sh = list[i].Height;
- Crop corpFilter = new Crop(new Rectangle(0, 0, w, h));
- list[i] = corpFilter.Apply(list[i]);
- //再反转回去
- list[i] = new Invert().Apply(list[i]);
- //计算中心位置
- int centerX = (w - sw) / 2;
- int centerY = (h - sh) / 2;
- list[i] = new CanvasMove(new IntPoint(centerX, centerY), Color.White).Apply(list[i]);
- resizeList.Add(list[i]);
- }
- return resizeList;
- }
其实精处理后,这些图片就可以作为我们的模板库的图片了,可以将每张模板图都标记下具体的数字,后续我们再遇到时,计算下其相似度就可以了,下面就是已经制作好的模板。
| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |