1
我試圖使用adaptiveThreshold方法對RGB圖像進行二值化。我的代碼如下:OpenCV:在應用adaptiveThreshold函數後,最大值爲-1
public byte[] filter(byte[] buff, int width, int height) {
Mat img_rgb = new Mat(width, height, CvType.CV_8UC3);
Mat img_gray = new Mat(width, height, CvType.CV_8U);
Mat img_bin = new Mat(width, height, CvType.CV_8U);
img_rgb.put(0, 0, buff);
Imgproc.cvtColor(img_rgb, img_gray, Imgproc.COLOR_RGB2GRAY);
Imgproc.adaptiveThreshold(img_gray, img_bin, 255,
Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 5, 2);
int size = (int) img_bin.total() * img_bin.channels();
byte[] bin_buff = new byte[size];
img_bin.get(0, 0, bin_buff);
return bin_buff;
}
的img_bin
數據的最大值申請後adaptiveThreshold應該是255,但它是-1代替。這是爲什麼發生?我是OpenCV的新手,我找不到任何解釋。
在此先感謝。
你說得對!我忘了在調試器中配置Java Primitives,所以它顯示的值是signed,而不是unsigned ... – jorgepr 2013-04-04 17:52:25