天天看点

Android Opencv(四)

图层金字塔与reSize

Pyramid中文金字塔,因此pyrDown和pyrUp函数也是十分形象的,

pyrDown和pyrUp都是先进行了5x5的高斯模糊,再进行了大小的改变。

pyrDown和pyrUp每调用一次,只能缩小2倍或者放大2倍。如果就单纯的图片尺寸的缩放来说,效率没有reSize高。

resize就是纯粹的根据比例改变长宽。

角点检测

//转换为单通道            Imgproc.cvtColor(drawing,drawing,COLOR_RGB2GRAY);
            drawing.convertTo(drawing,CvType.CV_8UC1);
            Imgproc.goodFeaturesToTrack(drawing,corners,4,0.1,30);
            MatOfPoint2f point2f=new MatOfPoint2f();
            corners.convertTo(point2f,CvType.CV_32FC2);
            Point[] allpoint=point2f.toArray();
            for (Point point:allpoint){
                Imgproc.circle(drawing,point,50,new Scalar(255,0,255));      

线段检测

public static final Mat lineSegmentDetector(Mat srcmat) {
        Mat line = new Mat();
        LineSegmentDetector lsd = new Imgproc().createLineSegmentDetector();
        lsd.detect(srcmat, line);
        lsd.drawSegments(srcmat, line);
       return      

质心

.moments(drawing);
        Point centerpoint = new Point(moments.get_m10() / moments.get_m00(), moments.get_m01() / moments.get_m00());      

根据2点计算所在直线参数

private  static double[] getLineParams(Point linepoint1, Point linepoint2){
        // 两点式公式为(y - y1)/(x - x1) = (y2 - y1)/ (x2 - x1)
        // 化简为一般式为(y2 - y1)x + (x1 - x2)y + (x2y1 - x1y2) = 0
        // A = y2 - y1
        // B = x1 - x2
        // C = x2y1 - x1y2
        double a = linepoint2.y - linepoint1.y;
        double b = linepoint1.x - linepoint2.x;
        double c = linepoint2.x * linepoint1.y - linepoint1.x * linepoint2.y;
        double[] abc=new double[]{a,b,c};
        return