GCHandle handle = GCHandle.Alloc(yuvs, GCHandleType.Pinned);
Emgu.CV.Image<Bgr, Byte> image = new Image<Bgr, Byte>(640, 480);
using (Image<Bgr, Byte> yuv420p = new Image<Bgr, byte>(640, (480 >> 1) * 3, 640, handle.AddrOfPinnedObject()))
{
CvInvoke.CvtColor(yuv420p, image, Emgu.CV.CvEnum.ColorConversion.Yuv420P2Bgr); //image now contains the same yuv image in bgr color space //
this.imgboxVideo.Image = image;
}
if (handle.IsAllocated) handle.Free();
說明:
1、yuvs為yuv的byte[]數組,
假設ys,vs,us為一幀圖像的y,u,v對應的數組,可以這樣擷取
byte[] yuvs = new byte[ys.Length + vs.Length + us.Length]; ys.CopyTo(yuvs, 0); vs.CopyTo(yuvs, ys.Length); us.CopyTo(yuvs, ys.Length + vs.Length);
2. 640為yuv圖像的寬,480為高,根據實際需要修改
3.效率上建立Image比較慢
Emgu.CV.Image<Bgr, Byte> image = new Image<Bgr, Byte>(640, 480);,
可以作為程式的全局變量一開始建立,其他轉換很快的
Emgu.CV.CvEnum.ColorConversion有很多枚舉值,注意根據yuv格式進行選擇。比如yv12有Yuv2BgrYv12
閱讀(0)| 評論(0) | 編輯 |删除 |推送 |置頂