v2 working
This commit is contained in:
68
record.py
Normal file
68
record.py
Normal file
@ -0,0 +1,68 @@
|
||||
import pickle
|
||||
import sys
|
||||
|
||||
import torch
|
||||
from ultralytics import YOLO
|
||||
import cv2
|
||||
import time
|
||||
|
||||
import utils
|
||||
from calculate import normalize_pose, compare_poses_boolean
|
||||
from draw import draw_new
|
||||
from utils import find_closest
|
||||
from video_methods import initialize_method
|
||||
|
||||
model = YOLO("yolo11x-pose.pt")
|
||||
model.to(torch.device('cuda:0'))
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
method_type = sys.argv[1]
|
||||
else:
|
||||
print("Podaj argument 'cam', albo 'net'.")
|
||||
exit(1)
|
||||
|
||||
method = initialize_method(method_type)
|
||||
|
||||
do_pose_shot = False
|
||||
startTime = 0
|
||||
|
||||
def click_event(event, x, y, flags, param):
|
||||
global do_pose_shot, startTime
|
||||
|
||||
if event == cv2.EVENT_LBUTTONDOWN: # lewy przycisk myszy
|
||||
do_pose_shot = not do_pose_shot
|
||||
if do_pose_shot:
|
||||
startTime = time.time()
|
||||
|
||||
def main():
|
||||
moves = []
|
||||
|
||||
while True:
|
||||
frame = method.receive_frame()
|
||||
|
||||
frame = cv2.flip(frame, 1)
|
||||
results = model(frame, verbose=False)
|
||||
|
||||
if len(results) != 0:
|
||||
|
||||
result = results[0]
|
||||
kpts = result.keypoints.data[0] if len(result.keypoints.data) else None
|
||||
|
||||
if kpts is None:
|
||||
continue
|
||||
|
||||
img = frame
|
||||
|
||||
if do_pose_shot:
|
||||
moves.append((time.time() - startTime, normalize_pose(result.keypoints.xy.cpu().numpy()[0]), result.keypoints.xy.cpu()[0]))
|
||||
elif len(moves) != 0:
|
||||
with open('moves.pkl', 'wb') as f: # 'wb' = write binary
|
||||
pickle.dump(moves, f)
|
||||
exit(1)
|
||||
|
||||
|
||||
cv2.imshow('Klatka z kamerki', img)
|
||||
cv2.setMouseCallback('Klatka z kamerki', click_event)
|
||||
cv2.waitKey(1) # Czekaj na naciśnięcie klawisza
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user