Bounding Box
The BoundingBox question type allows users to draw, move, and resize rectangular bounding boxes on an image. It’s useful for tasks such as object detection, image annotation, or any scenario where you need users to identify specific regions in an image.
Basic Usage
Parameters
Unique identifier for the question.
The main question text.
Additional text to display below the main question text.
URL of the image on which boxes will be drawn.
Color of the bounding boxes.
Opacity of the bounding boxes (0 to 1).
Maximum number of boxes that can be drawn.
Whether the question is required.
A custom validation function that takes the response as input and returns true if valid, or an error message string if invalid.
Custom styles to apply to the question. Available keys are:
root
innerContainer
textContainer
text
subText
canvas
controls
controlPoint
button
errorMessage
Data
Response Format
The BoundingBox question type returns an array of objects representing the drawn boxes:
Each box’s coordinates and dimensions are represented as percentages of the image’s width and height.
Validation
The BoundingBox question validates that:
- At least one box is drawn when
required
is true. - Any custom validation provided in the
customValidation
function passes.
If validation fails, it displays an error message.
Advanced
Methods
The BoundingBox question type inherits methods from the base Element class and adds some specific methods:
Removes all drawn boxes.
Removes the currently active (selected) box.
Undoes the last action (drawing, moving, or resizing a box).
Validate the current response against the question’s rules.
Returns:
- An object with
isValid
(boolean) anderrorMessage
(string) properties.
Example
Here’s an example of how to create a customized bounding box question:
This example creates a face detection question with custom styling, a maximum of 10 boxes, and custom validation to ensure at least two faces are identified.