2017-08-31 77 views
0

我试图计算每个CV_8UC3颜色通道的绝对差值,乘以使用OpenCV 2.4.8的Java中的比例!Java Pixel Access OpenCV 2.4.8

我知道,Java不使用UCHAR,并认为在Java中最接近的是一个字符串[]

但没有工作,所以我用了很短的话,我得到:

"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; 
     } 
    } 

有何建议?

回答

0

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

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

阅读OpenCV的Java API的documentation,它会在这里避免不必要的帖子。

+0

明天再说一遍吧!我发现OpenCV的Java文档有些缺乏,但是你的右眼是一个新的眼睛! –

+0

使用get()和put()来访问OpenCV for Java中的像素值! –

+0

@TomC太好了。 – zindarod