private void CreateTemplate(string filename, string templatefilename = "") { Bitmap bmp = (Bitmap)Bitmap.FromFile(filename); MyDetectFeatureRectAngle dr = new MyDetectFeatureRectAngle(bmp); if (dr.Detected()) { if (_artemplate != null) { _artemplate.Clear(); } _artemplate = new ARTemplate.Template(filename, bmp, dr.CorrectRect); _angle = new AutoAngle(dr.ListPoint); //或者导入时 设置 if (templatefilename != "" && File.Exists(templatefilename)) { _artemplate.Load(templatefilename); } this.Hide(); _artemplate.SetFeaturePoint(dr.ListFeatureRectangle, dr.CorrectRect); ARTemplate.FormTemplate f = new ARTemplate.FormTemplate(_artemplate); f.ShowDialog(); this.Show(); } }
private StringBuilder DetectAllImg(MyDetectFeatureRectAngle dr, string s, List <string> title = null) { if (dr == null) { title.Clear(); title.Add("文件名"); title.Add("CorrectRect"); title.Add("校验角度"); title.Add("选择题"); if (_artemplate.Dic.ContainsKey("考号") && _artemplate.Dic["考号"].Count > 0) { title.Add("考号"); } return(null); } Bitmap bmp = (Bitmap)Bitmap.FromFile(s); string str = s.Substring(s.Length - 7, 3); //MyDetectFeatureRectAngle dr = new MyDetectFeatureRectAngle(bmp); Rectangle CorrectRect = dr.Detected(bmp); StringBuilder sb = new StringBuilder(); sb.Append(s + "," + CorrectRect.ToString("-") + ","); // 文件名 CorrectRect if (CorrectRect.Width > 0) { //TODO: debug r1 in 001 Rectangle cr1 = new Rectangle(CorrectRect.Right - 60, CorrectRect.Top - 20, 80, 80); Rectangle r1 = dr.Detected(cr1, bmp); Rectangle cr2 = new Rectangle(CorrectRect.Left - 20, CorrectRect.Bottom - 60, 80, 80); Rectangle r2 = dr.Detected(cr2, bmp); sb.Append(_angle.SetPaper(CorrectRect.Location, r1.Location, r2.Location) + ","); //校验角度 Bitmap nbmp = (Bitmap)bmp.Clone(CorrectRect, bmp.PixelFormat); nbmp.Save(s.Replace("LJH\\", "LJH\\Correct\\")); //计算选择题 AutoComputeXZT acx = new AutoComputeXZT(_artemplate, _angle, nbmp); sb.Append(acx.ComputeXZT(str)); //选择题 //计算二维码 if (_artemplate.Dic.ContainsKey("考号") && _artemplate.Dic["考号"].Count > 0) { KaoHaoChoiceArea kha = (KaoHaoChoiceArea)(_artemplate.Dic["考号"][0]); if (kha.Type == "条形码") { Rectangle Ir = kha.ImgArea; // Ir.Offset(CorrectRect.Location); Bitmap barmap = (Bitmap)nbmp.Clone(kha.ImgArea, nbmp.PixelFormat); barmap.Save("f:\\aa.tif"); ZXing.Result rs = _br.Decode(barmap); if (rs != null) { sb.Append("," + rs.Text); } } } } else { //检测失败 } sb.AppendLine(); return(sb); //MessageBox.Show(sb.ToString()); }