1 | initial version |
Still not sure why the original code didn't hit that if-statement. A type change and a memory leak later, I got it to work:
private void euclidChannels(Mat in, Mat out){
in.convertTo(rgbF, CvType.CV_32F);
Core.pow(rgbF, 2, rgbF);
rgbF = rgbF.reshape(1,rgbF.rows() * rgbF.cols());
Core.reduce(rgbF, gF, 1, Core.REDUCE_SUM);
// fix rgbF - constant time
rgbF = rgbF.reshape(3, in.rows());
gF = gF.reshape(1, this.height);
Core.sqrt(gF, gF);
gF.convertTo(out, CvType.CV_8UC1);
}
Re-reshaping the rgbF matrix back to it's original state was key to eliminating the memory leak, as apparently convertTo() will re-allocate the destination matrix if it doesn't like the one you provide. (I guess I could have added another temp matrix instead, but reshape() is supposed to be constant time, so might as well save a bit of memory)