Add detected colors in correct field to scoreboard
This commit is contained in:
parent
e8e368cad7
commit
2462c7474f
@ -1,5 +1,6 @@
|
|||||||
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)]
|
||||||
@ -15,6 +16,12 @@ upper_green = np.array([70, 255, 255])
|
|||||||
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)
|
||||||
@ -91,6 +98,13 @@ def ermittle_position(results, img_width):
|
|||||||
|
|
||||||
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)
|
||||||
@ -106,6 +120,9 @@ if __name__ == "__main__":
|
|||||||
# 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)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from Database.database import QuestionDataBase
|
from Database.database import QuestionDataBase
|
||||||
import random
|
import random
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user