final version of 1,2 or 3
This commit is contained in:
parent
ddea6ea320
commit
ad2eea06e5
@ -1,6 +1,7 @@
|
|||||||
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):
|
||||||
|
@ -9,17 +9,17 @@ class Camera():
|
|||||||
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.lower_red = np.array([0, 185, 15])
|
||||||
self.upper_red = np.array([255, 255, 255])
|
self.upper_red = np.array([50, 255, 255])
|
||||||
|
|
||||||
self.lower_green = np.array([40, 50, 160])
|
self.lower_green = np.array([20, 70, 25])
|
||||||
self.upper_green = np.array([80, 255, 255])
|
self.upper_green = np.array([65, 200, 255])
|
||||||
|
|
||||||
self.lower_blue = np.array([95, 180, 90])
|
self.lower_blue = np.array([100, 220, 5])
|
||||||
self.upper_blue = np.array([130, 255, 255])
|
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,
|
||||||
@ -27,9 +27,9 @@ class Camera():
|
|||||||
'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)
|
||||||
@ -79,7 +79,7 @@ class Camera():
|
|||||||
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
|
||||||
|
|
||||||
@ -105,31 +105,21 @@ class Camera():
|
|||||||
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:
|
for i in range(0,100):
|
||||||
frame = my_camera.get_frame()
|
frame = self.get_frame()
|
||||||
interested_area = my_camera.range_of_interest(frame, my_camera.correct_field_frame)
|
interested_area = self.range_of_interest(frame, self.correct_field_frame)
|
||||||
my_camera.detect_color(interested_area)
|
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(self.scores)
|
||||||
square_error.append(my_camera.scores)
|
self.take_picture()
|
||||||
|
print(f'{i}. Iteration scores: {self.scores}')
|
||||||
if not my_camera.start_process:
|
self.start_process = False
|
||||||
pass
|
|
||||||
|
|
||||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
|
||||||
my_camera.take_picture()
|
|
||||||
print(my_camera.scores)
|
|
||||||
break
|
|
||||||
|
|
||||||
my_camera.video.release()
|
|
||||||
cv2.destroyAllWindows()
|
|
||||||
|
|
||||||
|
|
||||||
# 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,7 +1,6 @@
|
|||||||
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__)
|
||||||
|
|
||||||
@ -29,9 +28,8 @@ def scoreboard():
|
|||||||
@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…
x
Reference in New Issue
Block a user