EmguCV 绘画图形

1.Image类中绘图常用函数列表

 

实践验证

///初始化图片

private void Form1_Load(object sender, EventArgs e)

        {

            oldpic = new Emgu.CV.Image<Bgr, byte>(500, 400, new Bgr(Color.AliceBlue));

            pictureBox1.Image = oldpic.Bitmap;

        }

/// 画-矩?形?

            Emgu.CV.Image<Bgr, byte> pic1 = oldpic.Clone();

            pic1.Draw(new Rectangle(100, 100, 120, 150), new Bgr(Color.Red), 5);

            pic1.Draw(new Rectangle(100, 100, 120, 150), new Bgr(Color.Red), 5, Emgu.CV.CvEnum.LineType.FourConnected, 1); //缩小为原来1/2,起点位置也一样

            pic1.Draw(new Rectangle(100, 100, 120, 150), new Bgr(Color.Red), 5, Emgu.CV.CvEnum.LineType.FourConnected, 2);//缩小为原来1/4,起点位置也一样

            pic1.Draw(new Rectangle(100, 100, 120, 150), new Bgr(Color.Red), 5, Emgu.CV.CvEnum.LineType.FourConnected, 3);//缩小为原来1/8,起点位置也一样

            pictureBox1.Image = pic1.Bitmap;

            pic1.Dispose();

运行如下:

画圆和椭圆类如画矩形 ,画文字

Emgu.CV.Image<Bgr, byte> pic1 = oldpic.Clone();

            pic1.Draw(new CircleF(new PointF(100, 100), 50), new Bgr(Color.Red), 5);

            pic1.Draw(new Ellipse((RectangleF)(new Rectangle(100, 100, 120, 150))), new Bgr(Color.Red), 5); //注意类型转换

string a = "OK";

pic1.Draw(a, new Point(100, 250), Emgu.CV.CvEnum.FontFace.HersheyComplex, 5, new Bgr(Color.YellowGreen),5);

 

            pictureBox1.Image = pic1.Bitmap;

            pic1.Dispose();

运行如下:

工程实际用到画轮廓(根据点位进行),实际上又是调用画线的函数

Point[] poi = new Point[6];

Emgu.CV.Image<Bgr, byte> pic1 = oldpic.Clone();

            for (int i = 0; i < 6; i++)

            {

                poi[i] = new Point(i * 50 + 50, i*i * 8 + 50);

pic1.Draw(new Cross2DF(poi[i], 20, 20), new Bgr(Color.Black), 2);

            }

            pic1.Draw(poi, new Bgr(Color.Red),3,Emgu.CV.CvEnum.LineType.AntiAlias);

            pictureBox1.Image = pic1.Bitmap;

            pic1.Dispose();

运行如下:

绘制多线形跟画轮廓一样,主要看是否闭合,第二个参数不同

pic1.DrawPolyline(poi,false, new Bgr(Color.Red), 3, Emgu.CV.CvEnum.LineType.AntiAlias);

对于MAT类可以先转Image 绘完后再转回。

特别指出在实际案例中会  统一一起绘制时采用此方式 int contourIdx 设定负数,全部一起

public void Draw(IInputArray contours, int contourIdx, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, IInputArray hierarchy = null, int maxLevel = 2147483647, Point offset = null);

 

posted on 2018-03-03 18:31  努力的毛毛虫  阅读(861)  评论(0编辑  收藏  举报

导航