我用的版本为Android的opencv的3.4.2版本
我从python和c语言一个一个试过来过来的能用的功能
我做过的项目有:1.手绘几何图像识别,2.相机图片截取并透视变换,3.数字识别,不提供项目代码,但亲测可用
Mat就类似于Bitamp类,但是在我这个版本(V3.4.2)不能与Bitmap互相转换,V4.0+以后的版本可以互转
List<MatOfPoint> contours=new ArrayList<>();//点集
MatOfInt hull;
MatOfPoint2f approx;
Mat src = Imgcodecs.imread(input/**你的文件路径string*/, Imgcodecs.IMREAD_UNCHANGED);//读取图形
Mat dst = new Mat();
Mat kernel = new Mat(3, 3, CvType.CV_32F, new Scalar(-1));
kernel.put(1, 1, 8.9);//这个我忘记干啥的了,但是锐化得用 sorry
Imgproc.filter2D(src, dst, src.depth(), kernel);//锐化
Imgproc.cvtColor(dst, dst, Imgproc.COLOR_RGB2GRAY);//灰度化
Imgproc.GaussianBlur(dst, dst, new Size(15, 15), 0, 0);//高斯滤波
Imgproc.dilate(dst, dst, new Mat(), new Point(-1, -1), 3, 1, new Scalar(1)); // 膨胀,连接边缘
Imgproc.Canny(dst, dst, 10, 22);//边缘检测
Imgproc.threshold(dst, dst, 0, 255, Imgproc.THRESH_OTSU);//二值化
Imgproc.findContours(dst, contours, hierarchy, Imgproc.RETR_LIST, CHAIN_APPROX_SIMPLE); //查找轮廓点
Imgproc.drawContours(dst, contours, -1, new Scalar(255, 255, 255), 3);//绘制点
Mat element = Imgproc.getStructuringElement(Imgproc.MARKER_CROSS, new Size(3, 3));
Imgproc.dilate(dst, dst, element);//膨胀
Imgproc.erode(dst, dst, element);//腐蚀
Imgproc.morphologyEx(dst, dst, Imgproc.MORPH_GRADIENT, element);//闭运算
//透视变换
Mat pt = Imgproc.getPerspectiveTransform(mat/**存有4个点的变换前Mat类型*/, size/**存有4个点的变换后Mat类型*/);
Imgproc.warpPerspective(src, src, pt, new Size(maxSize.width, maxSize.height), INTER_LINEAR);
Rect rectangleIn = Imgproc.boundingRect(new MatOfPoint(contours.get(i).toArray()/**轮廓的集合*/));//最小外接矩形
如有错误恳请纠正,转载请注明出处