Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Memory Leaks opencv 2.3

I'am trying to use drawLargestContour mehthod to my program, but unfortunately my program suddenly turns off after about 1 minutes. I don't know why ? please some body help me :

this is my code (i use this for online capture) :

Mat HSV = new Mat();
    Imgproc.cvtColor(image, HSV, Imgproc.COLOR_RGB2HSV, 3);

    Mat mHSVThreshed = new Mat();
    //skin color detection
    Core.inRange(HSV,  new Scalar(0, 58, 89), new Scalar(25, 173, 229), mHSVThreshed);

    Mat hierarchy = new Mat(mHSVThreshed.rows(), mHSVThreshed.cols(), CvType.CV_8UC1, new Scalar(0));
    List<Mat> contours =new ArrayList<Mat>(100);

    Imgproc.findContours(mHSVThreshed, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);

    Mat Mask = new Mat();
    Mask = Mat.zeros(mHSVThreshed.rows(), mHSVThreshed.cols(), CvType.CV_8UC1);

    Imgproc.drawContours(Mask, contours, -1, new Scalar(255), Core.FILLED);

    Mat crop = new Mat(image.rows(), image.cols(), CvType.CV_8UC3);

    crop.setTo(new Scalar(0,255,0));

    image.copyTo(crop, Mask);

    Core.normalize(Mask.clone(), Mask, 0.0, 255.0, Core.NORM_MINMAX, CvType.CV_8UC1);

    Mat Biner = new Mat();
    Mask.convertTo(Biner, CvType.CV_8U);

    Imgproc.cvtColor(Biner, image, Imgproc.COLOR_GRAY2RGB, 0);
    Imgproc.cvtColor(image, image, Imgproc.COLOR_RGB2RGBA, 0);

    return image;