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.
Configuration
{
"name": "<your-camera-name>",
"model": "webcam",
"api": "rdk:component:camera",
"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>
},
"format": <string>,
"video_path": "<your-video-path>",
"width_px": <int>,
"height_px": <int>,
"frame_rate": <float>
}
}
{
"name": "my_cam",
"model": "webcam",
"api": "rdk:component:camera",
"attributes": {
"video_path": "video0"
}
}
Attributes
| 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:
|
Using video_path
Find a video path using a discovery service
The viam:find-webcams:webcam-discovery service helps you identify path options.
To add and use the service:
- Navigate to the CONFIGURE tab of your machine’s page.
- Click the + icon next to your machine part in the left-hand menu and select Service.
- Search for
find-webcamsand select thediscovery / find-webcams:webcam-discoveryservice. - Click Add module.
- Enter a name or use the suggested name for your camera and click Create.
- Save your configuration, and wait a moment for the service to start.
- Click Test to see the available
video_paths. - Click the Copy attributes button for the camera you want to use.
- Click the {} icon in the upper right corner of the camera component configuration.
- Paste the copied attributes.
- Click Save.
- You can now delete the discovery service and the module that provides it from your machine.
Find a video path using the command line
To list available video_paths use the following command:
ls /dev/v4l/by-id/
To find the paths 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.
If you are using macOS version 15.x.x Sequoia or later, you need to give viam-server permissions to access webcams.
When you run viam-server for the first time, a pop-up message will ask for camera access.
Click Allow.
To confirm settings, you can go to System Settings > Privacy & Security > Camera and check that the toggle next to viam-server is set to enable access.
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 Viam, 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
Troubleshooting
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!