python的locateCenterOnScreen怎么定位不到图片

2025-05-09 01:46:37

1、首先安装pycharm,这是实现python编程的常用软件。安装好后,点击打开pycharm。

python的locateCenterOnScreen怎么定位不到图片

2、如图导入pyautogui库,这样才能应用locateCenterOnScreen函数定位图片。

python的locateCenterOnScreen怎么定位不到图片

3、如图输入:pyautogui.locateCenterOnScreen(r'C:\Users\Administrator\desktop\python\bjh_zhijiefabu.png' , grayscale=False, confidence=0.7),其中可选参数confidence的设置是关键,一般很多人不设置,数值在0-1之间,1为100%相似,要求最高,如果太高的话,很容易识别不到图片。适当降低该值,有利于提高成功率,也不宜设置过低,导致错误识别点击。

python的locateCenterOnScreen怎么定位不到图片

4、使用confidence还需要安装opencv,terminal命令行中输入:pip install opencv-python。

python的locateCenterOnScreen怎么定位不到图片

5、上述设置成功运行识图定位一般都会成功。如图所示。

python的locateCenterOnScreen怎么定位不到图片
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢