我正在尝试找到一个截图中的图像,并在它周围画一个矩形。我不明白的是,如何解释我的result
矩阵来识别包含图像的区域。
下面的代码将绘制一个矩形,但它并不在正确的位置,我不知道这是因为我没有正确使用我的result
还是其他什么原因。
using (Mat templateImage = CvInvoke.Imread("\\top_1.png", Emgu.CV.CvEnum.ImreadModes.AnyColor))
using (Mat inputImage = CvInvoke.Imread(AppDomain.CurrentDomain.BaseDirectory + "\\currentScreen.png", Emgu.CV.CvEnum.ImreadModes.AnyColor))
{
Mat result = new Mat();
CvInvoke.MatchTemplate(inputImage, templateImage, result, Emgu.CV.CvEnum.TemplateMatchingType.SqdiffNormed);
result.MinMax(out double[] minVal, out double[] maxVal, out Point[] minLoc, out Point[] maxLoc);
int x = minLoc[0].X;
int y = minLoc[0].Y;
int w = maxLoc[0].X - minLoc[0].X;
int h = maxLoc[0].Y - minLoc[0].Y;
Form f = new Form
{
BackColor = Color.Red,
//TransparencyKey = Color.Red,
FormBorderStyle = FormBorderStyle.None,
TopMost = true,
Location = new Point(x, y),
Size = new Size(w, h)
};
Application.EnableVisualStyles();
Application.Run(f);
}
发布于 2020-01-24 08:27:55
我唯一看到的是表单的位置,您必须将StarPosition设置为手动
Form f = new Form
{
StartPosition = FormStartPosition.Manual,
BackColor = Color.Red,
//TransparencyKey = Color.Red,
FormBorderStyle = FormBorderStyle.None,
TopMost = true,
Location = new Point(x, y),
Size = new Size(w, h)
};
https://stackoverflow.com/questions/59888044
复制相似问题