Reading Camera Input from RoboMaster S1 - HU-ICT-LAB/RobotWars GitHub Wiki

RoboMaster S1 must have the hack applied for this to work, and you must be connected to the robot on the same network for the code to work.

Use the following script adapted and slightly adjusted from this SDK documentation examples page while the aforementioned requirements are met;

(Please note that you will need to install the imported modules mentioned in the script below)

import cv2
import robomaster
from robomaster import robot
from robomaster import vision

if __name__ == '__main__':
    ep_robot = robot.Robot()
    ep_robot.initialize(conn_type="sta", sn="159CGAC0050QS0")  # You can find the Serial Number on top of the robot on an info card.

    ep_camera = ep_robot.camera

    ep_camera.start_video_stream(display=False)
    for i in range(0, 200):
        img = ep_camera.read_cv2_image()
        cv2.imshow("Robot", img)
        cv2.waitKey(0)
    cv2.destroyAllWindows()
    ep_camera.stop_video_stream()

    ep_robot.close()

The img variable will continually be updated with a image from the camera, which is essentially a numpy array.

Sources

Related issues

Issues: #8, #25, #31