use*_*674 10 c# surf emgucv matchtemplate
我是emgu的新手,想要从哪里开始.
我已经看过形状检测,但它太复杂了我需要的东西..我想..而且我的例子不起作用.我收到此错误:
无论如何,这就是我想要做的:在图像B中找到图像A.图像A是一个简单的正方形,总是具有相同的灰色1像素边框并且总是相同的尺寸(我相信)但内部颜色可能是黑色或大约7种其他颜色之一(只有纯色).当我按下按钮时,我需要在图像b中找到图像A的坐标.见下图.
图B
和
图片A
Osk*_*kne 22
Goosebumps答案是正确的,但我认为一些代码也可能有所帮助.这是我MatchTemplate用于检测源图像(图像B)内的模板(图像A)的代码.如上所述Goosebumps,您可能希望在模板周围添加一些灰色.
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;
Run Code Online (Sandbox Code Playgroud)