1 | initial version |
Your problem is caused by explicitly stating the new operator. If you do so than the garbage collector will not automatically delete your objects once they run out of scope. You can avoid this by changing your code to:
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat sourceimage = inputFrame.rgba();
Imgproc.cvtColor(sourceimage , sourceimage, Imgproc.COLOR_RGBA2RGB);
Imgproc.cvtColor(sourceimage , sourceimage, Imgproc.COLOR_BGR2HSV);
Mat mRgba, lines, filter2;
Core.inRange(sourceimage, Scalar(50, 70, 100), Scalar(150, 250, 250), filter2);
mRgba=filter2.clone();
Imgproc.cvtColor(mRgba , mRgba, Imgproc.COLOR_GRAY2RGBA);
Imgproc.Canny(filter2, filter2, 80, 100, 5, true);
Imgproc.HoughLinesP(filter2, lines, 1, Math.PI/180, 125, 20, 20);
for (int x = 0; x < lines.cols(); x++)
{
double[] vec = lines.get(0, x);
double x1 = vec[0],
y1 = vec[1],
x2 = vec[2],
y2 = vec[3];
Point start (x1, y1);
Point end (x2, y2);
Core.line(mRgba, start, end, Scalar(255,0,0), 2);
}
return mRgba;
}
And the memory leaking should be a thing of the past. Other way is to explicitly delete every object yourself!
2 | No.2 Revision |
Your problem is caused by explicitly stating the new operator. If you do so than the garbage collector will not automatically delete your objects once they run out of scope. You can avoid this by changing your code to:
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat sourceimage = inputFrame.rgba();
Imgproc.cvtColor(sourceimage , sourceimage, Imgproc.COLOR_RGBA2RGB);
Imgproc.cvtColor(sourceimage , sourceimage, Imgproc.COLOR_BGR2HSV);
Mat mRgba, lines, filter2;
Core.inRange(sourceimage, new Scalar(50, 70, 100), new Scalar(150, 250, 250), filter2);
mRgba=filter2.clone();
Imgproc.cvtColor(mRgba , mRgba, Imgproc.COLOR_GRAY2RGBA);
Imgproc.Canny(filter2, filter2, 80, 100, 5, true);
Imgproc.HoughLinesP(filter2, lines, 1, Math.PI/180, 125, 20, 20);
for (int x = 0; x < lines.cols(); x++)
{
double[] vec = lines.get(0, x);
double x1 = vec[0],
y1 = vec[1],
x2 = vec[2],
y2 = vec[3];
Point start (x1, y1);
Point end (x2, y2);
Core.line(mRgba, start, end, new Scalar(255,0,0), 2);
}
return mRgba;
}
And the memory leaking should be a thing of the past. Other way is to explicitly delete every object yourself!