• openCV 放大


        IplImage* img_src0 = cvLoadImage("d:\\1.jpg");
        IplImage* img_src1 = cvLoadImage("d:\\1.jpg");

        CvRect rect0 = cvRect(59, 19, 62, 32);
        CvRect rect1 = cvRect(25, 94, 24, 116);
        //cvRectangleR(img_src, rect0, CV_RGB(255, 0, 0));
        cvSetImageROI(img_src0, rect0);
        double dDiff = ComputeTextureDiff(img_src0, img_src1);
        printf("%f",dDiff);

        cvDilate(img_src0, img_src0);
        cvErode(img_src0, img_src0);
        Mat img1=Mat(img_src0, false);

        //cvSetImageROI(img_src1, rect0);
        CvPoint2D32f center = cvPoint2D32f(img_src1->width/4.5, img_src1->height/1.8);  
        CvMat* mat_rot    = cvCreateMat(2,3,CV_32FC1);
        cv2DRotationMatrix(center, 0, 2.5, mat_rot);
        // do the transformation
        cvWarpAffine(img_src1, img_src1, mat_rot);

        Mat img2=Mat(img_src1, false);

        if (img1.empty() ||img2.empty())
            return -1;

        int minHessian = 1000;

        SurfFeatureDetector detector( minHessian );

        std::vector<KeyPoint> keypoints_1, keypoints_2;
        
        detector.detect( img1, keypoints_1 );
        detector.detect( img2, keypoints_2 );

        //-- Step 2: Calculate descriptors (feature vectors)
        SurfDescriptorExtractor extractor;

        Mat descriptors_1, descriptors_2;

        extractor.compute( img1, keypoints_1, descriptors_1 );
        extractor.compute( img2, keypoints_2, descriptors_2 );

        //-- Step 3: Matching descriptor vectors with a brute force matcher
        FlannBasedMatcher matcher;  
        std::vector< DMatch > matches;  
        matcher.match( descriptors_1, descriptors_2, matches );  

        double max_dist = 0; double min_dist = 100;  

        //-- Quick calculation of max and min distances between keypoints  
        for( int i = 0; i < descriptors_1.rows; i++ )  
        { double dist = matches[i].distance;  
        if( dist < min_dist ) min_dist = dist;  
        if( dist > max_dist ) max_dist = dist;  
        }  

        printf("-- Max dist : %f \n", max_dist );  
        printf("-- Min dist : %f \n", min_dist );  

        //-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist )  
        //-- PS.- radiusMatch can also be used here.  
        std::vector< DMatch > good_matches;  

        for( int i = 0; i < descriptors_1.rows; i++ )  
        { if( matches[i].distance < 2*min_dist )  
            { good_matches.push_back( matches[i]); }  
        }    

        //-- Draw matches
        Mat img_matches;
        drawMatches( img1, keypoints_1, img2, keypoints_2, matches, img_matches );

        //-- Show detected matches
        imshow("Matches", img_matches );

        waitKey(0);

        return 0;

  • 相关阅读:
    react-redux不完全指北
    ztext简单的介绍
    svg配合css多变形
    微服务异常感知与快速定位排错
    K8S(rancher) 服务(POD)定时重启服务方案
    记一次简单的微服务项目拆分
    K8S(rancher)Nginx Ingress Controller 负载均衡多路径问题解决方案
    15个必须知道的JavaScript数组方法
    python实现视频分帧
    python实现随机复制若干个文件到新目录
  • 原文地址:https://www.cnblogs.com/cplusplus/p/2951626.html
Copyright © 2020-2023  润新知