yuv420p轉為emgucv的圖像格式Emgu.CV.Image


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) 編輯 |刪除 |推送 |置頂


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM