I am new to openCV, trying to draw bounding boxes around humans in an image. The main issue I am having is that detectMultiScale seems to throw an error no matter what I do. If I have only 1 argument, it says there are an invalid number of arguments. If I use 1.1 and 3 for the 2nd and 3rd argument, it says argument 2 needs to be a rectVector. If I use a rectVector, it simply outputs "abort(6620504)" as the error. I am trying to run this code on a Raspberry Pi using node.js. I have confirmed that openCV is working (I can perform simpler operations with it). Here is the code:
var src = cv.matFromImageData(im.bitmap);
//detect human
let classifier = new cv.CascadeClassifier();
await classifier.load('haarcascade_fullbody.xml');
cv.cvtColor(src, src, cv.COLOR_BGR2GRAY);
const rectVector = new cv.RectVector();
const humans = classifier.detectMultiScale(src, rectVector, 3).objects;
if (!faceRects.length) {
console.log('no humans detected');
} else {
console.log('humans detected');
}
// Draw bounding boxes around detected humans
humans.forEach((rect) => {
const { x, y, width, height } = rect;
cv.rectangle(src, new cv.Point(x, y), new cv.Point(x + width, y + height), [255, 0, 0, 255], 2);
});
Please let me know what you think, thanks.