首页 > 代码库 > YV12转opencv IplImage
YV12转opencv IplImage
<pre name="code" class="cpp"> int bet(int min, int max, int val) { if (val > max) return max; else if (val < min) return min; else return val; }
void Yv12ToImg(uchar *pin, IplImage* img) { uchar y, cb, cr; int ySize = img->width * img->height; int uSize = ySize / 4; uchar *pY = pin; uchar *pU = pY + ySize; uchar *pV = pU + uSize; uchar r, g, b; int iheight = img->height; int iwidth = img->width; int hwidth = iwidth / 2; uchar* p = (uchar*)(img->imageData); for (int h = 0; h < iheight; h++) { for (int w = 0; w < iwidth; w++) { y = pY[h*iwidth + w]; int offuv = h/2 * hwidth + w/2; cb = pU[offuv]; cr = pV[offuv]; b = uchar(bet(0, 255,(y + 1.772*(cb - 128)))); g = uchar(bet(0, 255, (y - 0.344*(cb - 128) - 0.714*(cr - 128)))); r = uchar(bet(0, 255, (y + 1.402*(cr - 128)))); int offw = w * 3; p[offw] = b; p[offw + 1] = g; p[offw + 2] = r; } p += img->widthStep; } }
YV12转opencv IplImage
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。