简体   繁体   中英

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

Your floodFill function is expecting a cv::Mat and you are passing a Bitmap.

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. You'll then have the problem that floodFill is returning a cv::Mat and you're assigning it to a bitmap.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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