简体   繁体   English

坎尼边缘检测器后的opencv Floodfill

[英]opencv floodfill after canny edge detector

private Bitmap CannyImg(Bitmap photo) {

    Mat srcMat = new Mat (photo.getHeight(), photo.getWidth(), CvType.CV_8UC3);
    Bitmap myBitmap32 = photo.copy(Bitmap.Config.ARGB_8888, true);
    Utils.bitmapToMat(myBitmap32, srcMat);
    Mat gray = new Mat(srcMat.size(), CvType.CV_8UC1);
    Imgproc.cvtColor(srcMat, gray, Imgproc.COLOR_RGB2GRAY,4);
    Mat edge = new Mat();
    Mat dst = new Mat();
    Imgproc.Canny(gray, edge, 80, 90);
    Imgproc.cvtColor(edge, dst, Imgproc.COLOR_GRAY2RGBA,4);
    Bitmap resultBitmap = Bitmap.createBitmap(dst.cols(), dst.rows(),Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(dst, resultBitmap);
    return resultBitmap;
}
private static Mat floodFill(Mat img)
{
    Mat floodfilled = Mat.zeros(img.rows() + 2, img.cols() + 2, CvType.CV_8U);
    Imgproc.floodFill(img, floodfilled, new Point(0, 0), new Scalar(255), new Rect(), new Scalar(0), new Scalar(0), 4 + (255 << 8) + Imgproc.FLOODFILL_MASK_ONLY);
    Core.subtract(floodfilled, Scalar.all(0), floodfilled);
    Rect roi = new Rect(1, 1, img.cols() - 2, img.rows() - 2);
    Mat temp = new Mat();
    floodfilled.submat(roi).copyTo(temp);
    img = temp;
    //Core.bitwise_not(img, img);
    return img;
}

//Start OCR Button
    bO.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Bitmap caImg = CannyImg(cropped);
            Bitmap flfill = floodFill(caImg);
            preptessdata();
            startOCR(flfill);
            iv.setImageBitmap(flfill);

Error: Floodfill(org.opencv.core.Mat) cannot be applied to android.graphic.Bitmap My canny works the problem is floodfill 错误:Floodfill(org.opencv.core.Mat)无法应用于android.graphic.Bitmap我的精明作品问题是Floodfill

Your floodFill function is expecting a cv::Mat and you are passing a Bitmap. 您的FloodFill函数期望使用cv :: Mat,并且正在传递位图。

If I understand what you're trying to do you can fix it by having CannyImg return the edge cv::Mat and then pass that cv::Mat to floodFill. 如果我了解您要执行的操作,可以通过使CannyImg返回边缘cv :: Mat并将该cv :: Mat传递给FloodFill来解决。 You'll then have the problem that floodFill is returning a cv::Mat and you're assigning it to a bitmap. 然后,您将遇到FloodFill返回cv :: Mat并将其分配给位图的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM