zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    [Baltic2013]ballmachine BZOJ3133
    [Jxoi2012]奇怪的道路 BZOJ3195 状压DP
    [Baltic 2011]Lamp BZOJ2346
    可并堆
    [Jsoi2016]最佳团体 BZOJ4753 01分数规划+树形背包/dfs序
    点分治
    J2EE WEB应用架构分析
    {经典}springmvc+mybatis+restful+webservice Jeesz分布式架构
    深入Spring Boot:那些注入不了的 Spring 占位符 ( ${} 表达式 )
    G1 垃圾收集器之对象分配过程
  • 原文地址:https://www.cnblogs.com/cplusplus/p/2951626.html
Copyright © 2011-2022 走看看