Android app Force closed by memory leak
Hey everyone. I'm trying to build a app,which can detect red color form input image , and do Hough line transform ,after sent the result to screen.
i think i finish the program,but the program will be Force closed,about every 30~50 sec.
i'm using opencv 2.4.10 (for android),and eclipse to build the program;
the program is revised from the OPENCV sample "example-tutorial-1-camerapreview", and i revised "public Mat onCameraFrame(CvCameraViewFrame inputFrame) " into below
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 = new Mat();
Mat lines = new Mat();
Mat filter2= new Mat();
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 = new Point(x1, y1);
Point end = new Point(x2, y2);
Core.line(mRgba, start, end, new Scalar(255,0,0), 2);
}
return mRgba;
}
I think " Core.inRange(sourceimage, new Scalar(50, 70, 100), new Scalar(150, 250, 250), filter2);" will cause the program Force closed,because when i trying to avoid program Force closed,i have removed "Core.inRange(sourceimage, new Scalar(50, 70, 100), new Scalar(150, 250, 250), filter2);" from program,though program can't show image to screen ,but the program won't be Force closed.
Does anyone know how to solve this problem? maybe the problem is not caused by "Core.inRange"
finally ,i'm apology about my poor English,and thanks for your response.