Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python脚本,用于标识图像何时出现在屏幕上的某个区域中_Python_Opencv_Python Imaging Library_Pyautogui - Fatal编程技术网

python脚本,用于标识图像何时出现在屏幕上的某个区域中

python脚本,用于标识图像何时出现在屏幕上的某个区域中,python,opencv,python-imaging-library,pyautogui,Python,Opencv,Python Imaging Library,Pyautogui,所以我想让程序在屏幕上的某个区域主动寻找我给它的图像。如果屏幕上有代码,我想让它运行;如果屏幕上没有代码,我想让其他代码运行 我一直试图用pyautogui实现这一点,但它似乎不起作用 pyautogui.locateCenterOnScreen('F.png', confidence = .7, region = (275, 259, 1011, 482)) 当我打印此文件时,它找不到图像,输出为:None 当我打印它时,它确实找到了它将输出的图像:点(x=297,y=266) 所以我建立了

所以我想让程序在屏幕上的某个区域主动寻找我给它的图像。如果屏幕上有代码,我想让它运行;如果屏幕上没有代码,我想让其他代码运行

我一直试图用pyautogui实现这一点,但它似乎不起作用

pyautogui.locateCenterOnScreen('F.png', confidence = .7, region = (275, 259, 1011, 482))
当我打印此文件时,它找不到图像,输出为:None 当我打印它时,它确实找到了它将输出的图像:点(x=297,y=266)

所以我建立了一个if语句

findImg = pyautogui.locateCenterOnScreen('F.png', confidence = .7, region = (275, 259, 1011, 482))

print (findImg)

if findImg == 'None':
   print ("not found")

这将打印,但不会打印未找到


我如何解决这个问题,或者是否有更好的方法解决这个问题?

这是因为
'None'
在引号中,所以它是一个字符串,而不是
None
。如果findImg==None,请尝试
。虽然更好的方法可能是将
print(findImg)
移动到
块,这样它就不会打印“None”和“notfound”

如果findImg==无:
打印(“未找到”)
其他:
打印(findImg)

发生这种情况是因为
'None'
在引号中,所以它是一个字符串,而不是
None
。如果findImg==None,请尝试
。虽然更好的方法可能是将
print(findImg)
移动到
块,这样它就不会打印“None”和“notfound”

如果findImg==无:
打印(“未找到”)
其他:
打印(findImg)

不熟悉代码中使用的库。但是None通常是关键字而不是字符串。尝试修改if语句,因为'if findImg is None'可能会解决此问题。不熟悉代码中使用的库。但是None通常是关键字而不是字符串。尝试修改if语句,因为'if findImg is None'可能会解决此问题。