码迷,mamicode.com
首页 > 其他好文 > 详细

YV12转opencv IplImage

时间:2015-01-08 18:01:21      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

<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

标签:

原文地址:http://blog.csdn.net/tobacco5648/article/details/42526759

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!