Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem background subtraction JAVA

Hi

my background subtraction is not generating results...

@Override
public void run() {

    while (true) {


        Mat fgmask = new Mat();
        Mat copy = new Mat();
        frame.copyTo(copy); // webcam.read(frame)

        BackgroundSubtractorMOG2 bgsubtraction = Video.createBackgroundSubtractorMOG2();
        bgsubtraction.apply(copy, fgmask);

        int cols = fgmask.cols();
        int rows = fgmask.rows();
        int elemSize_mat = (int) fgmask.elemSize(); 

        byte[] data_mat = new byte[cols * rows * elemSize_mat];
        fgmask.get(0, 0, data_mat);

        BufferedImage imageBuffer = new BufferedImage(cols, rows, BufferedImage.TYPE_BYTE_GRAY);
        imageBuffer.getRaster().setDataElements(0, 0, cols, rows, data_mat);
        Icon icon = new ImageIcon(imageBuffer);
        this.jLabel_diferenca_entre_fotos.setIcon(icon);
        this.jLabel_diferenca_entre_fotos.repaint();

        try {
            Thread.sleep(30);
        } catch (InterruptedException ex) {

        }
    }
}

image description

what is the problem?