fillPolly() and drawContours() not working

asked 2016-12-07 06:50:09 -0600

I am new to image processing and I cant get fillPoly() working. Also, drawContours() is leaving some spaces while drawing contours

   Size sSize5 = new Size(5, 5);


    mIntermediateMat = new Mat();

    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.al);
    ;
    Mat rgba = new Mat(bmp.getHeight(), bmp.getWidth(), CvType.CV_8UC1);
    Utils.bitmapToMat(bmp, rgba);


    Size sizeRgba = rgba.size();

    Mat rgbaInnerWindow, greyInnerWindow;

    int rows = (int) sizeRgba.height;
    int cols = (int) sizeRgba.width;

    int left = cols / 19;
    int top = rows / 19;
    int width = cols * 15 / 16;


    int height = rows * 15 / 16;


    rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);

    greyInnerWindow = new Mat();

    Mat mRgba = new Mat();


    Imgproc.cvtColor(rgbaInnerWindow, greyInnerWindow, Imgproc.COLOR_RGBA2GRAY);

    Imgproc.GaussianBlur(greyInnerWindow, greyInnerWindow, sSize5, 2, 2);


    Imgproc.Canny(greyInnerWindow, mIntermediateMat, 5, 35);

    Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);



    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

    Imgproc.findContours(mIntermediateMat, contours, mHierarchy, Imgproc.RETR_EXTERNAL,
            Imgproc.CHAIN_APPROX_SIMPLE);

    for( int i = 0; i< contours.size(); i++ )
    {
        Imgproc.drawContours(rgbaInnerWindow, contours, i, new Scalar(0, 0, 255), -1);

        Imgproc.fillPoly(rgbaInnerWindow, contours, new Scalar(0, 0, 255));

    }
    Bitmap resultBitmap = Bitmap.createBitmap(rgbaInnerWindow.cols(), rgbaInnerWindow.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(rgbaInnerWindow, resultBitmap);
    imageView.setImageBitmap(resultBitmap);
edit retag flag offensive close merge delete