Untitled

Anonymous
plain_text
02/26/2026 4:24 PM
2.8 KB
13
Indexable
def main():
    # Open live camera (EVK3) – 30 ms slices
    mv_iterator = EventsIterator(device=None, delta_t=30000)  # 30 000 µs = 30 ms [web:7]
    height, width = mv_iterator.get_size()  # sensor resolution [web:7]

    # Frame generator: accumulate events into grayscale frames
    frame_gen = PeriodicFrameGenerationAlgorithm(
        width, height, 30000  # same period as iterator
    )  # [web:7]

    # Buffer for the generated frame
    frame = np.zeros((height, width, 1), dtype=np.uint8)

    # Callback: Metavision will fill "frame" each period
    def on_frame(ts, out):
        nonlocal frame
        frame = out.copy()

    frame_gen.set_output_callback(on_frame)

    # Main loop
    for evs in mv_iterator:
        # Process GUI events (needed on Linux/macOS)
        EventLoop.poll_and_dispatch()  # [web:7]

        # Feed events to frame generator
        frame_gen.process_events(evs)

        # We now have a grayscale frame in "frame"
        if frame is None:
            continue

        # Convert to BGR for colored drawing
        vis = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)

        # ------------------------------------------------------------------
        # YOUR DETECTIONS HERE
        # Replace this with your DNN / tracking output.
        # detections is a list of (x_min, y_min, x_max, y_max, label, score)
        # ------------------------------------------------------------------
        detections = [
            (50, 60, 200, 220, "obj", 0.95),
            # ...
        ]

        # Draw bounding boxes + labels
        for x1, y1, x2, y2, label, score in detections:
            x1, y1, x2, y2 = map(int, [x1, y1, x2, y2])
            cv2.rectangle(vis, (x1, y1), (x2, y2), (0, 255, 0), 2)
            text = f"{label} {score:.2f}"
            cv2.putText(vis, text, (x1, max(0, y1 - 5)),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1)

        # Show real-time window
        cv2.imshow("EVK3 real-time with detections", vis)

        # Exit with 'q'
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cv2.destroyAllWindows()


if __name__ == "__main__":
    main()
Editor is loading...
Leave a Comment