Camera Input
The Camera Input widget allows you to capture a picture from your webcam to your notebook. Useful for creating many image related apps.
Basic Usage
First, create a Camera Input widget and optionally configure its settings. For example, you can set the output variable name to store the file path of the captured image or the destination path for the pictures.
Python Code Usage Example
When a picture is captured through the Camera widget, two additional variables besides the configured output_variable will be available in your Python context:
- Fullpath Variable: A
{output_variable_name}_fullpathvariable that contains the full file path of the captured picture. - Project Path Variable: A
{output_variable_name}_project_pathvariable that contains the path of the captured picture, starting from the project root.
tip
These variables allow for seamless integration and utilization of images within your Python code or for passing them to other widgets, such as image display widgets.
Here is how you can utilize these variables in your Python code:
# Assuming your variable name is `camera_picture`
print(f'''
Widget Name: {camera_picture} \n
Full File Path: {camera_picture_fullpath} \n
Project Path: {camera_picture_project_path}
''')
# Use the full path to open and process the image
try:
with open(camera_picture_fullpath, 'rb') as image_file:
# Process the image file here
pass # Insert your processing code here
except FileNotFoundError:
print(f'Error: The file {camera_picture_fullpath} could not be found. Please check the path.')
# Use the project path for widgets or other display purposes
image_widget_path = camera_picture_project_path
API reference
| Setting name | Type | Description | Default |
|---|---|---|---|
| Output variable | string | Name of the variable that stores the path of the captured file. | |
| Path | string | Folder in the project where the captured file is saved. | ./myfile |
| Required | boolean | If enabled, execution stops until a file is captured. | false |
| Vertical alignment | start | center | end | Vertical alignment of the container. | center |
| Horizontal alignment | left | center | right | Horizontal alignment of the container. | center |
See also
- All widgets — browse the full widget catalog.
- Image — display the captured pictures.
- Upload — provide image files from local storage instead.