2

I want to extract foreground mask of moving human alone in a static background. How to implement this in open-CV java?

package com.java.opencv;

import org.opencv.core.Mat;
import org.opencv.video.BackgroundSubtractor;
import org.opencv.video.BackgroundSubtractorMOG2;
import org.opencv.videoio.VideoCapture;

public class HelloCV {
    public static void main(String[] args){
        VideoCapture capture = new VideoCapture(0);
          Mat camImage = new Mat();
          BackgroundSubtractorMOG2 backgroundSubtractorMOG=new BackgroundSubtractorMOG2();
            if (capture.isOpened()) {
                while (true) {
                    capture.read(camImage);


                    Mat fgMask=new Mat();
                    backgroundSubtractorMOG.apply(camImage, fgMask,0.1);

                    Mat output=new Mat();
                    camImage.copyTo(output,fgMask);

                    //displayImageOnScreen(output);
                   }
                }
    }
}

im getting an error at this line.

BackgroundSubtractorMOG2 backgroundSubtractorMOG=new BackgroundSubtractorMOG2();

The constructor BackgroundSubtractorMOG2() is undefined

Couldn't find proper documentation for these methods

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Avinash S
  • 31
  • 1
  • 6

1 Answers1

6

They removed constructors in the last version, use this:

BackgroundSubtractorMOG2 mog2 = Video.createBackgroundSubtractorMOG2();
StepTNT
  • 3,867
  • 7
  • 41
  • 82