All that's left to do is call the initializer functions at the bottom of index.js:
initializeNNC();initializeMBS();
The end result should look like:
import lampix from'@lampix/core';import'./styles.css';import handleObjectClassified from'./handleObjectClassified';constinitializeNNC= () => {constnncElement=document.getElementsByClassName('nnc')[0];constnncBounds=nncElement.getBoundingClientRect();constnncRecognizedClassElement=document.getElementsByClassName('nnc-recognized-class')[0];// 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 itconstnncCallback= ([recognizedObject]) => {nncRecognizedClassElement.textContent =`Recognized: ${recognizedObject.classTag}`;if (Number(recognizedObject.classTag) ===1) {nncElement.style.borderColor ='#FF0000'; } else {// Go back to white if object no longer therenncElement.style.borderColor ='#FFFFFF'; } };constnncFruitsWatcher= { name:'NeuralNetworkClassifier', shape:lampix.helpers.rectangle(nncBounds.left,nncBounds.top,nncBounds.width,nncBounds.height ), params: { neural_network_name:'fruits' }, onClassification: nncCallback };lampix.watchers.add(nncFruitsWatcher);};constinitializeMBS= () => {constmbsElement=document.getElementsByClassName('mbs')[0];constmbsBounds=mbsElement.getBoundingClientRect();constonClassification= (classifiedObjects) =>classifiedObjects.forEach((classifiedObject) => {handleObjectClassified(classifiedObject,'#FFFFFF'); });constonLocation= (locatedObjects) => {// This step fires before onClassification!console.log(locatedObjects); };constmbsFruitsWatcher= { name:'MovementBasedSegmenter', shape:lampix.helpers.rectangle(mbsBounds.left,mbsBounds.top,mbsBounds.width,mbsBounds.height ), params: { neural_network_name:'fruits' }, onLocation, onClassification };lampix.watchers.add(mbsFruitsWatcher);};initializeNNC();initializeMBS();
Minus the next, optional step, this is the exact application in the fruits example on our GitHub.
If you're having trouble with this guide, see if the source code can help you out.