public Interpret(KeySuite keys, Acquired acquired, Anchor anchor, CoreMsgEventHandler handler) { this.result = new Discover(); this.result.file = acquired.FileName; this.CoreMsg += handler; this.acq = acquired; this.keys = keys; place = new Place(anchor, this.CoreMsgDelegates); }
public Discover OneFile(string fileName, ref KeySuite keys) { if (!File.Exists(fileName)) { Inform(this, "Tệp {0} không có thực!", fileName); return(null); } else { Inform(this, "Xử lý: '{0}'", fileName); } FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); Acquired acq; try { Bitmap sourceBitmap = new Bitmap(fs); switch (sourceBitmap.PixelFormat) { case PixelFormat.Format24bppRgb: case PixelFormat.Format32bppArgb: case PixelFormat.Format8bppIndexed: break; default: Inform(this, "Hệ màu không hỗ trợ. Chỉnh lại cấu hình quét về màu RGB hoặc Grey 8-bit."); return(null); } acq = new Acquired(sourceBitmap, CoreMsgDelegates); acq.FileName = fileName; } catch (ArgumentException) { Inform(this, "Tệp'{0}' bị hỏng.", fileName); return(null); } finally { fs.Close(); } Anchor anchor = new Anchor(acq, this.CoreMsgDelegates); anchor.Detect(AnchorType.TopLeft); anchor.Detect(AnchorType.TopRight); anchor.Detect(AnchorType.BottomLeft); anchor.Detect(AnchorType.BottomRight); Inform(this, string.Format("Neo: TL{0} TR{1} BL{2} BR{3}", anchor[AnchorType.TopLeft].ToString(), anchor[AnchorType.TopRight].ToString(), anchor[AnchorType.BottomLeft].ToString(), anchor[AnchorType.BottomRight].ToString())); if (anchor.Acceptable) { Interpret interpret = new Interpret(keys, acq, anchor, this.CoreMsgDelegates); interpret.FindAnswer(); interpret.FindStudent(); interpret.FindProblem(); interpret.FindGroup(); interpret.FindMark(); interpret.Result.root = anchor[AnchorType.TopLeft]; interpret.Result.portion = keys.portion; return(interpret.Result); } else { return(null); } }
public int Add(KeySuite s) { return(suites.Add(s)); }
private void toolBtnRecognize_Click(object sender, EventArgs e) { if (_isRecognized) { return; } if (Core.Ref.UniSuite.ActiveSuiteIndex == -1) { Core.Utility.Msg("Chưa có bộ đáp án nào được chọn"); return; } _keys = Core.Ref.UniSuite.ActiveSuite; // Tạm dừng hoạt động, tránh người sử dụng bấm lung tung -> hỏng việc // : ) toolBtnRecognize.Enabled = false; #region Xác định nguồn dữ liệu quuét Hashtable tag = (Hashtable)this.Tag; _automate = new Core.Automate(); _automate.CoreMsg += new Core.CoreMsgEventHandler(CoreMsg_Handler); switch ((Core.Automate.Source)tag[TagKeys.AutomateSource]) { case Core.Automate.Source.Files: _files = (string[])tag[TagKeys.Files]; break; case Core.Automate.Source.Folder: _automate.Folder((string)tag[TagKeys.Path]); _files = _automate.FileList; break; } if (_files == null) { _automate.Inform(_automate, "Không có tệp nào."); return; } UseWaitCursor = true; #endregion #region Kiểu cũ: dựa vào dropDown //if (tag[TagKeys.KeySuite] != null && Core.Ref.UniSuite[(int)tag[TagKeys.KeySuite]] != null) // // Lấy thẳng từ tag của form trỏ đến Unisuite // _keys = Core.Ref.UniSuite[(int)tag[TagKeys.KeySuite]] as Core.KeySuite; //else //{ // // Tìm nguồn suite thay thế // DialogResult doAction = MessageBox.Show(string.Format( // "Chưa có bộ đáp án nào được chuyển đến để chấm điểm.{0}" + // "\tChọn Yes nếu muốn *tạo mới* một bộ đáp án.{0}" + // "\tChọn No nếu muốn *mở hay nạp* một bộ đáp án có sẵn.{0}" + // "\tChọn Cancel để nhận dạng bài làm thuần tuý Trong lúc đó bạn sẽ nhập bộ đáp án {0}" + // "\tvà việc lên điểm diễn ra sau cùng.", Environment.NewLine), // UI.Properties.Settings.Default.WindowCaption, MessageBoxButtons.YesNoCancel, // MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); // switch (doAction) // { // case DialogResult.Yes: // #region Tạo mới một bộ đáp án và chuyển luôn vào của sổ hiện tại // FormNewsuite fns = new FormNewsuite(); // fns.MdiParent = this.MdiParent; // this.Enabled = false; // fns.Show(); // fns.FormClosing += new FormClosingEventHandler(fns_FormClosing); // return; // #endregion // case DialogResult.No: // #region Mở một bộ đáp án có sẵn // ToolStripMenuItem mnuFile = (this.ParentForm.MainMenuStrip.Items["mnuFile"]) as ToolStripMenuItem; // ToolStripMenuItem mnuFileOpen = mnuFile.DropDownItems["mnuFileOpen"] as ToolStripMenuItem; // if (mnuFileOpen == null) // { // Core.Utility.Error("Develop: Không tìm thấy chức năng Open trong menu File"); // return; // } // mnuFileOpen.PerformClick(); // if (mnuFileOpen.Tag == null) // { // Core.Utility.Msg("Quá trình chấm điểm dừng do không có tệp nào *được chọn*."); // } // else // { // _keys = Core.Ref.UniSuite[(int)mnuFileOpen.Tag] as Core.KeySuite; // } // break; // #endregion // case DialogResult.Cancel: // #region Quét ngầm, tạo mới đáp án, lên điểm sau cùng. // return; #endregion #region Chấm gridMark.Hide(); _numberBlurSources = 0; UseWaitCursor = true; Cursor = Cursors.WaitCursor; int ri;// result index in Discovers for (int i = 0; i < _files.Length; i++) { txtLog.AppendText(string.Format("{1}#{0}{1}", i, Environment.NewLine)); Core.Discover result = _automate.OneFile(_files[i], ref _keys); #region Chuyển kết quả vào grid và cập nhật trạng thái if (result != null) { result.date = DateTime.Now; ri = this.Result.AddItem(result); gridMark_Populate(result, ri, _files[i]); } progressBar.Value = (int)((i + 1) * 100.0f / _files.Length); #endregion } #endregion UseWaitCursor = false; Cursor = Cursors.Default; System.Media.SystemSounds.Beep.Play(); if (_numberBlurSources != 0) { Core.Utility.Error(string.Format("Có {0}* bài không nhận dạng được do:{1}" + "1. Giấy bị mờ chặc bẩn (đặc biệt ở bốn góc) {1}" + "2. Khi quét nghiêng quá mức, quăn mép; dữ liệu không đúng chuẩn. {1}" + "3. Học sinh tô không đủ đậm, cần nhắc nhở. {1}" + "4. Mã đề trong đáp án không đúng với mã đề trong bài làm.{1}{1}" + "Những bài chắc chắn có lỗi được tô đỏ, hãy dùng nút 'Bài gốc' để xem lại{1}" + "và hiệu chỉnh cho đúng. Nhấn vào tiêu đề cột điểm sẽ liệt kê chúng.", _numberBlurSources, Environment.NewLine)); } toolBtnRecognize.Enabled = true; toolBtnRecognize.Text = "Chấm lại"; _isRecognized = true; toolBtnRecognize.Click += new EventHandler(toolBtnRecaculate_Click); gridMark.Show(); }