我正在使用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());
}
}
}