huskytools.huskylens
Module implementing a low level API for the Huskylens camera.
Arrow
Class representing an arrow
id: int
property
Object ID of the arrow.
learned: bool
property
If the block is learned.
x_head: int
property
X coordinate of the head of the arrow.
x_tail: int
property
X coordinate of the tail of the arrow.
y_head: int
property
Y coordinate of the head of the arrow.
y_tail: int
property
Y coordinate of the tail of the arrow.
get_angle()
Get the angle of the arrow in degrees
get_length()
Get the length of the arrow in pixels
Block
Class representing a block
height: int
property
Height of the block in pixels.
id: int
property
Object ID of the block.
learned: bool
property
If the block is learned.
width: int
property
Width of the block in pixels.
x: int
property
X coordinate of the center of the block.
y: int
property
Y coordinate of the center of the block.
ChecksumMismatch
Bases: Exception
Exception raised when a checksum does not match the expected value.
Interface
Serial port interface for the Huskylens camera.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port |
str
|
Serial port connected to the Huskylens camera. |
required |
baudrate |
int
|
Baudrate, make sure that this matches the baudrate configured on the Huskylens. |
9600
|
timeout |
float
|
Timeout in seconds. |
1.0
|
Raises:
| Type | Description |
|---|---|
ChecksumMismatch
|
If the checksum returned from the Huskylens is incorrect. |
ResponseLengthError
|
If the response from the Huskylens is to short or long. |
Examples:
Here is an example of how to create a Huskylens interface object:
>>> from huskytools import huskylens
>>> with huskylens.Interface("/dev/ttyUSB0") as lens:
... pass
clear_text()
Clear all custom texts on the HuskyLens display.
Returns:
| Type | Description |
|---|---|
bool
|
True if the text was cleared successfully. |
forget()
Forget learned objects for the current algorithm.
Returns:
| Type | Description |
|---|---|
bool
|
True if the learned objects was forgotten successfully. |
get_arrows()
Get a list of arrows from the HuskyLens.
Returns:
| Type | Description |
|---|---|
List[Arrow]
|
A list of all arrows. |
get_arrows_by_id(id)
Get a list of arrows with a specific ID from the HuskyLens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
int
|
ID of requested arrow. |
required |
Returns:
| Type | Description |
|---|---|
List[Arrow]
|
List of arrows with |
get_arrows_learned()
Get a list of learned arrows from the HuskyLens.
Returns:
| Type | Description |
|---|---|
List[Arrow]
|
A list of all learned arrows. |
get_blocks()
Get a list of blocks from the HuskyLens.
Returns:
| Type | Description |
|---|---|
List[Block]
|
A list of all blocks. |
Examples:
>>> lens.get_blocks()
[<Block>, <Block>]
get_blocks_by_id(id)
Get a list of blocks with a specific ID from the HuskyLens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
int
|
ID of requested block. |
required |
Returns:
| Type | Description |
|---|---|
List[Block]
|
List of blocks with |
get_blocks_learned()
Get a list of learned blocks from the HuskyLens.
Returns:
| Type | Description |
|---|---|
list
|
A list of all learned blocks. |
is_pro()
Check if the HuskyLens is a pro version.
Returns:
| Type | Description |
|---|---|
bool
|
True if pro. |
knock()
Check if the HuskyLens is connected.
Returns:
| Type | Description |
|---|---|
bool
|
True if the Huskylens is connected and responding. |
Examples:
>>> print(lens.knock())
True
learn(object_id)
Learn the current recognized object with the given ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_id |
int
|
ID for the object to learn (1-1023). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if object was learned successfully. |
load_model(file_number)
Load a model from the SD-card.
See save_model for more information about models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_number |
int
|
File number used to generate the file name of the model to load. |
required |
Note
The Huskylens will return success even if no SD-card is inserted but an error message
will be displayed on the screen.
photo()
Take a photo with the HuskyLens and save to the SD-card.
Returns:
| Type | Description |
|---|---|
bool
|
True if the command was successful. |
Note
The Huskylens will return success even if no SD-card is inserted but an error message
will be displayed on the screen.
save_model(file_number)
Save the current algorithms model to the SD-card.
The file will be saved as <algorithm>_Backup_<file_number>.conf, e.g.
FaceRecognition_Backup_0.conf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_number |
int
|
File number used to generate the file name for the model. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the command was successful. |
Note
The Huskylens will return success even if no SD-card is inserted but an error message
will be displayed on the screen.
screenshot()
Save a screenshot of the current UI to the SD-card.
Returns:
| Type | Description |
|---|---|
bool
|
True if the command was successful. |
Note
The Huskylens will return success even if no SD-card is inserted but an error message
will be displayed on the screen.
set_algorithm(algorithm)
Set the algorithm used by the HuskyLens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm |
int
|
ID of the algorithm to set. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if algorithm was changed successfully. |
Examples:
>>> print(lens.set_algorithm(huskylens.RecognitionAlgorithm.FACE_RECOGNITION))
True
set_name(name, object_id)
Set a custom name for the object with given ID.
The custom name will be displayed on the Huskylens screen if an object with object_id
is recognized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name to be set for the object |
required |
object_id |
int
|
The id of the object whose name is to be set |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the name was set successfully. |
set_text(text, x, y)
Set a custom text on the HuskyLens display.
Set a custom text of max 19 characters that will be displayed on the Huskylens screen. Max 10 texts can be displayed at the same time, new texts above this limit will replace old texts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text |
str
|
Text to display. |
required |
x |
int
|
The X coordinate for the text (0-320). |
required |
y |
int
|
The Y coordinate for the text (0-240). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the text was set successfully. |
RecognitionAlgorithm
Class representing the algorithms available on the HuskyLens.
Attributes:
| Name | Type | Description |
|---|---|---|
FACE_RECOGNITION |
Recognize and track faces. |
|
OBJECT_TRACKING |
Track a single learned object. |
|
OBJECT_RECOGNITION |
Recognize and track several pre-defined objects. |
|
LINE_TRACKING |
Track lines, several lines of different color can be tracked. |
|
COLOR_RECOGNITION |
Recognize and track colors. |
|
TAG_RECOGNITION |
Detect and track April Tags. |
|
OBJECT_CLASSIFICATION |
Recognize learned objects. |
ResponseLengthError
Bases: Exception
Exception raised when the response length does not match the expected value.