Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You could do it e. g. this way:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

VideoCapture videoCapture = new VideoCapture();
videoCapture.open(0);

...

Mat mat = new Mat();
Mat prevMat = null;
Mat diffMat = new Mat();

while( true) {

    // get frame
    videoCapture.read(mat);

    // difference
    if( prevMat != null) {
        Core.absDiff(mat, prevMat, diffMat);
    }

    // remember mat
    prevMat = mat.clone();

    // wait
    Thread.sleep(100);
}

The difference image is in diffMat.