emgu在图像b中找到图像a [英] emgu finding image a in image b
问题描述
我是emgu的新手,想从何处入手一些建议。
I'm new to emgu and would like some advice on where to start.
我看过形状检测,但是对于我来说它太复杂了需要..我认为..和我的surfexample无法正常工作。我收到此错误:
I've looked through the shape detection but its far too complex for what i need .. i think.. and my surfexample isn't working. I get this error:
无论如何,这就是我想做的事情:查找图像A图像A是一个简单的正方形,它始终具有相同的1个像素灰色边框,并且始终具有相同的大小(我相信),但是内部颜色可以是黑色或大约7种其他颜色中的一种(只能是纯色)。当我按下按钮时,我需要在图像b中找到图像A的坐标。参见下面的图像。
Anyway, this is what i would like to do: Find image A in image B. Image A is a simple square which always has the same grey 1 pixel border and always the same size (i believe) but the inner colour could be black or one of about 7 other colours (only ever a solid colour). i need to find the coordinates of image A in image b when i press a button. see the below images.
图像 B
并且
图片 A
< img src = https://i.stack.imgur.com/HJ29C.png alt =图像a>
推荐答案
鸡皮
答案是正确的,但我认为编写一些代码也可能会有所帮助。这是我的代码,使用 MatchTemplate
检测源图像(图像B)中的模板(图像A)。正如 Goosebumps
所指出的那样,您可能希望在模板周围包括一些灰色。
Goosebumps
answer is correct, but I thought that a bit of code might be helpful also. This is my code using MatchTemplate
to detect a template (image A) inside a source image (image B). As Goosebumps
noted, you probably want to include some grey around the template.
Image<Bgr, byte> source = new Image<Bgr, byte>(filepathB); // Image B
Image<Bgr, byte> template = new Image<Bgr, byte>(filepathA); // Image A
Image<Bgr, byte> imageToShow = source.Copy();
using (Image<Gray, float> result = source.MatchTemplate(template, Emgu.CV.CvEnum.TM_TYPE.CV_TM_CCOEFF_NORMED))
{
double[] minValues, maxValues;
Point[] minLocations, maxLocations;
result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);
// You can try different values of the threshold. I guess somewhere between 0.75 and 0.95 would be good.
if (maxValues[0] > 0.9)
{
// This is a match. Do something with it, for example draw a rectangle around it.
Rectangle match = new Rectangle(maxLocations[0], template.Size);
imageToShow.Draw(match, new Bgr(Color.Red), 3);
}
}
// Show imageToShow in an ImageBox (here assumed to be called imageBox1)
imageBox1.Image = imageToShow;
这篇关于emgu在图像b中找到图像a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!