The Opentrons OT-2 has a camera built in to its chassis, positioned to get a view of the deck. It has a resolution of 640x480px for still images and 320x240px for video.

The camera can be used in two ways: taking a picture (can only be a still image) through the HTTP API of the robot, and saving images or video from the robot's terminal.

 Taking images with the HTTP API

The robot will respond to POST /camera/picture  with the picture in the body and a Content-Type: image/jpeg . For instance, you can find your robot's IP address from the Opentrons App:

In this image, the robot's IP address is 10.10.3.187 

You can then use an application like Postman , wget , or curl to make a POST request to that IP, port 31950:

Taking images and video from the robot's command line

Sometimes, taking a still image is not enough, or you want to handle the images from the robot itself. In this case, you can SSH into the robot and use the ffmpeg utility to interact with the camera directly.

1. Connect to your OT-2 with SSH

See Connecting to Your OT-2 With SSH.

2. Invoke ffmpeg

Once you can run commands on the robot, you can use the pre-installed ffmpeg utility to save pictures and video. Full documentation on this interface can be found online.

Example: save an image

ffmpeg -y -f video4linux2 -s 640x480 -i /dev/video0 -ss 0:0:1 -frames 1 /data/user_storage/image.jpg 

This will save a 640x480 (-s 640x480 ) JPEG image (-ss 0:0:1 -frames 1 ) from the camera (-i /dev/video0) to a file in the /data/user_storage  directory named image.jpg .

Example: save a video

ffmpeg -y -video_size 320x240 -i /dev/video0 -t 00:00:01 /data/user_storage/video.mp4
This will save 1 second (-t 00:00:01 ) of 320x240 video (-video_size 320x240 ) from the camera (-i /dev/video0 ) to a file in the /data/user_storage  directory named video.mp4 .

Taking images and video from a Python protocol

To integrate the camera into your protocol, use the Python subprocess module to invoke the ffmpeg  commands above. For instance, to save an image from the camera from a protocol you might do this:

import subprocess

def run(protocol):
if not protocol.is_simulating():
subprocess.check_call(['ffmpeg', '-y', '-f', 'video4linux2', '-s',
'640x480', '-i', '/dev/video0', '-ss', '0:0:1',
'-frames', '1', '/data/user_storage/image.jpg'])

contents = open('/data/user_storage/image.jpg', 'rb').read()
protocol.comment('The OT-2 Just took a picture!')

 And the image file would be in the variable contents

Note that the code that takes the picture is wrapped in if not protocol.is_simulating()  to avoid taking pictures during protocol simulation.

Downloading image and video files from the robot to your computer

You can use SCP to download the files you just created. See: Copying Files To and From Your OT-2 With SCP.

You can also save your files under the /var/lib/jupyter/notebooks directory, which will allow them to be accessed through your robot's Jupyter Notebook.

Did this answer your question?