Constructor
(private) new P5Beholder()
Creates an instance of P5Beholder. It is automatically called during p5 loading. Initialization of the library is only compelte after prepare()
is called on sketch setup (see P5Beholder#prepare).
- Source
Members
(static) _defaultConfig
An object holding camera, detection, feed and overlay default options for the Beholder detection system.
- Source
// Structure of the default configuration object
{
camera_params: {
videoSize: 0, // The video size values map to the following [320 x 240, 640 x 480, 1280 x 720, 1920 x 1080]
rearCamera: false, // Boolean value for defaulting to the rear facing camera. Only works on mobile
torch: false, // Boolean value for if torch/flashlight is on. Only works for rear facing mobile cameras. Can only be set from init
},
detection_params: {
minMarkerDistance: 10,
minMarkerPerimeter: 0.2,
maxMarkerPerimeter: 0.8,
sizeAfterPerspectiveRemoval: 49,
},
feed_params: {
contrast: 0,
brightness: 0,
grayscale: 0,
flip: false,
},
overlay_params: {
present: true, // Determines if the Beholder overlay will display or be invisible entirely via display: none
hide: true, // Determines if the overlay should be hidden on the left of the screen or visible
},
}
Methods
angleInRange(currentAngle, detectionTargetAngle, angleRange) → {true|false}
Checks if the current angle is within a defined range from a target angle. All angles are in radians.
Name | Type | Description |
---|---|---|
currentAngle | number | Value to be checked. |
detectionTargetAngle | number | The target angle. |
angleRange | number | The range centers around the target angle. Should be less than PI. |
- Source
- Type:
- true |
false
cameraToCanvasVector(coord) → {p5.Vector}
Converts a position from camera to canvas using a p5.Vector.
Name | Type | Description |
---|---|---|
coord | p5. | p5.Vector with camera position. |
- Source
- p5.Vector with canvas position.
- Type:
- p5.
Vector
cameraToCanvasX(x) → {number}
Converts X position from camera to canvas.
Name | Type | Description |
---|---|---|
x | number | Camera X position. |
- Source
- Canvas X position.
- Type:
- number
cameraToCanvasXY(pX, pY) → {p5.Vector}
Converts a position from camera to canvas positions using 2 numbers.
Name | Type | Description |
---|---|---|
pX | number | Camera-relative X value. |
pY | number | Camera-relative Y value. |
- Source
- p5.Vector with canvas position.
- Type:
- p5.
Vector
cameraToCanvasY(y) → {number}
Converts Y position from camera to canvas.
Name | Type | Description |
---|---|---|
y | number | Camera Y position. |
- Source
- Canvas Y position.
- Type:
- number
debugDrawMarker(markerIdopt)
Debug functionality for drawing a marker on the canvas.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
markerId | number | <optional> | 0 | The id of the marker to draw. |
- Source
markerPresenceToKey(markerIdopt, pKeyCodeopt)
Quick converter between marker presence and keyboard input. When a marker is detected, fires the keydown
event. Whe the marker is undetected, fires the keyup
event.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
markerId | number | <optional> | 0 | The id of the marker to check. |
pKeyCode | number | <optional> | 32 | The number with the keyboard code (from |
- Source
markerPresenceToMouseClick(markerIdopt, non-null, clickXopt, clickYopt)
If a marker is present, the mouse button 0 goes down and, when undetected, goes up. The position of the resulting click can be defined, in pixels.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
markerId | number | <optional> | 0 | The id of the marker to check presence. |
clickX | number | <optional> | 0 | The X position where of the resulting click. |
clickY | number | <optional> | 0 | The Y position where of the resulting click. |
- Source
markerRotationInRange(markerId, detectionTargetAngle, angleRange) → {true|false}
Checks if a marker's rotation is within a specified range from a target angle. Useful for detecting things like a crank or spinner with a marker at its center. All angles are in radians.
Name | Type | Description |
---|---|---|
markerId | number | The id of the marker to be checked. |
detectionTargetAngle | number | The target angle. |
angleRange | number | The range centers around the target angle. Should be less than PI. |
- Source
- Type:
- true |
false
prepare(configopt, querySelectoropt)
Sets-up the p5beholder and sketch integration. Adds Beholder to the HTML page at the and initializes it with proper config file. Important: must be called once on setup()
. The config file must use P5Beholder._defaultConfig as a base.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
config | * | <optional> | P5Beholder._defaultConfig | Controls how Beholder detection will run. |
querySelector | string | <optional> | "#beholder_root" | Picks an HTML element to be the parent of the Beholder system elements (GUI, etc). |
- Source
setMarkersTimeout(timeoutopt)
Changes the timeout value for all markers.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
timeout | number | <optional> | 50 | New time in milliseconds. |
- Source