<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          OpenCV基于DLCO描述子匹配

          共 4050字,需瀏覽 9分鐘

           ·

          2022-07-22 10:35

          點擊上方小白學視覺”,選擇加"星標"或“置頂

          重磅干貨,第一時間送達

           

          一:局部特征描述子介紹
           

          2014年VGG發(fā)表了一篇基于凸優(yōu)化的局部特征描述子學習(DLCO)的論文,OpenCV3.2以后在擴展模塊中對該論文的完成了代碼實現(xiàn)并發(fā)布了API支持,提供了基于DLCO的描述子生成支持、基于生成的描述子,可以實現(xiàn)圖像特征匹配的對象識別。關(guān)于特征描述子學習相關(guān)的細節(jié)可以看這里:

          http://www.robots.ox.ac.uk/~vgg/software/learn_desc/

          提供了描述子模型,學習數(shù)據(jù),C++版本實現(xiàn)的源代碼下載


          二:OpenCV程序演示

          OpenCV中VGG的DLCO描述子生成支持下面幾種

          • VGG_120 = 100,

          • VGG_80 = 101,

          • VGG_64 = 102,

          • VGG_48 = 103

          默認支持輸出描述子是120個向量即VGG_120。基于DLCO在OpenCV中代碼實現(xiàn)對象檢測與匹配大致分為如下幾步:

          1.加載圖像

          1. Mat box = imread("D:/vcprojects/images/box.png");

          2. Mat scene = imread("D:/vcprojects/images/box_in_scene.png");

          3. imshow("box image", box);

          4. imshow("scene image", scene);

          2.關(guān)鍵點檢測(SURF)

          1. Ptr<SURF> detector = SURF::create();

          2. int minHessian = 400;

          3. vector<KeyPoint> keypoints_1, keypoints_2;

          4. detector->setHessianThreshold(minHessian);

          5. detector->detect(box, keypoints_1);

          6. detector->detect(box_scene, keypoints_2);

          3.描述子生成(DLCO)

          1. Ptr<VGG> vgg_descriptor = VGG::create();

          2. Mat descriptors_1, descriptors_2;

          3. vgg_descriptor->compute(box,  keypoints_1, descriptors_1);

          4. vgg_descriptor->compute(box_scene, keypoints_2, descriptors_2);

          4.特征匹配實現(xiàn)對象識別

          1. // 計算匹配點

          2. FlannBasedMatcher matcher;

          3. std::vector< DMatch > matches;

          4. matcher.match(descriptors_1, descriptors_2, matches);

          5. double max_dist = 0; double min_dist = 100;

          6. // 計算最大與最小距離

          7. for (int i = 0; i < descriptors_1.rows; i++)

          8. {

          9.    double dist = matches[i].distance;

          10.    if (dist < min_dist) min_dist = dist;

          11.    if (dist > max_dist) max_dist = dist;

          12. }

          13. printf("-- Max dist : %f \n", max_dist);

          14. printf("-- Min dist : %f \n", min_dist);

          15. // 尋找最佳匹配,距離越小越好

          16. std::vector< DMatch > good_matches;

          17. for (int i = 0; i < descriptors_1.rows; i++)

          18. {

          19.    if (matches[i].distance <= min(2 * min_dist, 1.5))

          20.    {

          21.        good_matches.push_back(matches[i]);

          22.    }

          23. }

          24. // 繪制最終匹配點

          25. Mat img_matches;

          26. drawMatches(box, keypoints_1, box_scene, keypoints_2,

          27.    good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),

          28.    vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

          29. //-- Localize the object

          30. std::vector<Point2f> obj;

          31. std::vector<Point2f> scene;

          32. for (size_t i = 0; i < good_matches.size(); i++)

          33. {

          34.    //-- Get the keypoints from the good matches

          35.    obj.push_back(keypoints_1[good_matches[i].queryIdx].pt);

          36.    scene.push_back(keypoints_2[good_matches[i].trainIdx].pt);

          37. }

          38. Mat H = findHomography(obj, scene, RANSAC);

          39. //-- Get the corners from the image_1 ( the object to be "detected" )

          40. std::vector<Point2f> obj_corners(4);

          41. obj_corners[0] = cvPoint(0, 0); obj_corners[1] = cvPoint(box.cols, 0);

          42. obj_corners[2] = cvPoint(box.cols, box.rows); obj_corners[3] = cvPoint(0, box.rows);

          43. std::vector<Point2f> scene_corners(4);

          44. perspectiveTransform(obj_corners, scene_corners, H);

          45. //-- Draw lines between the corners (the mapped object in the scene - image_2 )

          46. line(img_matches, scene_corners[0] + Point2f(box.cols, 0), scene_corners[1] + Point2f(box.cols, 0), Scalar(0, 255, 0), 4);

          47. line(img_matches, scene_corners[1] + Point2f(box.cols, 0), scene_corners[2] + Point2f(box.cols, 0), Scalar(0, 255, 0), 4);

          48. line(img_matches, scene_corners[2] + Point2f(box.cols, 0), scene_corners[3] + Point2f(box.cols, 0), Scalar(0, 255, 0), 4);

          49. line(img_matches, scene_corners[3] + Point2f(box.cols, 0), scene_corners[0] + Point2f(box.cols, 0), Scalar(0, 255, 0), 4);

          50. //-- Show detected matches

          51. imshow("Good Matches & Object detection", img_matches);

          原圖:

          特征匹配結(jié)果


          好消息!

          小白學視覺知識星球

          開始面向外開放啦??????




          下載1:OpenCV-Contrib擴展模塊中文版教程
          在「小白學視覺」公眾號后臺回復(fù):擴展模塊中文教程即可下載全網(wǎng)第一份OpenCV擴展模塊教程中文版,涵蓋擴展模塊安裝、SFM算法、立體視覺、目標跟蹤、生物視覺、超分辨率處理等二十多章內(nèi)容。

          下載2:Python視覺實戰(zhàn)項目52講
          小白學視覺公眾號后臺回復(fù):Python視覺實戰(zhàn)項目即可下載包括圖像分割、口罩檢測、車道線檢測、車輛計數(shù)、添加眼線、車牌識別、字符識別、情緒檢測、文本內(nèi)容提取、面部識別等31個視覺實戰(zhàn)項目,助力快速學校計算機視覺。

          下載3:OpenCV實戰(zhàn)項目20講
          小白學視覺公眾號后臺回復(fù):OpenCV實戰(zhàn)項目20講,即可下載含有20個基于OpenCV實現(xiàn)20個實戰(zhàn)項目,實現(xiàn)OpenCV學習進階。

          交流群


          歡迎加入公眾號讀者群一起和同行交流,目前有SLAM、三維視覺、傳感器、自動駕駛、計算攝影、檢測、分割、識別、醫(yī)學影像、GAN、算法競賽等微信群(以后會逐漸細分),請掃描下面微信號加群,備注:”昵稱+學校/公司+研究方向“,例如:”張三 + 上海交大 + 視覺SLAM“。請按照格式備注,否則不予通過。添加成功后會根據(jù)研究方向邀請進入相關(guān)微信群。請勿在群內(nèi)發(fā)送廣告,否則會請出群,謝謝理解~


          瀏覽 74
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲中文视频免费 | 诱咪一区二区三区四区 | 欧美操逼視频在线观看 | 九色免费网站 | 日韩人妻在线免费观看 |