started different cameras

This commit is contained in:
moscovskayaliza
2026-06-18 17:25:32 +03:00
parent 59eff8b84b
commit 6b803b405e
8 changed files with 106 additions and 59 deletions
+10 -9
View File
@@ -3,8 +3,9 @@ import os
import sys
import time
from pathlib import Path
from camera import create_camera
def capture_photo(output_dir='captured', camera_id=0, mirror=True):
def capture_photo(output_dir='captured', camera):
"""
Простой инструмент для захвата фото с камеры.
При нажатии 's' запускается отсчёт 3 секунды, затем делается снимок.
@@ -26,12 +27,9 @@ def capture_photo(output_dir='captured', camera_id=0, mirror=True):
countdown_start = 0
while True:
ret, frame = cap.read()
if not ret:
break
if mirror:
frame = cv2.flip(frame, 1)
frame = camera.get_frame()
if frame is None:
continue
display = frame.copy()
@@ -65,7 +63,7 @@ def capture_photo(output_dir='captured', camera_id=0, mirror=True):
countdown = 1
countdown_start = time.time()
cap.release()
camera.release()
cv2.destroyAllWindows()
print(f"Завершено. Сохранено {capture_count} фото.")
@@ -75,5 +73,8 @@ if __name__ == '__main__':
parser.add_argument('--dir', default='captured', help='Папка для сохранения')
parser.add_argument('--camera', type=int, default=0, help='ID камеры')
parser.add_argument('--no-mirror', action='store_true', help='Отключить зеркалирование')
parser.add_argument('--camera_type', default='web', choices=['web', 'oak'])
args = parser.parse_args()
capture_photo(output_dir=args.dir, camera_id=args.camera, mirror=not args.no_mirror)
camera = create_camera(camera_type=args.camera_type, camera_id=args.camera, mirror=not args.no_mirror)
capture_photo(output_dir=args.dir, camera)
+17 -11
View File
@@ -10,16 +10,20 @@ import pandas as pd
#sys.path.append(str(Path(__file__).parent.parent))
from skeleton.mediapipe_detector import MediaPipeDetector
from ml_gestures_dynamic.feature_extractor import extract_sequence
from camera import create_camera
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--label', required=True, help='Название жеста (например, wave_left)')
parser.add_argument('--output', default='dynamic_data.csv', help='CSV файл для сохранения')
parser.add_argument('--camera', type=int, default=0)
parser.add_argument('--camera_type', default='web', choices=['web', 'oak'])
parser.add_argument('--duration', type=float, default=3.0, help='Длительность записи (сек)')
parser.add_argument('--no-mirror', action='store_true', help='Отключить зеркалирование')
args = parser.parse_args()
output_path = Path(args.output)
camera = create_camera(camera_type=args.camera_type, camera_id=args.camera, mirror=not args.no_mirror)
# Создаём файл с заголовком, если его ещё нет
if not output_path.exists():
@@ -47,10 +51,10 @@ def main():
sequence = []
while True:
ret, frame = cap.read()
if not ret:
break
frame = cv2.flip(frame, 1) # зеркало для удобства
frame = camera.get_frame()
if frame is None:
continue
#frame = cv2.flip(frame, 1) # зеркало для удобства
result = detector.detect(frame)
if result['success']:
landmarks = result['landmarks']
@@ -90,10 +94,10 @@ def main():
# Обратный отсчёт на живом видео
for i in range(3, 0, -1):
# Получаем свежий кадр для отсчёта
ret, frame = cap.read()
if not ret:
break
frame = cv2.flip(frame, 1)
frame = camera.get_frame()
if frame is None:
continue
#frame = cv2.flip(frame, 1)
result = detector.detect(frame)
if result['success']:
vis = detector.draw_landmarks(frame, result['pose_landmarks'])
@@ -104,9 +108,11 @@ def main():
cv2.imshow('Record dynamic gesture', vis)
cv2.waitKey(1000)
# Показываем "GO!"
ret, frame = cap.read()
if ret:
frame = cv2.flip(frame, 1)
frame = camera.get_frame()
if frame is None:
continue
else:
#frame = cv2.flip(frame, 1)
result = detector.detect(frame)
if result['success']:
vis = detector.draw_landmarks(frame, result['pose_landmarks'])