3
我使用Emgu CV,我想檢測兩個銳利的畫面,我首先轉換爲灰度圖像,並調用cvCanny,然後調用FindContours,但只找到了一個輪廓,三角形沒有找到。
代碼:
public static void Do(Bitmap bitmap, IImageProcessingLog log)
{
Image<Bgr, Byte> img = new Image<Bgr, byte>(bitmap);
Image<Gray, Byte> gray = img.Convert<Gray, Byte>();
using (Image<Gray, Byte> canny = new Image<Gray, byte>(gray.Size))
using (MemStorage stor = new MemStorage())
{
CvInvoke.cvCanny(gray, canny, 10, 5, 3);
log.AddImage("canny",canny.ToBitmap());
Contour<Point> contours = canny.FindContours(
Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE,
stor);
for (int i=0; contours != null; contours = contours.HNext)
{
i++;
MCvBox2D box = contours.GetMinAreaRect();
Image<Bgr, Byte> tmpImg = img.Copy();
tmpImg.Draw(box, new Bgr(Color.Red), 2);
log.AddMessage("contours" + (i) +",angle:"+box.angle.ToString() + ",width:"+box.size.Width + ",height:"+box.size.Height);
log.AddImage("contours" + i, tmpImg.ToBitmap());
}
}
}
我們爲什麼需要分成3個頻道?那麼在彩色圖像之後,Canny會不會很好地工作?或轉換爲灰色? – Mikos 2012-08-09 16:24:02
沒有必要吐。你可以轉換成灰度級並使用Canny邊緣檢測器。 – Michael 2012-09-11 20:42:37