admin管理员组文章数量:1400201
enter image description here
I'm making a bot for a game, and I need it to find buttons and click on them. I decided to search for buttons on the screen using the example, but matchTemplate does not always accurately find buttons, and I understand that if the image size decreases or increases, then this function will not work. I would like to know if there are any other solutions to my problem.
ScreenShot();
Image<Bgr, byte> source = new Image<Bgr, byte>(ScreenShot());
Image<Gray, byte> hsvSource = source.Convert<Gray, byte>();
Image<Bgr, byte> template = new Image<Bgr, byte>(pathToTemplate); // Image A
Image<Gray, byte> hsvTemplate = template.Convert<Gray, byte>();
Image<Bgr, byte> imageToShow = source.Copy();
using (Image<Gray, float> result = hsvSource.MatchTemplate(hsvTemplate, TemplateMatchingType.CcoeffNormed))
{
double[] minValues, maxValues;
Point[] minLocations, maxLocations;
result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);
if (maxValues[0] > 0.8)
{
Rectangle match = new Rectangle(maxLocations[0], template.Size);
//MessageBox.Show($"{match.X + offsetX} X {match.Y + offsetY}");
//Clicker(match.X + offsetX, match.Y + offsetY);
TestFunctions.Click(match.X + offsetX, match.Y + offsetY);
//TestFunctions.ClikerAlt(match.X + offsetX, match.Y + offsetY);
imageToShow.Draw(match, new Bgr(Color.Red), 3);
return;
}
}
public string ScreenShot()
{
Rectangle bounds = Screen.AllScreens[0].Bounds;
Bitmap bitmap = new Bitmap(1500, 800, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
}
string screenshotPath =Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "screenshot.png");
bitmap.Save(screenshotPath, ImageFormat.Png);
return screenshotPath;
}
本文标签: cWhat can replace the matchTemplate function from EmguCVStack Overflow
版权声明:本文标题:c# - What can replace the matchTemplate function from EmguCV? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744147212a2592893.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论