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);
错误:Floodfill(org.opencv.core.Mat)无法应用于android.graphic.Bitmap 我的canny可以工作,问题在于floodfill