const initializeNNC = () => {
// Get the elements we'll be working with...
const nncElement = document.getElementsByClassName('nnc')[0];
const nncRecognizedClassElement = document.getElementsByClassName('nnc-recognized-class')[0];
// ...along with the bounding rect that defines the watcher size
const nncBounds = nncElement.getBoundingClientRect();
// All Lampix classifiers return a list of recognized objects
// NNClassifier only recognizes one at a time, hence expecting
// an array with one element and destructuring it
const nncCallback = ([recognizedObject]) => {
nncRecognizedClassElement.textContent = `Recognized: ${recognizedObject.classTag}`;
if (Number(recognizedObject.classTag) === 1) {
nncElement.style.borderColor = '#FF0000';
// Go back to white if object no longer there
nncElement.style.borderColor = '#FFFFFF';
const nncFruitsWatcher = {
name: 'NeuralNetworkClassifier',
shape: lampix.helpers.rectangle(
neural_network_name: 'fruits'
onClassification: nncCallback
lampix.watchers.add(nncFruitsWatcher);