Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从图片和模板中获得绝对差异。[模板匹配]_Java_Image Processing_Template Matching - Fatal编程技术网

Java 从图片和模板中获得绝对差异。[模板匹配]

Java 从图片和模板中获得绝对差异。[模板匹配],java,image-processing,template-matching,Java,Image Processing,Template Matching,我有两种方法,可以将模板的绝对差值和原始图片中相同大小的面片的像素值写入到面片和模板坐标均为0,0的像素中 以下是我的两种方法 private void normalizeAndDraw(double biggest, double[] temporaryPixels, int[] dstPixels ){ double normalize = 255 / biggest; for (int c = 0; c < temporaryPixels.

我有两种方法,可以将模板的绝对差值和原始图片中相同大小的面片的像素值写入到面片和模板坐标均为0,0的像素中

以下是我的两种方法

private void normalizeAndDraw(double biggest, double[] temporaryPixels, int[] dstPixels  ){
         double normalize = 255 / biggest;
            for (int c = 0; c < temporaryPixels.length; c++) {
            int value = (int) (temporaryPixels[c] * normalize);
            dstPixels[c] = 0xFF000000 | (value << 16) | (value << 8) | value;
        }
    }

    private void getAbsolutePicture(int srcPixels[], int srcWidth, int srcHeight, int dstPixels[], int dstWidth, int dstHeight, int templatePixels[], int tmpHeight, int tmpWidth) {
        double temporaryPixels[] = new double[dstHeight * dstWidth];
        double biggest = 0;

        double sumR = 0;
        for (int j = 0; j < tmpHeight; j++) {
            for (int i = 0; i < tmpWidth; i++) {

                int posTmp = j * tmpWidth + i;
                sumR += templatePixels[posTmp] & 0xFF;
            }
        }

        for (int y = 0; y < dstHeight; y++) {
            for (int x = 0; x < dstWidth; x++) {
                double sumI = 0;
                for (int j = 0; j < tmpHeight; j++) {
                    for (int i = 0; i < tmpWidth; i++) {
                        int pos = (y + j) * dstWidth + (x + i);
                        sumI += srcPixels[pos] & 0xFF;
                    }
                }
                double absDifference = Math.abs(sumI - sumR);

                biggest = Math.max(absDifference, biggest);

                temporaryPixels[y * dstWidth + x] = absDifference;
            }
        }

         normalizeAndDraw(biggest, temporaryPixels, dstPixels);

    }
如果将值写入DST像素数组,则会自动显示这些值

不幸的是,这不是正确的解决方案

我得到的结果是这样的

我很确定我的错误在sumR和sumI的计算中,但我就是想不出来


我的代码到底出了什么问题?

我的代码实际上还行。最大的问题是,当我调用getAbsolutePicture()时,我混淆了tmpWdith和tmpHeight

getAbsolutePicture(srcPixels, srcWidth, srcHeight, dstPixels, dstWidth, dstHeight, templatePixels, templateWidth, templateHeight);