Opencv Framdiffrence on Android Studio

Hi everyone.

I try to make gait recognitor in andoid.So i want to diff frames.How can I make it look like these binary pictures.

opcvout

Codes:

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    mGray = inputFrame.rgba();
    Imgproc.cvtColor(mGray,mGray,Imgproc.COLOR_BGR2GRAY);
    Imgproc.GaussianBlur(mGray,mGray,new Size(21,21),0);
    if(firstFrame.empty()){
        firstFrame=mGray;
    }
    Core.absdiff(firstFrame,mGray,mFGMask);
    Imgproc.threshold(mFGMask,mFGMask,50,255,Imgproc.THRESH_BINARY);
    Imgproc.dilate(mFGMask,mFGMask,new Mat(),new Point(),2);
    Imgproc.findContours(mFGMask.clone(), contours, new Mat(), Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_SIMPLE);





    return mFGMask;
}