简体   繁体   English

PyAutoGUI图像识别-像素颜色匹配存在轻微问题

[英]PyAutoGUI Image Recognition - Slight issue with pixel color matching

I am trying to stop a possible block in my bot program by using PyAutoGUI's Image Recognition function ( pyautogui.locateCenterOnScreen ) to recognize a simple 'OK' button, in order to get rid of the possible block error message. 我试图通过使用PyAutoGUI的图像识别功能( pyautogui.locateCenterOnScreen )来识别一个简单的“ OK”按钮,从而在我的机器人程序中停止一个可能的块,以摆脱可能的块错误消息。 However, the function only sometimes works as I have found out by screenshotting different error messages and comparing the pixel color side by side. 但是,该功能只有在通过截取不同的错误消息并并排比较像素颜色发现时才起作用。 The result I have found out is that the pixel color on two different 'OK' buttons are usually off by 1, explaining the image recognition function returning None most of the time. 我发现的结果是,两个不同的“确定”按钮上的像素颜色通常偏离1,这说明图像识别功能大多数时候返回None I would like to be able to recognize the image even if the color is off by 1 or 2 pixels. 即使颜色偏离1或2像素,我也希望能够识别图像。 I understand there is the tolerance keyword argument, but the position of the button changes on the screen, making it difficult to use the getpixel function, and you can't use tolerance with locateCenterOnScreen (to my understanding). 据我所知还有就是tolerance关键字参数,但屏幕上的按钮的位置发生变化,因此很难用getpixel功能,您不能使用tolerancelocateCenterOnScreen (我的理解)。 Would there be any suggestions as to how i can get across this problem? 关于如何解决这个问题,会有什么建议吗? Thanks in advance. 提前致谢。

Try this below ( see here: http://pyautogui.readthedocs.io/en/latest/screenshot.html ) 请在下面尝试(请参见此处: http : //pyautogui.readthedocs.io/en/latest/screenshot.html

在此处输入图片说明

From the comment I know that you have tried that and this didn't solved the issue in your case. 从评论中我知道您已经尝试过了,但这并没有解决您的问题。

Another idea which could help is when you crop the image of the button down to an absolute minimum required to find it on screen. 另一个可能有用的想法是,当您将按钮的图像裁剪到在屏幕上找到它所需的绝对最小值时。 Usually the colors near the center are more "stable" than shadows. 通常,靠近中心的颜色比阴影更“稳定”。

From the comment I know, that this hasn't solved your issue either. 从我知道的评论来看,这也没有解决您的问题。

Do you allow TRANSPARENCY for Windows in your OS (transparency is when you can "see" through what the current application displays what is in background of the window of this application - is a feature which is a default value in many versions of newest operating systems)? 您是否在操作系统中允许Windows的TRANSPARENCY (透明度是当您可以“查看”当前应用程序在此应用程序窗口的背景中显示的内容时的透明性-此功能在许多最新版本的操作系统中都是默认值) )?

From the comment I know you do. 从评论中我知道你知道。

This can lead to severe recognition problems. 这可能导致严重的识别问题。 Reducing (to what level?) transparency didn't solved the issue, what means that the only right way to go is: 将透明度降低到什么水平并不能解决问题,这意味着唯一正确的方法是:

Switch the transparency feature OFF to get stable colors 关闭透明度功能以获得稳定的色彩

That's it - problem solved (how to do that for your specific system is another question not related to the subject of image recognition). 就这样-问题解决了 (如何针对您的特定系统执行此操作是另一个与图像识别主题无关的问题)。

All or one from this above should solve your problem and if not you will be probably forced to do own image recognition using another image processing tools next to pyautogui . 上面的全部或一个应该可以解决您的问题,否则,您可能会被迫使用pyautogui旁边的其他图像处理工具来进行自己的图像识别。

ADDENDUM: The shape and color of an [OK] button can depend on many things. 附录:[确定]按钮的形状和颜色可能取决于很多因素。 If displayed in an Internet browser it can change its size with resizing the page. 如果显示在Internet浏览器中,则可以通过调整页面大小来更改其大小。 If a user dialog is created by different applications the shape and color of an [OK] button can also be different if the application doesn't use the system stadards. 如果用户对话框是由不同的应用程序创建的,则在应用程序不使用系统标准控件的情况下,[确定]按钮的形状和颜色也可能不同。 And as said above the colors can vary if the system uses the transparency feature. 如上所述,如果系统使用透明度功能,则颜色可能会发生变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 pyautogui 进行 Python 图像识别 - Python image recognition with pyautogui 图像识别-pyautogui - Image Recognition - pyautogui 图像颜色识别,一般颜色 - Image color recognition, the general color PyAutoGUI 定位命令返回错误的图像识别坐标 - PyAutoGUI locate command returning incorrect coordinates for image recognition 如何在图像中找到像素颜色? - How to find pixel color in image? Pyautogui:具有图像识别功能的自动点击器如何制作仅在识别图像时才运行的 function? - Pyautogui : Autoclicker with Image recognition How do I make a function I made only run if an image is recognised? 使用PyAutoGUI在屏幕上定位图像,无论色调/亮度如何 - Using PyAutoGUI to locate an image on screen regardless of the color tone / brightness 我正在尝试使用 pyautogui 制作一个机器人,它根据像素颜色拍摄目标,但是一旦机器人找到该像素,光标就会卡住 - I'm trying to make a bot with pyautogui that shoots targets based on their pixel color but the cursor gets stuck once the bot finds that pixel 我正在尝试使用 pyautogui 图像识别,我的退出代码为 0,但它不起作用 - i am trying to use pyautogui image recognition, and im coming out with a exit code of 0, but its not working 用第 0 个像素的颜色填充 10 个像素的图像 - Pad an image with 10 Pixel with color of 0th pixel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM