added handshake code
This commit is contained in:
parent
b4e623c59f
commit
139acca29e
3 changed files with 24 additions and 14 deletions
|
@ -20,10 +20,20 @@ classNames = ["person", "bicycle", "car", "motorbike", "aeroplane", "bus", "trai
|
||||||
|
|
||||||
def main(websocket_addr):
|
def main(websocket_addr):
|
||||||
# Connect to websocket server
|
# Connect to websocket server
|
||||||
# ws = create_connection(websocket_addr)
|
ws = create_connection(websocket_addr)
|
||||||
|
|
||||||
|
handshake = ws.recv()
|
||||||
|
|
||||||
|
if handshake == "Type?":
|
||||||
|
ws.send("Type: Automated")
|
||||||
|
else:
|
||||||
|
ws.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
print("Handshake complete")
|
||||||
|
|
||||||
# Load YOLO model
|
# Load YOLO model
|
||||||
model = YOLO('yolov8s.pt') # Load an official Detect model
|
model = YOLO('yolov8x.pt') # Load an official Detect model
|
||||||
|
|
||||||
# Open webcam
|
# Open webcam
|
||||||
cap = cv2.VideoCapture(0)
|
cap = cv2.VideoCapture(0)
|
||||||
|
@ -32,19 +42,20 @@ def main(websocket_addr):
|
||||||
|
|
||||||
while cap.isOpened():
|
while cap.isOpened():
|
||||||
ret, frame = cap.read()
|
ret, frame = cap.read()
|
||||||
|
frame = cv2.resize(frame, (640, 480))
|
||||||
if not ret:
|
if not ret:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Perform object detection
|
# Perform object detection
|
||||||
results = model.predict(frame)
|
results = model.track(frame, persist=True)
|
||||||
|
|
||||||
max_x1, max_y1, max_x2, max_y2 = 0
|
|
||||||
|
|
||||||
for r in results:
|
for r in results:
|
||||||
|
lines = ""
|
||||||
boxes = r.boxes
|
boxes = r.boxes
|
||||||
for box in boxes:
|
for box in boxes:
|
||||||
if box.cls[0].item() == 0:
|
if box.cls[0].item() == 0 and not box.id is None:
|
||||||
# bounding box
|
# bounding box
|
||||||
|
id = box.id.int().cpu().tolist()
|
||||||
x1, y1, x2, y2 = box.xyxy[0]
|
x1, y1, x2, y2 = box.xyxy[0]
|
||||||
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) # convert to int values
|
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) # convert to int values
|
||||||
|
|
||||||
|
@ -56,20 +67,19 @@ def main(websocket_addr):
|
||||||
|
|
||||||
# object details
|
# object details
|
||||||
org = [x1, y1]
|
org = [x1, y1]
|
||||||
|
org2 = [x1, y1+50]
|
||||||
font = cv2.FONT_HERSHEY_SIMPLEX
|
font = cv2.FONT_HERSHEY_SIMPLEX
|
||||||
fontScale = 1
|
fontScale = 1
|
||||||
color = (255, 0, 0)
|
color = (255, 0, 0)
|
||||||
|
color_w = (255, 255, 255)
|
||||||
thickness = 2
|
thickness = 2
|
||||||
|
|
||||||
cv2.putText(frame, classNames[cls], org, font, fontScale, color, thickness)
|
cv2.putText(frame, classNames[cls], org, font, fontScale, color, thickness)
|
||||||
|
cv2.putText(frame, str(id), org2, font, fontScale, color_w, thickness)
|
||||||
|
|
||||||
if (x2-x1) * (y2 - y1):
|
lines += f"{id} {x1}:{y1} {x2}:{y2}\n"
|
||||||
max_x1 = x1
|
|
||||||
max_x2 = x2
|
|
||||||
max_y1 = y1
|
|
||||||
max_y2 = y2
|
|
||||||
|
|
||||||
print(f"{max_x1}:{max_y1}, {max_x2}:{max_y2}")
|
ws.send(lines)
|
||||||
|
|
||||||
cv2.imshow('Webcam', frame)
|
cv2.imshow('Webcam', frame)
|
||||||
if cv2.waitKey(1) == ord('q'):
|
if cv2.waitKey(1) == ord('q'):
|
||||||
|
|
|
@ -10,5 +10,5 @@ model = YOLO('yolov8s.pt') # Load an official Detect model
|
||||||
|
|
||||||
|
|
||||||
# Run inference on 'bus.jpg' with arguments
|
# Run inference on 'bus.jpg' with arguments
|
||||||
for i in model.predict('D:\Projects\FaceTrackingCamerav3\YOLO python\kevin-center-camera-position.mp4', show=True, save=True, save_frames=True, save_txt=True, conf=0.5, stream=True):
|
for i in model.predict("D:\Projects\FaceTrackingCamerav3\Raymond.mp4", save=True, save_frames=True, save_txt=True, conf=0.5, stream=True):
|
||||||
continue
|
continue
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2278b4cd79c9ec0267198eba9f92b4e4ad4aeb78
|
Subproject commit ef96409082241db6ff012dc2d898894e6efde3a3
|
Loading…
Reference in a new issue