我寫一個自定義的灰度轉換方法:圖像處理呼叫垃圾收集
public Mat grayScaleManual(Mat imageMat){
Mat dst = new Mat(imageMat.width(), imageMat.height(), CvType.CV_8UC1);
double[] bgrPixel;
double grayscalePixel;
for(int y = 0; y < imageMat.height(); y++){
for(int x = 0; x < imageMat.width(); x++){
bgrPixel = imageMat.get(y, x);
grayscalePixel = (bgrPixel[0] + bgrPixel[1] + bgrPixel[2])/3;
imageMat.put(y, x, grayscalePixel);
}
}
return imageMat;
}
Mat
從OpenCV4Android庫中的一類。我知道OpenCV有一個內置的灰度級方法,但我想對我的灰度級實現和OpenCV進行比較。
這種方法總是讓垃圾回收器調用。我知道垃圾收集器在有未使用的對象時被調用,但我認爲我的代碼中沒有任何未使用的對象。
爲什麼這個代碼保持通話垃圾收集器?