I have used various techniques to human body extraction.There is a lot of way to detect human bodies and extract these bodies on videos but Every technique has their own disadvantages.How can i do the my best for human body extraction?If there ıs a better algorithms please comment below.
Algorithm 1-)I am using Backgroundsubstraction method to human body extraction.When it comes to detect moving bodies this algorithm work well but if the body does not move, this algorithm does not work.
For example If we’re watching anyone comes in to the park, then this person is a new foreground object. But should it stay foreground forever? In areas where there was no foreground object a given(a foreground person does not move and exit the foreground but object is still there) , I could continue updating our background model.How can i keep this unmoving person on extracting foreground?
1-Apply the BackgroundsubstractorMOG2 to frame
2-Copy colors to the frame
Algorithm 2-)I am using haarcascades to extract human bodies.This algorithm run on following 5 steps.These algorithm not work very well because sometimes haar cascades cannot detect objects.
0-Detect human bodies with haar cascades
1-Create a mask with the rectangular coordinates
2-Mask out the object(rectengular) region
3-Edge detection using canny
4-Find contours.(Human face contours)
5-Extract human body by contours
Algorithm 1 Code:
let video = document.getElementById('videoInput');
let cap = new cv.VideoCapture(video);
let frame = new cv.Mat(video.height, video.width, cv.CV_8UC4);
let fgmask = new cv.Mat(video.height, video.width, cv.CV_8UC1);
let fgbg = new cv.BackgroundSubtractorMOG2(500, 16, true);
const FPS = 30;
function processVideo() {
try {
if (!streaming) {
// clean and stop.
frame.delete(); fgmask.delete(); fgbg.delete();
return;
}
let begin = Date.now();
// start processing.
cap.read(frame);
fgbg.apply(frame, fgmask);
frame.copyTo(fgmask, fgmask);
cv.imshow('canvasOutput', fgmask);
// schedule the next one.
let delay = 1000/FPS - (Date.now() - begin);
setTimeout(processVideo, delay);
} catch (err) {
utils.printError(err);
}
};
// schedule the first one.
setTimeout(processVideo, 0);
Algorithm2 Code:
let src = cv.imread('canvasInput');
let gray = new cv.Mat();
cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0);
let faces = new cv.RectVector();
let poly=new cv.MatVector();
let faceCascade = new cv.CascadeClassifier();
faceCascade.load('haarcascade_frontalface_default.xml');
let msize = new cv.Size(0, 0);
faceCascade.detectMultiScale(gray, faces, 1.1, 3, 0, msize, msize);
//1-Create a mask with the rectangular coordinates
let rect = new cv.Rect(faces.get(0).x, faces.get(0).y,faces.get(0).width,faces.get(0).height);
//2-Mask out
dst = src.roi(rect);
//3-Edge detection using canny
let cannyoutput=new cv.Mat();
cv.Canny(dst, cannyoutput, 0, 100, 3, true);
//4-Find contours
let contours = new cv.MatVector();
let hierarchy = new cv.Mat();
cv.findContours(cannyoutput,contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_NONE);
//cv.drawContours();
cv.imshow('canvasOutput', cannyoutput);
src.delete(); gray.delete(); faceCascade.delete();
faces.delete();
contours.delete(); hierarchy.delete();