- Setup: The
setup
function initializes the canvas and video capture. The video is hidden by p5.js’s default element so that we can draw it onto the canvas manually. - Model Loading: We load the COCO-SSD model asynchronously. Once the model is ready, we start continuous object detection by calling
detectObjects()
. - Detection Loop: The
detectObjects
function uses the loaded model to analyze the current video frame and stores the detection results. It recursively calls itself so that new frames are analyzed continuously. - Drawing: In the
draw
loop, the video feed is displayed and for each detected object, a rectangle and label are drawn. The bounding box coordinates and object class are provided by the model.
Now that you have a basic real-time object detection app, consider extending its functionality: