Browse Source

final version of 1,2 or 3

master
David Engert 1 year ago
parent
commit
ad2eea06e5

+ 1
- 0
src_folder/BackEnd/CameraDetection/Track.py View File

import numpy as np import numpy as np
import cv2 import cv2



cap = cv2.VideoCapture(0) cap = cv2.VideoCapture(0)


def nothing(x): def nothing(x):

+ 18
- 28
src_folder/BackEnd/camera.py View File

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

+ 1
- 3
src_folder/BackEnd/router.py View File

from flask import Flask, jsonify, Response, request from flask import Flask, jsonify, Response, request
from camera import Camera from camera import Camera
from game import Game from game import Game
import time


app = Flask(__name__) app = Flask(__name__)


@app.route('/check', methods=['GET']) @app.route('/check', methods=['GET'])
def check(): def check():
my_camera.start_process = True my_camera.start_process = True
my_camera.process()
time.sleep(5)
my_camera.correct_field_frame = my_game.field my_camera.correct_field_frame = my_game.field
my_camera.process()
my_game.set_scoreboard(my_camera.scores) my_game.set_scoreboard(my_camera.scores)
my_camera.start_process = False my_camera.start_process = False
return jsonify(my_game.scoreboard) return jsonify(my_game.scoreboard)

Loading…
Cancel
Save