Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        private void DetectAllImgs(MyDetectFeatureRectAngle dr, List <string> nameList)
        {
            FileInfo fi  = new FileInfo(nameList[0]);
            string   dir = fi.Directory.FullName.Replace("LJH\\", "LJH\\Correct\\");

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            InitRundt(_artemplate);
            dgv.DataSource = _rundt;
            InitDgvUI();
            _rundr       = dr;
            _runnameList = nameList;

            Thread thread = new Thread(new ThreadStart(RunDetectAllImg));

            thread.Start();
        }
Esempio n. 3
0
        public FormM()
        {
            InitializeComponent();
            _workpath    = textBoxWorkPath.Text;
            _angle       = null;
            _artemplate  = null;
            _rundr       = null;
            _runnameList = null;
            _runmsg      = "";
            _exportdata  = "";
            _xztpos      = -1;
            _titlepos    = new Dictionary <string, int>();
            //for 二维码
            DecodingOptions decodeOption = new DecodingOptions();

            decodeOption.PossibleFormats = new List <BarcodeFormat>()
            {
                BarcodeFormat.All_1D
            };
            _br         = new BarcodeReader();
            _br.Options = decodeOption;
        }
Esempio n. 4
0
        private void ButtonScanClick(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex == -1)
            {
                return;
            }
            if (listBoxTemplate.SelectedIndex == -1)
            {
                MessageBox.Show("还未选择模板");
                return;
            }
            string        path     = listBox1.SelectedItem.ToString();
            List <string> nameList = NameListFromDir(path);

            if (nameList.Count == 0)
            {
                return;
            }
            Bitmap bmp = (Bitmap)Bitmap.FromFile(_artemplate.Filename);
            MyDetectFeatureRectAngle dr = new MyDetectFeatureRectAngle(bmp);

            DetectAllImgs(dr, nameList);
        }
Esempio n. 5
0
        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());
        }