Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Make sure there's no any Mat describing method in onCameraFrame function. I assume it's because in every frame operation it creates new Mat without closing previous and forces to a memory leak. (didnt try to code, but having similar issue is solved this method)

public class ... {

  Mat sourceimage, mRgba, lines, filter2;

  public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    sourceimage = inputFrame.rgba();
    Imgproc.cvtColor(sourceimage , sourceimage, Imgproc.COLOR_RGBA2RGB);
    Imgproc.cvtColor(sourceimage , sourceimage, Imgproc.COLOR_BGR2HSV);

    mRgba = new Mat();
    lines = new 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;
  }
}