private void m_btnSaveScreenShot_Click_1(object sender, EventArgs e) { try { if (m_shotNum == 2) { HOperatorSet.GenRectangle1(out rectangle, SS_Row[0], SS_Col[0], SS_Row[1], SS_Col[1]); //Bitmap grabimage = (Bitmap)m_picShowCorrectImage.InitialImage; HObject grab; ImageConvert.Bitmap2HObjectBpp24(TransImage, out grab); HOperatorSet.ReduceDomain(grab, rectangle, out ho_ScreenShot); HOperatorSet.CropDomain(ho_ScreenShot, out ho_ScreenShot); ImageConvert.HObject2Bpp8(ho_ScreenShot, out ScreenShot); //先传递给camera,camera再传递给imagealg camera.TargetLocation[0].X = (int)SS_Col[0].D; camera.TargetLocation[0].Y = (int)SS_Row[0].D; camera.TargetLocation[1].X = (int)SS_Col[1].D; camera.TargetLocation[1].Y = (int)SS_Row[1].D; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void m_btnMatch_Click(object sender, EventArgs e) { HTuple hv_Column, hv_Score, hv_Row; //Bitmap temp = (Bitmap)m_picShowCorrectImage.InitialImage; HObject ho_Match; ImageConvert.Bitmap2HObjectBpp24(TransImage, out ho_Match); //ImageConvert.Bitmap2HObjectBpp8(ScreenShot, out ho_ScreenShot); MatchAlg.ImageLocation(ho_ScreenShot, ho_Match, out hv_Row, out hv_Column, out hv_Score); if (hv_Score > 0.5) { pictureBox2.Refresh(); pictureBox2.Image = TransImage; Graphics g = pictureBox2.CreateGraphics(); Pen p = new Pen(Color.Red, 2); HTuple height = SS_Row[1] - SS_Row[0]; HTuple width = SS_Col[1] - SS_Col[0]; width = width * pictureBox2.Width / TerminalWidth; height = height * pictureBox2.Height / TerminalHeight; hv_Column = hv_Column * pictureBox2.Width / TerminalWidth - width / 2; hv_Row = hv_Row * pictureBox2.Height / TerminalHeight - height / 2; //以矩形左上角的点为基准 pictureBox2.Update(); g.DrawRectangle(p, hv_Column.TupleInt(), hv_Row.TupleInt(), width.TupleInt(), height.TupleInt()); } else { MessageBox.Show("无法定位!"); pictureBox2.Refresh(); } }