{"id":9204,"date":"2016-12-02T06:48:15","date_gmt":"2016-12-02T11:48:15","guid":{"rendered":"httpss:\/\/www.powenko.com\/wordpress\/?p=9204"},"modified":"2016-12-02T06:50:14","modified_gmt":"2016-12-02T11:50:14","slug":"9204","status":"publish","type":"post","link":"https:\/\/www.powenko.com\/wordpress\/?p=9204","title":{"rendered":"03 surf \u627e\u7279\u5fb5\u9ede\u548c\u914d\u5c0d"},"content":{"rendered":"<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;opencv2\/core\/core.hpp&gt;\r\n#include &lt;opencv2\/features2d\/features2d.hpp&gt;\r\n#include &lt;opencv2\/nonfree\/features2d.hpp&gt;\r\n#include &lt;opencv2\/highgui\/highgui.hpp&gt;\r\n#include &lt;opencv2\/nonfree\/nonfree.hpp&gt;\r\n\r\nusing namespace cv;\r\n\r\nvoid readme();\r\n\r\n\/** @function main *\/\r\nint main( int argc, char** argv )\r\n{\r\n    \/\/if( argc != 3 )\r\n    \/\/{ readme(); return -1; }\r\n    \r\n    Mat img_1 = imread( &quot;\/Users\/powenko\/Desktop\/taipei_101_2.jpg&quot;, CV_LOAD_IMAGE_GRAYSCALE );\r\n    Mat img_2 = imread( &quot;\/Users\/powenko\/Desktop\/taipei_101.jpg&quot;, CV_LOAD_IMAGE_GRAYSCALE );\r\n    \r\n    if( !img_1.data || !img_2.data )                                                    \/\/\u5982\u679c\u6578\u64da\u70ba\u7a7a\r\n    { std::cout&lt;&lt; &quot; --(!) Error reading images &quot; &lt;&lt; std::endl; return -1; }\r\n    \r\n    \r\n    \r\n    \/\/-- Step 1: Detect the keypoints using SURF Detector \u00a0\u00a0\u00a0\u00a0\/\/\u7b2c\u4e00\u6b65\uff0c\u7528SIFT\u7b97\u5b50\u6aa2\u6e2c\u95dc\u9375\u9ede\r\n    int minHessian = 400;\r\n    \r\n    SurfFeatureDetector detector( minHessian );\r\n    std::vector&lt;KeyPoint&gt; keypoints_1, keypoints_2;\r\n    \r\n    detector.detect( img_1, keypoints_1 );\r\n    detector.detect( img_2, keypoints_2 );\r\n    \r\n    \/\/-- Draw keypoints \u00a0\/\/\u5728\u5716\u50cf\u4e2d\u756b\u51fa\u7279\u5fb5\u9ede\r\n    Mat img_keypoints_1; Mat img_keypoints_2;\r\n    \r\n    drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );\r\n    drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );\r\n    \r\n    \/\/-- Show detected (drawn) keypoints\r\n    imshow(&quot;Keypoints 1&quot;, img_keypoints_1 );\r\n    imshow(&quot;Keypoints 2&quot;, img_keypoints_2 );\r\n    \r\n    \/\/\u8a08\u7b97\u7279\u5fb5\r\n    SurfDescriptorExtractor extractor;\/\/\u5b9a\u7fa9\u5c0d\u8c61\r\n    \r\n    Mat descriptors_1,descriptors_2;\/\/\u5b58\u653e\u7279\u5fb5\u5411\u91cf\u7684\u8209\u9663\r\n    \r\n    extractor.compute(img_1,keypoints_1,descriptors_1);\/\/\u8a08\u7b97\u7279\u5fb5\u5411\u91cf\r\n    extractor.compute(img_2,keypoints_2,descriptors_2);\r\n    \r\n    \/\/-- Step 3: Matching descriptor vectors with a brute force matcher\r\n    BFMatcher matcher(NORM_L2);\r\n    std::vector&lt; DMatch &gt; matches;\r\n    matcher.match( descriptors_1, descriptors_2, matches );\r\n    \r\n    \/\/-- Draw matches\r\n    Mat img_matches;\r\n    drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );\r\n    \r\n    \/\/-- Show detected matches\r\n    imshow(&quot;Matches&quot;, img_matches );\r\n    \r\n    waitKey(0);\r\n    \r\n    return 0;\r\n}\r\n\r\n\/** @function readme *\/\r\nvoid readme()\r\n{ std::cout &lt;&lt; &quot; Usage: .\/SURF_detector &lt;img1&gt; &lt;img2&gt;&quot; &lt;&lt; std::endl; }\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;stdio.h&gt; #include &lt;iostream&gt; #inc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9205,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[338],"tags":[],"class_list":["post-9204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ch06-surfsift"],"_links":{"self":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/9204"}],"collection":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9204"}],"version-history":[{"count":3,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/9204\/revisions"}],"predecessor-version":[{"id":9210,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/9204\/revisions\/9210"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/9205"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}