EmguCV的学习日志(一)

由于需要使用到EmguCV,作为初次接触者,参照官方的wiki,记了一些笔记。原网址: http://www.emgu.com/wiki/index.php/Tutorial#C.23

一、映射

函数映射: Emgu.CV.CvInvoke

结构映射: Emgu.CV.Structure.Mxxx

数值映射: Emgu.CV.CvEnum


  



二、Image

emguCV3.0使用Mat类,内存大小自动分配。

1.1、使用Mat创建Image

    <1>创建一个200*400的三通道图像

    Mat img = new Mat(200, 400, DepthType.Cv8U, 3); 

    Mat img = new Mat(img1.Size,DepthType.Cv8U, 3);

    <2>创建空白Image(在调用cvInvoke的函数需使用新Image时,需要先创建空的Image)       

    Mat img = new Mat();

    <3>从文件读取图像

    Mat img = CvInvoke.Imread("myimage.jpg", CvEnum.LoadImageType.AnyColor);

1.2 使用 Image<,>创建Image

   <1>从文件读取

    Image<Bgr, Byte> img1 = new Image<Bgr, Byte>("MyImage.jpg"); 

   <2>使用Image<TColorTDepth>。但是使用该类下的方法时,必须采用相同的颜色或色深类型。

           如Image<,>中的SetValue(TColor color, Image<Gray, Byte> mask)函数。

    Image<Gray, Byte> image = new Image<Gray, Byte>( width, height);      
 

   <3> 创建带背景色的Image

    Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(480, 320, new Bgr(255, 0, 0));
    Image<Gray, Byte> img1 = new Image<Gray, Byte>(400, 300, new Gray(30)); 

  <4>从 .Net的Bitmap类型创建

    Image<Bgr, Byte> img = new Image<Bgr, Byte>(bmp); //where bmp is a Bitmap

 TColor参数类型:   

    • Gray

    • Bgr (Blue Green Red)

    • Bgra (Blue Green Red Alpha)

    • Hsv (Hue Saturation Value)

    • Hls (Hue Lightness Saturation)

    • Lab (CIE L*a*b*)

    • Luv (CIE L*u*v*)

    • Xyz (CIE XYZ.Rec 709 with D65 white point)

    • Ycc (YCrCb JPEG)

    TDepth参数类型:

    • Byte

    • SByte

    • Single (float)

    • Double

    • UInt16

    • Int16

    • Int32 (int)

2.1.获取Mat类型图像的像素

    Mat类型的大小自动分配,因此没有Data属性来直接获取像素。

    <1>使用 ToImage 方法将Mat类的图像复制到一个Image<,>类型的图像。

    Image<Bgr, Byte> img = mat.ToImage<Bgr, Byte>();

        然后使用Image<,>.Data属性获取图像像素。

2.2.使用Image<,>处理像素

    <1>The safe (slow) way

    Bgr color = img[y, x];

    img[y,x] = color;

    <2>The fast way

        Byte byCurrent = imageGray.Data[x, y, 0];

    <3>运算符重载方式

    Image<Gray, Byte> image3 = (image1 + image2 - 2.0) * 0.5;

 2.3.对Image<,>的所有像素操作

    <1>使用内置函数

    Image<Gray, Byte> img2 = img1.Not();

    img1._Not();//replace

    <2>使用Convert函数,使用匿名委托类型,牺牲很少的效率,但更灵活

   ① Image<Gray, Byte> img3 = img1.Convert<Byte>

        ( delegate(Byte b) { return (Byte) (255-b); } );

    Image<Gray, Single> img4 = img1.Convert<Single>

            ( delegate(Byte b) { return (Single) Math.cos( b * b / 255.0); }  );

2.4.在Image<,>图像上绘制对象

    使用Draw()方法绘制 fonts, lines, circles, rectangles, boxes, ellipses as well as contours

2.5Image<,>图像类型转换

     例如有Image<Bgr, Byte> img1

    Image<Gray, Single> img2 = img1.Convert<Gray, Single>();

2.6显示图像

<1>Emgu的ImageBox控件。直接引用图像内存,速度快。

<2>wimForm的pictureBox控件

     使用ToBitmap()方法,返回Bitmap类型



三、Matrix

    //数据类型参考TDepth的类型列表

    Matrix<Single> matrix = new Matrix<Single>(width, height);



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值