Farberkennung Python?

2 Antworten

import cv2
import numpy as np
import pyautogui


screenshot = pyautogui.screenshot()
screenshot = np.array(screenshot)
frame = cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR)


lower_color = np.array([0, 0, 200])
upper_color = np.array([50, 50, 255])


mask = cv2.inRange(frame, lower_color, upper_color)


if np.any(mask):
    print("Farbe erkannt!")
else:
    print("Farbe nicht erkannt.")


cv2.imshow("Mask", mask)
cv2.waitKey(0)
cv2.destroyAllWindows()