|
|
|
|
|
|
|
|
import cv2 |
|
|
import cv2 |
|
|
import numpy as np |
|
|
import numpy as np |
|
|
|
|
|
from game import Game |
|
|
# from Track import nothing |
|
|
# from Track import nothing |
|
|
# Farbwerte für die Erkennung (Beispiel: Rot, Grün, Blau) |
|
|
# Farbwerte für die Erkennung (Beispiel: Rot, Grün, Blau) |
|
|
colors = [(0, 0, 255), (0, 255, 0), (255, 0, 0)] |
|
|
colors = [(0, 0, 255), (0, 255, 0), (255, 0, 0)] |
|
|
|
|
|
|
|
|
lower_blue = np.array([90, 100, 100]) |
|
|
lower_blue = np.array([90, 100, 100]) |
|
|
upper_blue = np.array([130, 255, 255]) |
|
|
upper_blue = np.array([130, 255, 255]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CURRENT_SCORES= {'score_red': 0, |
|
|
|
|
|
'score_green': 0, |
|
|
|
|
|
'score_blue': 0 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
# Funktion zur Farberkennung |
|
|
# Funktion zur Farberkennung |
|
|
def erkennung_farben(img): |
|
|
def erkennung_farben(img): |
|
|
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) |
|
|
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return positions |
|
|
return positions |
|
|
|
|
|
|
|
|
|
|
|
def count_colors(red: int, green: int, blue: int) -> None: |
|
|
|
|
|
currrent_scores = {'score_red': red, |
|
|
|
|
|
'score_green': green, |
|
|
|
|
|
'score_blue': blue |
|
|
|
|
|
} |
|
|
|
|
|
Game.set_scoreboard(currrent_scores) |
|
|
|
|
|
|
|
|
# Hauptprogramm |
|
|
# Hauptprogramm |
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
# Videoquelle öffnen (kann auch eine Bilddatei sein) |
|
|
# Videoquelle öffnen (kann auch eine Bilddatei sein) |
|
|
|
|
|
|
|
|
# Farben erkennen |
|
|
# Farben erkennen |
|
|
farben_img, ergebnisse, count_red, count_green, count_blue = erkennung_farben(frame) |
|
|
farben_img, ergebnisse, count_red, count_green, count_blue = erkennung_farben(frame) |
|
|
|
|
|
|
|
|
|
|
|
# Add counted colours to the scoreboard in the correct field |
|
|
|
|
|
count_colors(count_red, count_green, count_blue) |
|
|
|
|
|
|
|
|
# Anzahl der Farben anzeigen |
|
|
# Anzahl der Farben anzeigen |
|
|
cv2.putText(farben_img, f"Rot: {count_red}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, colors[0], 2) |
|
|
cv2.putText(farben_img, f"Rot: {count_red}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, colors[0], 2) |
|
|
cv2.putText(farben_img, f"Gruen: {count_green}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 1, colors[1], 2) |
|
|
cv2.putText(farben_img, f"Gruen: {count_green}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 1, colors[1], 2) |