Java 像素访问 OpenCv 2.4.8

Java Pixel Access OpenCv 2.4.8

我正在尝试使用 OpenCV 2.4.8 计算每个 CV_8UC3 颜色通道中的绝对差异,乘以 Java 中的比例!

我知道 java 不使用 uchar 并且认为 java 中最接近的是一个 String[]

但这没有用,所以我用了一个短路然后我得到:

"error: cannot find symbol
short[] ptr_entry = image_entry.<short>ptr(row);
symbol:   method <short>ptr(int) location: variable image_entry of type Mat

我尝试了尝试使用 at 方法的可能性,但我无法在 java 中使用它!

    for (int row = 0; row < image_entry.rows(); ++row)
    {
        short[] ptr_entry = image_entry.<short>ptr(row);
        uchar[] ptr_compressed = image_compressed.<uchar>ptr(row);
        uchar[] ptr_output = image_output.<uchar>ptr(row);

        for (int col = 0; col < image_entry.cols(); col++)
        {
            // Calculation of the absolute difference in each color channel, multiplied by the scale
            ptr_output[0] = Math.abs(ptr_entry[0] - ptr_compressed[0]) * scale;
            ptr_output[1] = Math.abs(ptr_entry[1] - ptr_compressed[1]) * scale;
            ptr_output[2] = Math.abs(ptr_entry[2] - ptr_compressed[2]) * scale;

            ptr_entry += 3;
            ptr_compressed += 3;
            ptr_output += 3;
        }
    }

有什么建议吗?

使用 Mat.get() 函数访问像素数据。

public int get(int row,int col, short[] data)

阅读 OpenCV Java API documentation,这样可以避免不必要的帖子。