python找图
import cv2
from PIL import ImageGrab
import numpy as np
import pyautogui
if __name__ == '__main__':
im = ImageGrab.grab()
im.save('./res/screen.png', 'png')
img_rgb = cv2.imread('./res/screen.png')
# 所有操作在灰度版中进行
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('./check/icon.png', 0)
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.9
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
print(pt[0], pt[1])
# pyautogui.moveTo(pt[0] + template.shape[0] / 2, pt[1] + template.shape[1] / 2)
pyautogui.doubleClick(pt[0] + template.shape[0] / 2, pt[1] + template.shape[1] / 2)
print('over')
cv2.imread解释
def imread(filename: Any,
flags: Any = None) -> None
filename:图片的绝对路径或者相对路径。 ps:路径中不能出现中文!
flags:图像的通道和色彩信息(默认值为1),即彩色图片。
flags = -1, 8位深度,原通道
flags = 0, 8位深度,1通道
flags = 1, 8位深度,3通道
flags = 2, 原深度, 1通道
flags = 3, 原深度, 3通道
flags = 4, 8位深度,3通道
那图像的深度,通道信息指的是什么呢?
图片是由一个个像素点构成的,所有不同颜色的像素点构成了一副完整的图像,计算机中所有图片是以二进制存储 的
1 bit 存储像素点的取值范围为0~1,人眼看来这幅图片是黑色或者白色。
4 bit 存储像素点的取值范围为0~15
8 bit 存储像素点的取值范围为 0~255
… …
以此类推,我们把计算机存储单个像素点所用到的bit为称之为图像的深度.
浙公网安备 33010602011771号