載入一張照片, 利用 InRange

參數lower和higher顏色BGR上下限篩選感興趣區域,

得到一張遮罩m_img_inRange,再利用CvBlobDetector 進行Blob運算

image

   1: using Emgu.CV;
   2: using Emgu.CV.Cvb;
   3: using Emgu.CV.CvEnum;
   4: using Emgu.CV.Structure;
   5: using Emgu.CV.VideoSurveillance;
   6: using System.Diagnostics;
   7: using System.Threading;
   8:  
   9: private void CalInRange()
  10:         {
  11:             if (m_img_color == null) return;
  12:             m_img_inRange = m_img_color.InRange(lower, higher);
  13:             m_img_inRange_not = m_img_inRange.Not();
  14:             using (CvBlobs blobs = new CvBlobs())
  15:             {
  16:                 m_blobDetector.Detect(m_img_inRange, blobs);
  17:                 m_img_color_copy = m_img_color.Copy();
  18:                 foreach (var pair in blobs)
  19:                 {
  20:                     CvBlob b = pair.Value;
  21:                     CvInvoke.Rectangle(m_img_color_copy, b.BoundingBox, new MCvScalar(255.255, 255, 0), 5);
  22:                     //CvInvoke.PutText(frame,  blob.ID.ToString(), Point.Round(blob.Center), FontFace.HersheyPlain, 1.0, new MCvScalar(255.0, 255.0, 255.0));
  23:                 }
  24:  
  25:                 imageBox1.Image = m_img_color_copy;
  26:                 imageBox2.Image = m_img_inRange;
  27:                 imageBox3.Image = m_img_inRange_not;
  28:             }
  29:         }

image

image

image

image

image

OpenCV Feature Detectors類別支援:

參考資料

1. EmguCV InRange

2. EmguCV CvBlobDetector 

3. OpenCV Feature Detectors

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(1) 人氣()