yuv420p转为emgucv的图像格式Emgu.CV.Image<Bgr, Byte>

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) 编辑 |删除 |推送 |置顶
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值