Android-特定区域的相机运动检测

时间:2018-10-26 18:43:14

标签: java android camera area motion-detection

现在,我在运动检测器应用程序上进行开发,该应用程序使用设备摄像头来检测运动。现在,我运行相机预览,它调用方法Camera.PreviewCallback。我的问题是运动检测可以正常工作,但是我需要知道运动在图片中的哪个位置发生,因此我可以在特定区域绘制一个矩形。我这个问题现在已经三天了。请帮助:))

    static boolean isDifferent(int[] first, int width, int height) {

    System.out.println("WIDTH = " + width);
    System.out.println("HEIGHT = " + height);

    int totDifferentPixels = 0;
    int pix, otherPix;
    for (int i = 0, ij = 0; i < height; i++) {
        for (int j = 0; j < width; j++, ij++) {
            pix = (0xff & (first[ij]));
            otherPix = (0xff & (mPrevious[ij]));

            // Catch any pixels that are out of range
            if (pix < 0) pix = 0;
            if (pix > 255) pix = 255;
            if (otherPix < 0) otherPix = 0;
            if (otherPix > 255) otherPix = 255;



            if (Math.abs(pix - otherPix) >= mPixelThreshold) {
                totDifferentPixels++;
                // Paint different pixel red
               // first[ij] = Color.RED;
            }

        }
    }


    if (totDifferentPixels <= 0) totDifferentPixels = 1;
    boolean different = totDifferentPixels > mThreshold;

    return different;
}

0 个答案:

没有答案