fillPolly()和drawContours()无法正常工作 - Android

时间:2016-12-08 06:38:20

标签: android opencv image-processing

我是图像处理的新手,我不能让fillPoly()工作。此外,drawContours()在绘制轮廓时会留下一些空格。我正在使用Android,并且在互联网上提供的大多数参考资料都是Python,Matlab或C ++

   sSize5 = new Size(5, 5);


    mIntermediateMat = new Mat();

    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.contours_in_contours_red);

    Mat rgba = new Mat(bmp.getHeight(), bmp.getWidth(), CvType.CV_8UC1);
    Utils.bitmapToMat(bmp, rgba);

    Mat greyInnerWindow;
    greyInnerWindow = new Mat();

    Mat mRgba = new Mat();


    Imgproc.cvtColor(rgba, 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(rgba, contours, i, new Scalar(0, 255, 0), -1);

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

    }
    Bitmap resultBitmap = Bitmap.createBitmap(rgba.cols(), rgba.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(rgba, resultBitmap);
    imageView.setImageBitmap(resultBitmap);

This is the image on which I am using fillPoly() and drawContours()

This is after using the above code

enter image description here

enter image description here

0 个答案:

没有答案