回复 12楼Twang的帖子
兄弟不好意思,一直在给你调试程序。
关键代码如下:
- private void button1_Click(object sender, EventArgs e)
- {
- //LeadRect rc_cor = new LeadRect(0, 0, beforePic.Image.Width, beforePic.Image.Height);
- //创建搜索目标区域
- LeadRect[] rc_cor = new LeadRect[2];
- rc_cor[0] = new LeadRect(14, 24, 22, 30);
- rc_cor[1] = new LeadRect(14, 222, 60, 37);
- for (int i = 0; i < rc_cor.Length; i++)
- {
- //添加区域到右侧图片浏览器
- afterPic.Image.AddRectangleToRegion(null, rc_cor[i], RasterRegionCombineMode.Set);
- //根据右侧图片区域克隆图片,赋值给左侧图片浏览器
- beforePic.Image = afterPic.Image.Clone(rc_cor[i]);
- afterPic.Image.MakeRegionEmpty();
- //CorrelationCommand 用于搜索图片
- CorrelationCommand cmd = new CorrelationCommand();
- cmd.CorrelationImage = beforePic.Image.Clone();
- cmd.Points = new LeadPoint[90];
- cmd.Threshold = Convert.ToInt32(this.txtThreshold.Text);
- cmd.XStep = 2;
- cmd.YStep = 1;
- cmd.Run(afterPic.Image);
- //afterPic.Image.MakeRegionEmpty();
- LogicalSize size = new LogicalSize(Convert.ToDouble(beforePic.Image.ImageWidth), Convert.ToDouble(beforePic.Image.ImageHeight), LogicalUnit.Pixel);
- //此处用户绘制图片搜索结果,背景色
- for (int i_cor = 0; i_cor < cmd.NumberOfPoints; i_cor++)
- {
- rc_cor[i] = new LeadRect(cmd.Points[i_cor].X, cmd.Points[i_cor].Y, beforePic.Image.Width, beforePic.Image.Height);
- LogicalPoint logPt = new LogicalPoint(cmd.Points[i_cor]);
- DrawRect(new LogicalRectangle(logPt, size), Color.Red, true);
- }
- afterPic.Refresh();
- }
- }
复制代码
Demo:
|