Module:camera
From Digi Developer
Contents |
The Camera Module
Introduction
Built-in python module provided by Digi for interacting with a USB Watchport/V2 camera.
Functions
get_image()
- Purpose
Retrieve the most recent camera image as a JPEG.
- Syntax
get_image() . (image, timestamp)
- image is buffer containing a JPEG of the most recent camera image
- timestamp is the timestamp the image was acquired by the device, in milliseconds since device power on.
- Description
Returns the most recent image from the attached Watchport camera. The camera parameters affecting the resolution, image quality, frame rate, etc are configured via the device web interface or command line interface.
The image is a standard JPEG.
The timestamp returned with the image is the time when the image was acquired by the device. The value is the same type as the uptime of the system (milliseconds since last boot time). The timestamp can be used to find the elapsed time between two images. It can also be used to determine if two calls to get_image() are the same image. Note, the timestamp of the image will be different than the current uptime of the device. This is because camera images are acquired continuously by the device based on the Frame Delay setting. The most recent image acquired by the device is what is returned by get_image() which can be as old as the value in Frame Delay.
If an image is not available (no camera attached, camera disabled, etc) (None, None) is returned.
- Example
##Internal module import camera ##Destination of the image fh = open('WEB/python/demo_image.jpg', 'wb') ##image, and timestamp image, timestamp = camera.get_image() ##write buffer and close fh.write(image) fh.close()
The above code saves the current camera image to a file on the device file system.
Note, the file handle must be opened in binary mode. Writing the image buffer without specifying 'b' will result in a corrupted image.
Availability
Products which support this module
This feature is available only on Digi products with built-in USB host ports.
Products which DO NOT support this module
This feature is not currently supported on:
- Digi ConnectPort X2/WiX2
- Digi ConnectPort X3
