<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尋找復(fù)雜背景下物體的輪廓

          共 4674字,需瀏覽 10分鐘

           ·

          2021-06-24 19:19

          點(diǎn)擊上方小白學(xué)視覺”,選擇加"星標(biāo)"或“置頂

          重磅干貨,第一時(shí)間送達(dá)

          本文轉(zhuǎn)自:opencv學(xué)堂


          問題提出


          是一個(gè)來自O(shè)PenCV問答社區(qū) - "answerOpenCV"問題,整編如下:

          (http://answers.opencv.org/question/200422/opencv-c-filling-holes/)
          title:OpenCV / C++ - Filling holes
          content:
          Hello there,
          For a personnel projet, I'm trying to detect object and there shadow. These are the result I have for now: Original:

          Object: 
          Shadow: 
          The external contours of the object are quite good, but as you can see, my object is not full. Same for the shadow. I would like to get full contours, filled, for the object and its shadow, and I don't know how to get better than this (I juste use "dilate" for the moment). Does someone knows a way to obtain a better result please? Regards.

          問題分析


          從原始圖片上來看,這張圖片的拍攝的背景比較復(fù)雜,此外光照也存在偏光現(xiàn)象;而提問者雖然提出的是“將縫隙合并”的要求,實(shí)際上他還是想得到目標(biāo)物體的準(zhǔn)確輪廓。

          問題解決


          基于現(xiàn)有經(jīng)驗(yàn),和OpenCV,GOCVhelper等工具,能夠很快得出以下結(jié)果

          h通道:

          去光差:

          閾值:

          標(biāo)注:



          算法關(guān)鍵

          這套算法首先解決了這個(gè)問題,而且我認(rèn)為也是穩(wěn)健魯棒的。其中,算法中除了經(jīng)典的“hsv分解->ostu閾值->最大輪廓標(biāo)注”外,最為關(guān)鍵的算法為頂帽去光差。這個(gè)算法來自于岡薩雷斯《數(shù)字圖像處理教程》形態(tài)學(xué)篇章,完全按照書本建議實(shí)現(xiàn),體現(xiàn)良好作用。

          //answerOpenCV OpenCV / C++ - Filling holes
          #include "stdafx.h"
          #include <iostream>
          #include <vector>


          using namespace cv;
          using namespace std;

          //find the biggest contour
          vector<Point> FindBigestContour(Mat src){    
              int imax = 0;  
              int imaxcontour = -1;  
              std::vector<std::vector<Point> >contours;    
              findContours(src,contours,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
              for (int i=0;i<contours.size();i++){
                  int itmp =  contourArea(contours[i]);
                  if (imaxcontour < itmp ){
                      imax = i;
                      imaxcontour = itmp;
                  }
              }
              return contours[imax];
          }

          //remove Light difference by using top hat
          Mat moveLightDiff(Mat src,int radius){
              Mat dst;
              Mat srcclone = src.clone();
              Mat mask = Mat::zeros(radius*2,radius*2,CV_8U);
              circle(mask,Point(radius,radius),radius,Scalar(255),-1);
              //top hat
              erode(srcclone,srcclone,mask);
              dilate(srcclone,srcclone,mask);
              dst =  src - srcclone;
              return dst;
          }

          int mainvoid )
          {
              Mat src = imread("e:/sandbox/question.png");
              Mat src_hsv;
              Mat bin;
              Mat src_h;

              cvtColor(src,src_hsv,COLOR_BGR2HSV);
              vector<Mat> rgb_planes;
              split(src_hsv, rgb_planes );
              src_h = rgb_planes[0]; // h channel is useful

              src_h = moveLightDiff(src_h,40);
              threshold(src_h,bin,100,255,THRESH_OTSU);

              //find and draw the biggest contour
              vector<Point> bigestcontrour =  FindBigestContour(bin);
              vector<vector<Point> > controus;
              controus.push_back(bigestcontrour);
              cv::drawContours(src,controus,0,Scalar(0,0,255),3);

              waitKey();
              return 0;
          }


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

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

          下載3:OpenCV實(shí)戰(zhàn)項(xiàng)目20講
          小白學(xué)視覺公眾號(hào)后臺(tái)回復(fù):OpenCV實(shí)戰(zhàn)項(xiàng)目20講,即可下載含有20個(gè)基于OpenCV實(shí)現(xiàn)20個(gè)實(shí)戰(zhàn)項(xiàng)目,實(shí)現(xiàn)OpenCV學(xué)習(xí)進(jìn)階。

          交流群


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


          瀏覽 57
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <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>
                  久久色亚洲 | 乱伦免费视频中文字幕 | 大香蕉青青免费 | 91乱子伦国产乱子伦www.sz-sd.cn | 伊人9999 |