add camera mode

This commit is contained in:
2025-10-26 02:16:12 -03:00
parent c4291c8759
commit d9b87a838d

View File

@@ -666,10 +666,12 @@ def main():
) )
# Essential arguments # Essential arguments
parser.add_argument('--input', '-i', required=True, parser.add_argument('--input', '-i', required=False,
help='Input source (path to video file or URL)') help='Input source (path to video file, URL, or camera index like "0" for webcam)')
parser.add_argument('--output', '-o', required=True, parser.add_argument('--camera', '-c', action='store_true',
help='Output JSON file to save pose data') help='Use default webcam (camera 0) as input source')
parser.add_argument('--output', '-o', required=False,
help='Output JSON file to save pose data (optional for camera mode)')
parser.add_argument('--model', type=str, default='n', choices=['n', 's', 'm', 'l', 'x'], parser.add_argument('--model', type=str, default='n', choices=['n', 's', 'm', 'l', 'x'],
help='YOLOv11 model size (n=nano, s=small, m=medium, l=large, x=xlarge)') help='YOLOv11 model size (n=nano, s=small, m=medium, l=large, x=xlarge)')
parser.add_argument('--device', type=str, default='auto', parser.add_argument('--device', type=str, default='auto',
@@ -693,6 +695,19 @@ def main():
args = parser.parse_args() args = parser.parse_args()
# Handle camera/input source logic
if args.camera:
input_source = 0 # Default webcam
print("📷 Using default webcam (camera 0)")
elif args.input:
input_source = args.input
else:
parser.error("Either --input/-i or --camera/-c must be specified")
# Output is optional for camera mode
if not args.output and not args.camera:
parser.error("--output/-o is required when not using camera mode")
# Validate filter window size # Validate filter window size
if args.filter_window % 2 == 0: if args.filter_window % 2 == 0:
args.filter_window += 1 args.filter_window += 1
@@ -701,8 +716,8 @@ def main():
print("\n" + "="*50) print("\n" + "="*50)
print("📹 JD-Clone YOLOv11 Pose Detector") print("📹 JD-Clone YOLOv11 Pose Detector")
print("="*50) print("="*50)
print(f"• Input: {args.input}") print(f"• Input: {input_source if not args.camera else 'Webcam (camera 0)'}")
print(f"• Output: {args.output}") print(f"• Output: {args.output if args.output else 'None (preview only)'}")
print(f"• Model: YOLOv11-{args.model}") print(f"• Model: YOLOv11-{args.model}")
print(f"• Device: {args.device}") print(f"• Device: {args.device}")
print(f"• Preview: {'Disabled' if args.no_preview else 'Enabled'}") print(f"• Preview: {'Disabled' if args.no_preview else 'Enabled'}")
@@ -714,7 +729,7 @@ def main():
# Run pose detection # Run pose detection
try: try:
run_pose_detection( run_pose_detection(
input_source=args.input, input_source=input_source,
output_file=args.output, output_file=args.output,
normalize=not args.no_normalize, normalize=not args.no_normalize,
detection_threshold=args.detection_threshold, detection_threshold=args.detection_threshold,