Configure a Webcam
webcam
is the general camera model.
If the camera drivers are among those in this mediadevices repository, the camera will work with the webcam model.
First, connect your camera to your machine’s computer (unless it is built-in like a webcam on a laptop) and power both on. Then, configure your camera:
Navigate to the CONFIGURE tab of your machine’s page in the Viam app.
Click the + icon next to your machine part in the left-hand menu and select Component.
Select the camera
type, then select the webcam
model.
Enter a name or use the suggested name for your camera and click Create.
Edit and fill in the attributes as applicable. If you click on Show more, then the video_path field while your machine is live, a dropdown autopopulates with identified camera paths.
{
"name": "<your-camera-name>",
"model": "webcam",
"type": "camera",
"namespace": "rdk",
"attributes": {
"intrinsic_parameters": {
"width_px": <int>,
"height_px": <int>,
"fx": <float>,
"fy": <float>,
"ppx": <float>,
"ppy": <float>
},
"distortion_parameters": {
"rk1": <float>,
"rk2": <float>,
"rk3": <float>,
"tp1": <float>,
"tp2": <float>
},
"debug": <boolean>,
"format": <string>,
"video_path": "<your-video-path>",
"width_px": <int>,
"height_px": <int>,
"frame_rate": <float>
}
}
{
"name": "my_cam",
"model": "webcam",
"type": "camera",
"namespace": "rdk",
"attributes": {
"video_path": "video0"
}
}
The following attributes are available for webcam
cameras:
Name | Type | Required? | Description |
---|---|---|---|
video_path | string | Optional | The ID of or the path to the webcam. If you don’t provide a video_path , it defaults to the first valid video path it finds. Using the ID of a webcam is more consistent than the path. See Using video_path . |
format | string | Optional | The camera image format, used with video_path to find the camera. See Using format . |
width_px | int | Optional | The camera image width in pixels, used with video_path to find a camera with this resolution. Negative values are silently ignored and result in the default being used.Default: Closest possible value to 480 |
height_px | int | Optional | The camera image height in pixels, used with video_path to find a camera with this resolution. Negative values are silently ignored and result in the default being used.Default: Closest possible value to 640 |
frame_rate | float | Optional | The camera capture frequency as frames per second, used with video_path to find a camera with this throughput.Default: Closest possible value to 30.0 |
intrinsic_parameters | object | Optional | The intrinsic parameters of the camera used to do 2D <-> 3D projections:
|
distortion_parameters | object | Optional | Modified Brown-Conrady parameters used to correct for distortions caused by the shape of the camera lens:
|
debug | boolean | Optional | Enables the debug outputs from the camera if true .Default: false |
Using video_path
To list available video_path
s use the following command:
ls /dev/v4l/by-id/
To find the path
s of all connected video devices, run the following command:
v4l2-ctl --list-devices
The id
listed by ls /dev/v4l/by-id/
is a more consistent way to refer to the webcam.
system_profiler SPCameraDataType
The Unique ID displayed for each camera is the video_path
.
Using format
Viam supports the following pixel formats:
- I420
- I444
- MJPEG / MJPG
- NV12
- NV21
- RGBA
- UYVY / Y422
- YUY2 / YUYV / V422
- Z16
If your machine is connected to the Viam app, the available pixel formats supported by your camera automatically appear in the Format dropdown menu, which is visible when you click the Show more button.
On Linux, you can also manually determine which pixel formats your camera supports by running the following command on the machine your camera is connected to.
Replace /dev/video0
with the video path you determined for your video device above, if different:
v4l2-ctl --list-formats-ext --device /dev/video0
View the camera stream
Once your camera is configured and connected, expand the TEST panel on the CONFIGURE or CONTROL tabs. If everything is configured correctly, you will see the live feed from your camera.
Troubleshooting
If your camera is not working as expected, follow these steps:
- Check your machine logs on the LOGS tab to check for errors.
- Review this camera model’s documentation to ensure you have configured all required attributes.
- Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the camera there.
If none of these steps work, reach out to us on the Community Discord and we will be happy to help.
Common errors
Next steps
For more configuration and usage info, see:
Have questions, or want to meet other people working on robots? Join our Community Discord.
If you notice any issues with the documentation, feel free to file an issue or edit this file.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!