Webcam Test

Review #185579 about “animal”

Webcam: animal
Rating: Excellent (5 out of 5)
Date:

Advantages of the webcam:
fast running

Disadvantages of the webcam:
nothing

Author’s comment:
import cv2 import torch from ultralytics import YOLO import time # Choose device device = 0 if torch.cuda.is_available() else "cpu" # Ultralytics accepts int GPU index print(f"Using device: {device}") # Load pretrained COCO model (baseline) model = YOLO("yolov8x.pt") # Animal-like COCO classes (edit as needed) ANIMAL_LABELS = { "bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe" } cap = cv2.VideoCapture(0) if not cap.isOpened(): raise RuntimeError("Could not open webcam.") # Optional FPS calc prev_t = time.time() frame_count = 0 while True: ret, frame = cap.read() if not ret: print("Error: Could not read frame.") break # Inference (pass BGR frame directly; Ultralytics handles conversion) results = model.predict( source=frame, device=device, conf=0.6, iou=0.5, verbose=False ) detected_animals = [] for result in results: # usually len=1 for single image boxes = result.boxes if boxes is None: continue for box in boxes: class_id = int(box.cls.item()) confidence = float(box.conf.item()) label = model.names.get(class_id, f"id_{class_id}") if label in ANIMAL_LABELS: detected_animals.append(label) x1, y1, x2, y2 = map(int, box.xyxy[0].tolist()) cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 3) cv2.putText( frame, f"{label} {confidence:.2f}", (x1, max(y1 - 10, 10)), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 2 ) if detected_animals: print("Detected animals:", ", ".join(sorted(set(detected_animals)))) # FPS overlay (optional) frame_count += 1 if frame_count >= 10: # update every 10 frames curr_t = time.time() fps = frame_count / (curr_t - prev_t) prev_t = curr_t frame_count = 0 fps_text = f"FPS: {fps:.1f}" try: frame # ensure exists

Webcam Information

Webcam Name: Integrated Webcam
Type of Webcam: Integrated
Quality Rank: #30838
Quality Rating: 964
Built-in Microphone:
Built-in Speaker:
Frame rate: 30 FPS
Stream Type: Video
Image Mode: RGB Color
Webcam MegaPixels: 0.92 MP
Webcam Resolution: 1280×720
Video Standard: HD
Aspect Ratio: 1.78
PNG File Size: 1.02 MB
JPEG File Size: 559.47 KB
Bitrate: 16.39 MB/s
Number of Colors: 187379
Average RGB Color:
 
Lightness: 31.57%
Luminosity: 32.52%
Brightness: 31.9%
Hue: 47°
Saturation: 5.59%

Device Information

Device Name dell
Device Type Laptop
Screen Resolution 1366×768
Color Depth 24-bit
Screen Orientation landscape-primary