I am trying to draw a mask over an image, the mask is the result of the processing done by body-pix (in NodeJS). I want to use OpenCV to draw the masks, instead of htmlcanva for performance reasons.
const segmentation = await net.segmentPersonParts(img, {
flipHorizontal: false,
internalResolution: 'medium',
segmentationThreshold: 0.7
});
//Mask into opencv Mat
const segmentationMask = new cv.Mat(segmentation.data, segmentation.height, segmentation.width, cv.CV_8UC4);
const mask = segmentationMask.cvtColor(cv.COLOR_BGRA2BGR);
//Application of mask
const result = mat.bitwiseAnd(mask);
cv.imwrite('mask.jpg', mask);
cv.imwrite('result.jpg', result);
This works perfectly, and achieves the desired result of drawing a black mask (the semantic segmentation) over persons detected. However SegmentPersonParts
is much slower than the method SegmentPerson
, and I wish to use this last method. The problem is, the mask does not work. When doing:
const segmentation = await net.segmentPerson(img, {
flipHorizontal: false,
internalResolution: 'medium',
segmentationThreshold: 0.7
});
//Mask into opencv Mat
const segmentationMask = new cv.Mat(segmentation.data, segmentation.height, segmentation.width, cv.CV_8UC4);
const mask = segmentationMask.cvtColor(cv.COLOR_BGRA2BGR);
//Application of mask
const result = mat.bitwiseAnd(mask);
cv.imwrite('mask.jpg', mask);
cv.imwrite('result.jpg', result);
The result is just a black image, as the mask is not correctly built. How can I solve this?