{"id":9191,"date":"2016-12-02T06:33:38","date_gmt":"2016-12-02T11:33:38","guid":{"rendered":"httpss:\/\/www.powenko.com\/wordpress\/?p=9191"},"modified":"2016-12-02T06:38:54","modified_gmt":"2016-12-02T11:38:54","slug":"02-sift-%e9%85%8d%e5%b0%8d%e7%89%b9%e5%be%b5%e9%bb%9e","status":"publish","type":"post","link":"https:\/\/www.powenko.com\/wordpress\/?p=9191","title":{"rendered":"02 sift \u914d\u5c0d\u7279\u5fb5\u9ede"},"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    SiftDescriptorExtractor 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<p><a href=\"httpss:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9192\" src=\"httpss:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM.png\" alt=\"screen-shot-2016-12-02-at-7-32-56-pm\" width=\"1011\" height=\"818\" srcset=\"https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM.png 1011w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM-300x243.png 300w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM-570x461.png 570w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM-316x256.png 316w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM-120x97.png 120w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM-210x170.png 210w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM-496x401.png 496w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-02-at-7.32.56-PM-140x113.png 140w\" sizes=\"(max-width: 1011px) 100vw, 1011px\" \/><\/a><\/p>\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":9192,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[338],"tags":[],"class_list":["post-9191","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\/9191"}],"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=9191"}],"version-history":[{"count":4,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/9191\/revisions"}],"predecessor-version":[{"id":9199,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/9191\/revisions\/9199"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/9192"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}