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.
const animalIdentificationQuestion = new BoundingBox({ id: 'animal_identification', text: 'Draw boxes around all the animals in this image.', imageUrl: 'https://example.com/path/to/image.jpg', boxColor: '#FF0000', boxOpacity: 0.3, maxBoxes: 5, required: true});
Each box’s coordinates and dimensions are represented as percentages of the image’s width and height.ValidationThe 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.
Here’s an example of how to create a customized bounding box question:
Copy
const customizedQuestion = new BoundingBox({ id: 'face_detection', text: 'Draw boxes around all faces in this image.', subText: 'Be sure to include all visible faces, including those in the background.', imageUrl: 'https://example.com/group-photo.jpg', boxColor: '#00FF00', boxOpacity: 0.5, maxBoxes: 10, required: true, customValidation: (response) => { if (response.length < 2) { return 'Please identify at least two faces in the image.'; } return true; }, styles: { root: { backgroundColor: '#f0f8ff', padding: '15px', borderRadius: '8px', boxShadow: '0 2px 4px rgba(0,0,0,0.1)' }, text: { color: '#2c3e50', fontSize: '1.2em', fontWeight: 'bold' }, subText: { color: '#7f8c8d', fontSize: '0.9em', marginTop: '5px' }, canvas: { border: '1px solid #3498db' }, button: { backgroundColor: '#3498db', color: 'white', padding: '10px 20px', borderRadius: '5px', '&:hover': { backgroundColor: '#2980b9' } }, errorMessage: { color: '#e74c3c', fontWeight: 'bold', marginTop: '5px' } }});
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.