Найти - Пользователи
Полная версия: Помогите сделать определение одного или другого цвета
Начало » Python для новичков » Помогите сделать определение одного или другого цвета
1
F1G1
 import time 
import numpy as np 
import pyscreenshot as ImageGrab
import cv2
import os 
import pytesseract  
import pyautogui 
import pyperclip
from mss import mss
from PIL import Image
monitor = {
    "left": 8,
    "top": 31,
    "width": 845,
    "height": 785,
}
# Поиск цвета на экране
def find_color(our_color, monitor={}):
    # Возмём кусок экрана
    m = mss()
    # Получаем пиксель с экрана монитора
    img = m.grab(monitor)
    # Преобразуем этот пиксель в матрицу
    img_arr = np.array(img)
    # Поиск цвета (b, g, r, alpha)
    our_map = (our_color[2], our_color[1], our_color[0], 255)
    indexes = np.where(np.all(img_arr == our_map, axis=-1))
    our_crd = np.transpose(indexes)
    return our_crd
# Искомый цвет, вот здесь мне нужно сделать несколько проверок на цвета, типо нет первого тогда проверка на второй, а если вообще ничего нет, то  pyautogui.leftClick()
our_color = [3, 121, 229]
while True:
    time1 = time.time()
    result = find_color(our_color, monitor)
    time2 = time.time()
    if result.__len__():
        xin = result[0][1] + monitor.get('left')
        yin = result[0][0] + monitor.get('top')
        print(time2 - time1, [xin, yin])
        break 
    else:
    	pyautogui.leftClick(717, 314)
xina = int(xin) + 275
yina = int(yin) + 58
print(xina, yina)
print(xin, yin)
filename = 'Image.png'
x = 1 
last_time = time.time()
m = ImageGrab.grab(bbox=(xin, yin, xina, yina)) 
m.save('Image.png')
cv2.cvtColor(np.array(m), cv2.COLOR_BGR2GRAY)	
m = cv2.imread('Image.png')
text = pytesseract.image_to_string(m)
xam1816
может как-нибудь так,

 def f(color):
	colors = [(3, 121, 229)]
	if color in colors:
		return True
	else:
		return False
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB