user15936471
user15936471

Reputation:

How to capture and save single RGB photo with OAK-D Camera using DepthAI API?

I have recently purchased an OAK-D camera from Luxonis, and I want to capture and save a single RGB photo with the camera using the DepthAI API. I am not sure how to do so, despite looking at their code samples on RGB Video and RGB Camera Control.

I created a Pipeline (ColorCamera node -> VideoEncoder -> XLinkOut), but cannot seem to get a photo to show. Attached below is my code:

pipeline = dai.Pipeline()

camera = pipeline.create(dai.node.ColorCamera)
mjpeg_still_encoder = pipeline.create(dai.node.VideoEncoder)
mjpeg_encoder_output = pipeline.create(dai.node.XLinkOut)
mjpeg_encoder_output.setStreamName("MJPEG Encoder Output")

mjpeg_still_encoder.setDefaultProfilePreset(1, dai.VideoEncoderProperties.Profile.MJPEG)

camera.setBoardSocket(dai.CameraBoardSocket.RGB)
camera.still.link(mjpeg_still_encoder.input)
mjpeg_still_encoder.bitstream.link(mjpeg_encoder_output.input)

with dai.Device(pipeline) as device:
    still_queue = device.getOutputQueue("MJPEG Encoder Output")
    still_frames = still_queue.tryGetAll()
    for still_frame in still_frames:
        frame = cv2.imdecode(still_frame.getData(), cv2.IMREAD_UNCHANGED)
        cv2.imshow("Still", frame)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

Can someone explain what I need to change to capture and save a photo? Thank you so much!

Upvotes: 3

Views: 3381

Answers (1)

Ram B
Ram B

Reputation: 1

Are you perhaps looking for something like this https://docs.luxonis.com/projects/api/en/v2.3.0.0/samples/06_rgb_full_resolution_saver/

You'd just need to break out / control when to save the image through a keystroke to prevent flooding your storage with the photos like the author mentions though.

Upvotes: 0

Related Questions