I am writing a custom grayscale conversion method:
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
is a class from the OpenCV4Android library. I know OpenCV has a built-in grayscaling method, but I want to make a comparison between my grayscale implementation and that of OpenCV.
This method always makes calls to the Garbage Collector. I know that the Garbage Collector is called when there are unused objects, but I do not think there are any unused objects in my code.
Why does this code keep calling the Garbage Collector?