[Python] Python Accessing EO Edmund Optics Camera

Discussão em 'Python' iniciado por Stack, Janeiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    I have a camera (EO Edmund Optics Camera, Model UI-154xSE-M) connected to a Windows computer via USB. When I open IDS Camera Manager, The camera is "configured correctly and can be opened".

    I am trying to write a code in Python to have the camera capture an image every x minutes for a period of y total minutes using the cv2 package. Unfortunately, I am getting an error while doing this.

    Please find my code below and the result:

    import cv2
    import os
    import time
    from datetime import datetime, timedelta


    output_directory =

    camera = cv2.VideoCapture(0)

    if not camera.isOpened():
    print("Error: Could not access the camera.")
    else:
    print("Camera found and initialized. Starting photo capture...")


    end_time = datetime.now() + timedelta(hours=24)
    capture_interval = 10 * 60 # Capture every 10 minutes (600 seconds)

    try:
    while datetime.now() < end_time:

    ret, frame = camera.read()


    print(f"Capture status: {ret}") # Print whether the capture was successful
    if not ret:
    print("Error: Failed to capture image.")
    continue # Skip this iteration and try again


    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    file_path = os.path.join(output_directory, f"photo_{timestamp}.jpg")


    cv2.imwrite(file_path, frame)
    print(f"Photo captured and saved at {file_path}")


    time.sleep(capture_interval)
    except KeyboardInterrupt:
    print("Photo capture interrupted by user.")
    finally:

    camera.release()
    print("Camera released. Photo capture ended.")


    "Error: Failed to capture image." prints for the time frame I specify. Although "Camera found and initialized. Starting photo capture..." prints as well.

    I am very unfamiliar with accessing/controlling external devices with Python code. I am open to alternate ways to do this besides Python.

    I am new to coding and devices.

    Continue reading...

Compartilhe esta Página