Skip to content

Better camera capture #7

Description

@archit0410

Instead of spamming 'a'/'p' for capturing, a better way would be to use time-based capturing

# To capture the anchor images
# Open the webcam
cap = cv2.VideoCapture(0)

# Set the interval for capturing images (0.5 seconds)
capture_interval = 0.3
last_capture_time = time.time()

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break

    # Cut down frame to 250x250px
    frame = frame[120:120+250, 200:200+250, :]

    # Check if it's time to capture an image
    current_time = time.time()
    if current_time - last_capture_time >= capture_interval:
        # Create the unique file path for anchor images
        imgname = os.path.join(ANC_PATH, '{}.jpg'.format(uuid.uuid1()))
        # Save the anchor image
        cv2.imwrite(imgname, frame)
        
        # Update the last capture time
        last_capture_time = current_time

    # Show image back to screen
    cv2.imshow('Image Collection', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release the webcam
cap.release()
# Close the image show frame
cv2.destroyAllWindows()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions