|
|
|
|
|
|
|
|
self.colors = [(0, 0, 255), (0, 255, 0), (255, 0, 0)] |
|
|
self.colors = [(0, 0, 255), (0, 255, 0), (255, 0, 0)] |
|
|
self.color_names = ["Rot", "Gruen", "Blau"] |
|
|
self.color_names = ["Rot", "Gruen", "Blau"] |
|
|
|
|
|
|
|
|
self.lower_red = np.array([80, 160, 150]) |
|
|
|
|
|
self.upper_red = np.array([255, 255, 255]) |
|
|
|
|
|
|
|
|
self.lower_red = np.array([0, 185, 15]) |
|
|
|
|
|
self.upper_red = np.array([50, 255, 255]) |
|
|
|
|
|
|
|
|
self.lower_green = np.array([40, 50, 160]) |
|
|
|
|
|
self.upper_green = np.array([80, 255, 255]) |
|
|
|
|
|
|
|
|
self.lower_green = np.array([20, 70, 25]) |
|
|
|
|
|
self.upper_green = np.array([65, 200, 255]) |
|
|
|
|
|
|
|
|
self.lower_blue = np.array([95, 180, 90]) |
|
|
|
|
|
self.upper_blue = np.array([130, 255, 255]) |
|
|
|
|
|
|
|
|
self.lower_blue = np.array([100, 220, 5]) |
|
|
|
|
|
self.upper_blue = np.array([255, 255, 255]) |
|
|
|
|
|
|
|
|
self.video = cv2.VideoCapture(0) |
|
|
self.video = cv2.VideoCapture(0) |
|
|
self.start_process = False |
|
|
|
|
|
|
|
|
self.start_process = True |
|
|
self.correct_field_frame = 0 |
|
|
self.correct_field_frame = 0 |
|
|
self.mean_error = [] |
|
|
self.mean_error = [] |
|
|
self.scores = {'score_red': 0, |
|
|
self.scores = {'score_red': 0, |
|
|
|
|
|
|
|
|
'score_blue': 0 |
|
|
'score_blue': 0 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def get_frame(self) -> np.ndarray: |
|
|
|
|
|
|
|
|
def get_frame(self): |
|
|
try: |
|
|
try: |
|
|
_, self.image = self.video.read(1) |
|
|
|
|
|
|
|
|
_, self.image = self.video.read(0) |
|
|
except Exception as err: |
|
|
except Exception as err: |
|
|
print("Can not capture the video..\n") |
|
|
print("Can not capture the video..\n") |
|
|
print(err) |
|
|
print(err) |
|
|
|
|
|
|
|
|
def current_score(self, scores: dict): |
|
|
def current_score(self, scores: dict): |
|
|
return scores |
|
|
return scores |
|
|
|
|
|
|
|
|
def range_of_interest(self, frame: np.ndarray, correct_field: int): |
|
|
|
|
|
|
|
|
def range_of_interest(self, frame, correct_field: int): |
|
|
num_windows_in_y = 1 |
|
|
num_windows_in_y = 1 |
|
|
num_windows_in_x = 3 |
|
|
num_windows_in_x = 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.current_score[team_color] = round(error) |
|
|
self.current_score[team_color] = round(error) |
|
|
|
|
|
|
|
|
def process(self): |
|
|
def process(self): |
|
|
my_camera = Camera() |
|
|
|
|
|
square_error = [] |
|
|
square_error = [] |
|
|
|
|
|
|
|
|
while my_camera.start_process: |
|
|
|
|
|
frame = my_camera.get_frame() |
|
|
|
|
|
interested_area = my_camera.range_of_interest(frame, my_camera.correct_field_frame) |
|
|
|
|
|
my_camera.detect_color(interested_area) |
|
|
|
|
|
|
|
|
for i in range(0,100): |
|
|
|
|
|
frame = self.get_frame() |
|
|
|
|
|
interested_area = self.range_of_interest(frame, self.correct_field_frame) |
|
|
|
|
|
self.detect_color(interested_area) |
|
|
|
|
|
|
|
|
cv2.line(img=frame, pt1=(frame.shape[1]//3, 0), pt2=(frame.shape[1]//3, frame.shape[0]), color=(0, 0, 0), thickness=2) |
|
|
cv2.line(img=frame, pt1=(frame.shape[1]//3, 0), pt2=(frame.shape[1]//3, frame.shape[0]), color=(0, 0, 0), thickness=2) |
|
|
cv2.line(img=frame, pt1=(2 * frame.shape[1]//3, 0), pt2=(2 * frame.shape[1]//3, frame.shape[0]), color=(0, 0, 0), thickness=2) |
|
|
cv2.line(img=frame, pt1=(2 * frame.shape[1]//3, 0), pt2=(2 * frame.shape[1]//3, frame.shape[0]), color=(0, 0, 0), thickness=2) |
|
|
cv2.imshow("Kamera 1,2 oder 3", frame) |
|
|
cv2.imshow("Kamera 1,2 oder 3", frame) |
|
|
|
|
|
|
|
|
print(my_camera.scores) |
|
|
|
|
|
square_error.append(my_camera.scores) |
|
|
|
|
|
|
|
|
|
|
|
if not my_camera.start_process: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
if cv2.waitKey(1) & 0xFF == ord('q'): |
|
|
|
|
|
my_camera.take_picture() |
|
|
|
|
|
print(my_camera.scores) |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
my_camera.video.release() |
|
|
|
|
|
cv2.destroyAllWindows() |
|
|
|
|
|
|
|
|
square_error.append(self.scores) |
|
|
|
|
|
self.take_picture() |
|
|
|
|
|
print(f'{i}. Iteration scores: {self.scores}') |
|
|
|
|
|
self.start_process = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# nur zum testen: my_camera.start_process auf True setzen und correct_field_frame zwischen 1 und 3 wählen |
|
|
# nur zum testen: my_camera.start_process auf True setzen und correct_field_frame zwischen 1 und 3 wählen |