1. 程式人生 > >YUV轉RGB彙總

YUV轉RGB彙總

#region ******************彩色影象記錄的格式,YUV 轉 RGB******************

        /* YUV, http://zh.wikipedia.org/wiki/YUV#.E5.B8.B8.E7.94.A8.E7.9A.84YUV.E6.A0.BC.E5.BC.8F
         *  作為視訊媒體型別的輔助說明型別(Subtype),它們對應的GUID如下:
         *  在DirectShow中,常見的RGB和YUV格式
            GUID                                格式描述
            MEDIASUBTYPE_RGB1                       2色,每個畫素用1位表示,需要調色盤
            MEDIASUBTYPE_RGB4                       16色,每個畫素用4位表示,需要調色盤
            MEDIASUBTYPE_RGB8                       256色,每個畫素用8位表示,需要調色盤
            MEDIASUBTYPE_RGB565                     每個畫素用16位表示,RGB分量分別使用5位、6位、5位
            MEDIASUBTYPE_RGB555                     每個畫素用16位表示,RGB分量都使用5位(剩下的1位不用)
            MEDIASUBTYPE_RGB24                      每個畫素用24位表示,RGB分量各使用8位
            MEDIASUBTYPE_RGB32                      每個畫素用32位表示,RGB分量各使用8位(剩下的8位不用)
            MEDIASUBTYPE_ARGB32                     每個畫素用32位表示,RGB分量各使用8位(剩下的8位用於表示Alpha通道值)
         *
            MEDIASUBTYPE_YUY2                    YUY2格式,以4:2:2方式打包
            MEDIASUBTYPE_YUYV                    YUYV格式(實際格式與YUY2相同)
            MEDIASUBTYPE_YVYU                    YVYU格式,以4:2:2方式打包
            MEDIASUBTYPE_UYVY                    UYVY格式,以4:2:2方式打包
            MEDIASUBTYPE_AYUV                    帶Alpha通道的4:4:4 YUV格式
            MEDIASUBTYPE_Y41P                    Y41P格式,以4:1:1方式打包
            MEDIASUBTYPE_Y411                    Y411格式(實際格式與Y41P相同)
            MEDIASUBTYPE_Y211                    Y211格式
            MEDIASUBTYPE_IF09                    IF09格式
            MEDIASUBTYPE_IYUV                    IYUV格式
            MEDIASUBTYPE_YV12                    YV12格式
            MEDIASUBTYPE_YVU9                    YVU9格式
         */


        #region RGB TO RGB32

        /* RGB32 */
        /// <summary>
        /// 根據指標地址及記憶體塊長度,獲取RGB32陣列
        /// @20140516
        /// </summary>
        /// <param name="pBuffer"></param>
        /// <param name="lBufferSize"></param>
        /// <param name="lPicWidth"></param>
        /// <param name="lPicHeight"></param>
        /// <returns></returns>
        public static byte[] GetRgb32_FromIntptr(IntPtr pBuffer, Int32 lBufferSize, Int32 lPicWidth, Int32 lPicHeight)
        {
            // 設定陣列大小
            byte[] rgba32 = new byte[lPicHeight * lPicWidth * 4];
            Marshal.Copy(pBuffer, rgba32, 0, lBufferSize);

            return rgba32;
        }

        #endregion


        #region YUV TO RGB32

        /// <summary>
        /// YUV 轉 RGB32
        /// </summary>
        /// <param name="pYPlaneByte"></param>
        /// <param name="pVPlaneByte"></param>
        /// <param name="pUPlaneByte"></param>
        /// <param name="lPicHeight"></param>
        /// <param name="lPicWidth"></param>
        /// <param name="bError">是否存在錯誤</param>
        /// <param name="strErrorDesc">錯誤訊息</param>
        /// <returns></returns>
        public static byte[] GetRgb32_From_Yuv(byte[] pYPlaneByte, byte[] pUPlaneByte, byte[] pVPlaneByte, Int32 lPicHeight, Int32 lPicWidth, ref bool bError, ref string strErrorDesc)
        {
            bError = true;
            strErrorDesc = "無錯誤";
            int picSize = lPicWidth * lPicHeight;

            byte[] pRrgaByte = new byte[picSize * 4];
            int A = 0;

            try
            {
                for (int iRow = 0; iRow < lPicHeight; iRow++)
                {
                    for (int jCol = 0; jCol < lPicWidth; jCol++)
                    {
                        //int Y = pYPlane[i * dwWidth + j];
                        //int U = pUPlane[(i / 2) * (dwWidth / 2) + (j / 2)];
                        //int V = pVPlane[(i / 2) * (dwWidth / 2) + (j / 2)];
                        //int R = Y + (U - 128) + (((U - 128) * 103) >> 8);
                        //int G = Y - (((V - 128) * 88) >> 8) - (((U - 128) * 183) >> 8);
                        //int B = Y + (V - 128) + (((V - 128) * 198) >> 8);
                        //R = max(0, min(255, R));
                        //G = max(0, min(255, G));
                        //B = max(0, min(255, B));

                        int Y = pYPlaneByte[iRow * lPicWidth + jCol];
                        int U = pUPlaneByte[(iRow / 2) * (lPicWidth / 2) + (jCol / 2)];
                        int V = pVPlaneByte[(iRow / 2) * (lPicWidth / 2) + (jCol / 2)];

                        /* 存在顏色轉換錯誤問題。現象:公交車編號的LED燈顯示顏色,與實際不符。如K30,圖片上的30顏色為藍色,但實際上30是紅色 */
                        /* 1、宣傳橫幅,紅色變成藍色 */
                        /* 2、公交編號LED,紅色變成藍色 */
                        /* 3、訊號燈LED,紅色變成藍色 */
                        //int R = Y + (U - 128) + (((U - 128) * 103) >> 8);
                        //int G = Y - (((V - 128) * 88) >> 8) - (((U - 128) * 183) >> 8);
                        //int B = Y + (V - 128) + (((V - 128) * 198) >> 8);

                        // http://zh.wikipedia.org/wiki/YUV#YV12
                        //Int32 R = Y + 1.13983 * (V - 128);
                        //Int32 G = Y - 0.39456 * (U - 128) - 0.58060 * (V - 128);
                        //Int32 B = Y + 2.03211 * (U - 128);

                        /* 2012.12.24,糾正顏色錯位問題R與B */
                        int R = Y + (V - 128) + (((V - 128) * 103) >> 8);
                        int G = Y - (((U - 128) * 88) >> 8) - (((V - 128) * 183) >> 8);
                        int B = Y + (U - 128) + (((U - 128) * 198) >> 8);

                        R = Math.Max(0, Math.Min(255, R));
                        G = Math.Max(0, Math.Min(255, G));
                        B = Math.Max(0, Math.Min(255, B));

                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 0] = Convert.ToByte(B);
                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 1] = Convert.ToByte(G);
                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 2] = Convert.ToByte(R);
                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 3] = Convert.ToByte(A);

                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 0] = Convert.ToByte(R);
                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 1] = Convert.ToByte(G);
                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 2] = Convert.ToByte(B);
                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 3] = Convert.ToByte(A);
                    }
                }

                return pRrgaByte;
            }
            catch (Exception exp)
            {
                pRrgaByte = null;

                bError = false;
                strErrorDesc = exp.ToString();
                //throw;
            }

            return null;
        }

        /* YUV420 / I420 
         * 儲存格式:yuv yuv yuv
         */

        /* YUV420P: 
         * 儲存格式:yyyyyyyy uuuuuuuu vvvvv
         * yuv420p 和 YUV420的區別 在儲存格式上有區別
            yuv420p:yyyyyyyy uuuuuuuu vvvvv
            yuv420: yuv yuv yuv
         */

        /// <summary>
        /// GetRgb32_From_Yuv420
        /// @20140521,記憶體排列順序有疑問
        /// </summary>
        /// <param name="pYuvPackedByte"></param>
        /// <param name="lBuffSize"></param>
        /// <param name="lPicHeight"></param>
        /// <param name="lPicWidth"></param>
        /// <param name="bError"></param>
        /// <param name="strErrorDesc"></param>
        /// <returns></returns>
        public static byte[] GetRgb32_From_Yuv420(byte[] pYuvPackedByte, Int32 lBuffSize, Int32 lPicHeight, Int32 lPicWidth, ref bool bError, ref string strErrorDesc)
        {
            bError = true;
            int picSize = lPicWidth * lPicHeight;
            strErrorDesc = string.Format("無錯誤.picSize4 = '{0}', lBuffSize1.5 = '{1}'", picSize * 4, lBuffSize * 3 / 2);

            byte[] pRrgaByte = new byte[picSize * 4];
            int A = 0;

            try
            {
                for (int iRow = 0; iRow < lPicHeight; iRow++)
                {
                    for (int jCol = 0; jCol < lPicWidth; jCol++)
                    {
                        int Y = pYuvPackedByte[iRow * lPicWidth + jCol + 0];
                        int U = pYuvPackedByte[iRow * lPicWidth + jCol + 1];
                        int V = pYuvPackedByte[iRow * lPicWidth + jCol + 2];

                        // http://zh.wikipedia.org/wiki/YUV#YV12
                        //Int32 R = Y + 1.13983 * (V - 128);
                        //Int32 G = Y - 0.39456 * (U - 128) - 0.58060 * (V - 128);
                        //Int32 B = Y + 2.03211 * (U - 128);

                        /* 2012.12.24,糾正顏色錯位問題R與B */
                        int R = Y + (V - 128) + (((V - 128) * 103) >> 8);
                        int G = Y - (((U - 128) * 88) >> 8) - (((V - 128) * 183) >> 8);
                        int B = Y + (U - 128) + (((U - 128) * 198) >> 8);

                        R = Math.Max(0, Math.Min(255, R));
                        G = Math.Max(0, Math.Min(255, G));
                        B = Math.Max(0, Math.Min(255, B));

                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 0] = Convert.ToByte(B);
                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 1] = Convert.ToByte(G);
                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 2] = Convert.ToByte(R);
                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 3] = Convert.ToByte(A);

                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 0] = Convert.ToByte(R);
                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 1] = Convert.ToByte(G);
                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 2] = Convert.ToByte(B);
                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 3] = Convert.ToByte(A);
                    }
                }

                return pRrgaByte;
            }
            catch (Exception exp)
            {
                pRrgaByte = null;

                bError = false;
                strErrorDesc = exp.ToString();
                //throw;
            }

            return null;
        }

        /* UYVY / YVYU */

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pYuvPackedByte"></param>
        /// <param name="lBuffSize"></param>
        /// <param name="lPicHeight"></param>
        /// <param name="lPicWidth"></param>
        /// <param name="bError"></param>
        /// <param name="strErrorDesc"></param>
        /// <returns></returns>
        public static byte[] GetRgb32_From_Uyvy(byte[] pYuvPackedByte, Int32 lBuffSize, Int32 lPicHeight, Int32 lPicWidth, ref bool bError, ref string strErrorDesc)
        {
            bError = true;
            int picSize = lPicWidth * lPicHeight;
            strErrorDesc = string.Format("無錯誤.picSize4 = '{0}', lBuffSize2 = '{1}'", picSize * 4, lBuffSize * 2);

            byte[] pRrgaByte = new byte[picSize * 4];
            //int A = 0;

            byte[] pYPlaneByte;
            byte[] pUPlaneByte;
            byte[] pVPlaneByte;

            try
            {
                // 使用每行跨距
                pYPlaneByte = new byte[lPicHeight * lPicWidth];
                pUPlaneByte = new byte[(lPicHeight) * (lPicWidth / 2)];
                pVPlaneByte = new byte[(lPicHeight) * (lPicWidth / 2)];

                for (int idxSrc = 0, idxDest = 0; idxSrc < lBuffSize; )
                {
                    pUPlaneByte[idxDest * 2] = pYuvPackedByte[idxSrc + 0];
                    pYPlaneByte[idxDest] = pYuvPackedByte[idxSrc + 1];

                    pVPlaneByte[idxDest * 2 + 1] = pYuvPackedByte[idxSrc + 2];
                    pYPlaneByte[idxDest] = pYuvPackedByte[idxSrc + 3];

                    idxSrc = idxSrc + 4;
                    idxDest++;
                }

                pRrgaByte = GetRgb32_From_Yuv(pYPlaneByte, pUPlaneByte, pVPlaneByte, lPicHeight, lPicWidth, ref bError, ref strErrorDesc);

                pYPlaneByte = null;
                pUPlaneByte = null;
                pVPlaneByte = null;

                return pRrgaByte;
            }
            catch (Exception exp)
            {
                pYPlaneByte = null;
                pUPlaneByte = null;
                pVPlaneByte = null;

                pRrgaByte = null;

                bError = false;
                strErrorDesc = exp.ToString();
                //throw;
            }

            return null;
        }

        /* YV12 / I420 
         * 
         * YV12格式與IYUV類似,每個畫素都提取Y,在UV提取時,將影象2 x 2的矩陣,每個矩陣提取一個U和一個V。
         * 
         * YV12格式和I420格式的不同處在V平面和U平面的位置不同。在YV12格式中,V平面緊跟在Y平面之後,然後才是U平面(即:YVU);但I420則是相反(即:YUV)。
         * 
         * NV12與YV12類似,效果一樣,YV12中U和V是連續排列的,而在NV12中,U和V就交錯排列的。
         */

        /// <summary>
        /// YV12 轉 RGB32
        /// @在YV12格式中,V平面緊跟在Y平面之後,然後才是U平面(即:YVU);但I420則是相反(即:YUV)
        /// </summary>
        /// <param name="pYPlaneByte"></param>
        /// <param name="pVPlaneByte"></param>
        /// <param name="pUPlaneByte"></param>
        /// <param name="lPicHeight"></param>
        /// <param name="lPicWidth"></param>
        /// <returns></returns>
        public static byte[] GetRgb32_From_Yv12(byte[] pYPlaneByte, byte[] pUPlaneByte, byte[] pVPlaneByte, Int32 lPicHeight, Int32 lPicWidth)
        {
            int picSize = lPicWidth * lPicHeight;

            byte[] pRrgaByte = new byte[picSize * 4];
            int A = 0;

            try
            {
                for (int iRow = 0; iRow < lPicHeight; iRow++)
                {
                    for (int jCol = 0; jCol < lPicWidth; jCol++)
                    {
                        //int Y = pYPlane[i * dwWidth + j];
                        //int U = pUPlane[(i / 2) * (dwWidth / 2) + (j / 2)];
                        //int V = pVPlane[(i / 2) * (dwWidth / 2) + (j / 2)];
                        //int R = Y + (U - 128) + (((U - 128) * 103) >> 8);
                        //int G = Y - (((V - 128) * 88) >> 8) - (((U - 128) * 183) >> 8);
                        //int B = Y + (V - 128) + (((V - 128) * 198) >> 8);
                        //R = max(0, min(255, R));
                        //G = max(0, min(255, G));
                        //B = max(0, min(255, B));

                        int Y = pYPlaneByte[iRow * lPicWidth + jCol];
                        int U = pUPlaneByte[(iRow / 2) * (lPicWidth / 2) + (jCol / 2)];
                        int V = pVPlaneByte[(iRow / 2) * (lPicWidth / 2) + (jCol / 2)];

                        /* 存在顏色轉換錯誤問題。現象:公交車編號的LED燈顯示顏色,與實際不符。如K30,圖片上的30顏色為藍色,但實際上30是紅色 */
                        /* 1、宣傳橫幅,紅色變成藍色 */
                        /* 2、公交編號LED,紅色變成藍色 */
                        /* 3、訊號燈LED,紅色變成藍色 */
                        //int R = Y + (U - 128) + (((U - 128) * 103) >> 8);
                        //int G = Y - (((V - 128) * 88) >> 8) - (((U - 128) * 183) >> 8);
                        //int B = Y + (V - 128) + (((V - 128) * 198) >> 8);

                        /* 2012.12.24,糾正顏色錯位問題R與B */
                        int R = Y + (V - 128) + (((V - 128) * 103) >> 8);
                        int G = Y - (((U - 128) * 88) >> 8) - (((V - 128) * 183) >> 8);
                        int B = Y + (U - 128) + (((U - 128) * 198) >> 8);

                        R = Math.Max(0, Math.Min(255, R));
                        G = Math.Max(0, Math.Min(255, G));
                        B = Math.Max(0, Math.Min(255, B));

                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 0] = Convert.ToByte(B);
                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 1] = Convert.ToByte(G);
                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 2] = Convert.ToByte(R);
                        pRrgaByte[4 * (iRow * lPicWidth + jCol) + 3] = Convert.ToByte(A);

                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 0] = Convert.ToByte(R);
                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 1] = Convert.ToByte(G);
                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 2] = Convert.ToByte(B);
                        //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 3] = Convert.ToByte(A);
                    }
                }

                return pRrgaByte;
            }
            catch (Exception exp)
            {
                pRrgaByte = null;
                //throw;
            }

            return null;
        }

        ///// <summary>
        ///// YV12 轉 RGB32(GetRgb32_From_Yv12_20130417,糾正R與B的轉換錯誤)
        ///// </summary>
        ///// <param name="pYPlaneByte"></param>
        ///// <param name="pUPlaneByte"></param>
        ///// <param name="pVPlaneByte"></param>
        ///// <param name="lPicHeight"></param>
        ///// <param name="lPicWidth"></param>
        ///// <returns></returns>
        //public static byte[] GetRgb32_From_Yv12_20130417(byte[] pYPlaneByte, byte[] pUPlaneByte, byte[] pVPlaneByte, Int32 lPicHeight, Int32 lPicWidth)
        //{
        //    try
        //    {
        //        int picSize = lPicWidth * lPicHeight;

        //        byte[] pRrgaByte = new byte[picSize * 4];
        //        int A = 0;

        //        for (int iRow = 0; iRow < lPicHeight; iRow++)
        //        {
        //            for (int jCol = 0; jCol < lPicWidth; jCol++)
        //            {
        //                //int Y = pYPlane[i * dwWidth + j];
        //                //int U = pUPlane[(i / 2) * (dwWidth / 2) + (j / 2)];
        //                //int V = pVPlane[(i / 2) * (dwWidth / 2) + (j / 2)];
        //                //int R = Y + (U - 128) + (((U - 128) * 103) >> 8);
        //                //int G = Y - (((V - 128) * 88) >> 8) - (((U - 128) * 183) >> 8);
        //                //int B = Y + (V - 128) + (((V - 128) * 198) >> 8);
        //                //R = max(0, min(255, R));
        //                //G = max(0, min(255, G));
        //                //B = max(0, min(255, B));

        //                int Y = pYPlaneByte[iRow * lPicWidth + jCol];
        //                int U = pUPlaneByte[(iRow / 2) * (lPicWidth / 2) + (jCol / 2)];
        //                int V = pVPlaneByte[(iRow / 2) * (lPicWidth / 2) + (jCol / 2)];

        //                /* 存在顏色轉換錯誤問題。現象:公交車編號的LED燈顯示顏色,與實際不符。如K30,圖片上的30顏色為藍色,但實際上30是紅色 */
        //                //int R = Y + (U - 128) + (((U - 128) * 103) >> 8);
        //                //int G = Y - (((V - 128) * 88) >> 8) - (((U - 128) * 183) >> 8);
        //                //int B = Y + (V - 128) + (((V - 128) * 198) >> 8);

        //                /* 2012.12.24,糾正顏色錯位問題R與B */
        //                int R = Y + (V - 128) + (((V - 128) * 103) >> 8);
        //                int G = Y - (((U - 128) * 88) >> 8) - (((V - 128) * 183) >> 8);
        //                int B = Y + (U - 128) + (((U - 128) * 198) >> 8);

        //                R = Math.Max(0, Math.Min(255, R));
        //                G = Math.Max(0, Math.Min(255, G));
        //                B = Math.Max(0, Math.Min(255, B));

        //                pRrgaByte[4 * (iRow * lPicWidth + jCol) + 0] = Convert.ToByte(B);
        //                pRrgaByte[4 * (iRow * lPicWidth + jCol) + 1] = Convert.ToByte(G);
        //                pRrgaByte[4 * (iRow * lPicWidth + jCol) + 2] = Convert.ToByte(R);
        //                pRrgaByte[4 * (iRow * lPicWidth + jCol) + 3] = Convert.ToByte(A);

        //                //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 0] = Convert.ToByte(R);
        //                //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 1] = Convert.ToByte(G);
        //                //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 2] = Convert.ToByte(B);
        //                //pRrgaByte[4 * (iRow * lPicWidth + jCol) + 3] = Convert.ToByte(A);
        //            }
        //        }

        //        return pRrgaByte;
        //    }
        //    catch (Exception exp)
        //    {
        //        //throw;
        //    }

        //    return null;
        //}


        static double[,] YUV2RGB_CONVERT_MATRIX = new double[3, 3] { { 1, 0, 1.4022 }, { 1, -0.3456, -0.7145 }, { 1, 1.771, 0 } };

        /// <summary>
        /// YUV420 轉 RGB 參考地址http://www.haogongju.net/art/953565
        /// </summary>
        /// <param name="yuvFrame">yuv資料</param>
        /// <param name="width">圖片寬</param>
        /// <param name="height">圖片高</param>
        /// <returns></returns>
        public static byte[] ConvertYUV420RGB(byte[] yuvFrame, int width, int height)
        {

            int gIndex = width * height;
            int uIndex = width * height;
            int vIndex = uIndex + ((width * height) >> 2);

            byte[] rgbFrame = new byte[gIndex * 3];

            int bIndex = gIndex * 2;

            int temp = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {

                    // R分量       
                    temp = (int)(yuvFrame[y * width + x] + (yuvFrame[vIndex + (y / 2) * (width / 2) + x / 2] - 128) * YUV2RGB_CONVERT_MATRIX[0, 2]);
                    rgbFrame[y * width + x] = (byte)(temp < 0 ? 0 : (temp > 255 ? 255 : temp));

                    // G分量      
                    temp = (int)(yuvFrame[y * width + x] + (yuvFrame[uIndex + (y / 2) * (width / 2) + x / 2] - 128) * YUV2RGB_CONVERT_MATRIX[1, 1] + (yuvFrame[vIndex + (y / 2) * (width / 2) + x / 2] - 128) * YUV2RGB_CONVERT_MATRIX[1, 2]);
                    rgbFrame[gIndex + y * width + x] = (byte)(temp < 0 ? 0 : (temp > 255 ? 255 : temp));

                    // B分量            
                    temp = (int)(yuvFrame[y * width + x] + (yuvFrame[uIndex + (y / 2) * (width / 2) + x / 2] - 128) * YUV2RGB_CONVERT_MATRIX[2, 1]);
                    rgbFrame[bIndex + y * width + x] = (byte)(temp < 0 ? 0 : (temp > 255 ? 255 : temp));
                    //rgbFrame[bIndex + y * width + x] = Math.Max(0, Math.Min(255, temp));

                }
            }
            return rgbFrame;

        }

        public static byte[] ConvertYUV420RGB(byte[] pYPlaneByte, byte[] pUPlaneByte, byte[] pVPlaneByte, Int32 lPicHeight, Int32 lPicWidth)
        {

            return null;
        }

        #endregion

        #endregion

相關推薦

YUVRGB彙總

#region ******************彩色影象記錄的格式,YUV 轉 RGB****************** /* YUV, http://zh.wikipedia.org/wiki/YUV#.E5.B8.B8.E7.94.A8.E7.9

常用YUVRGB程式碼

常用YUV轉RGB java程式碼 public class YuvToRGB { private static int R = 0; private static int G = 1; private static int B = 2; //I420是yuv42

常用YUVRGB 程式碼

public class YuvToRGB { private static int R = 0; private static int G = 1; private static int B = 2; //I420是yuv420格式,是3個plane,排列方式為(

yuvRGB

先區分一下YUV和YCbCrYUV色彩模型來源於RGB模型,該模型的特點是將亮度和色度分離開,從而適合於影象處理領域。應用:模擬領域Y'= 0.299*R' + 0.587*G' + 0.114*B'U'= -0.147*R' - 0.289*G' + 0.436*B' =

python實現yuvRGB圖片程式

import os import cv2 import numpy as np from PIL import Image #from scipy import misc import utilty as util search_path = 'E:/sti

最簡單的基於FFmpeg的libswscale的示例(YUVRGB

=====================================================最簡單的基於FFmpeg的libswscale的示例系列文章列表:====================================================

YUVRGB各種公式 (YUVRGB的轉換公式有很多種,請注意區別!!!)

一、 公式:基於BT.601-6       BT601 UV 的座標圖(量化後): (橫座標為u,縱座標為v,左下角為原點)           通過座標圖我們可以看到UV並不會包含整個座標系,而是呈一個旋轉了一

opencv+QT實現影象操作(影象的與、或、異或、取反、兩影象相減、RGBYUVYUVRG等等)

需求簡介: 由於最近在做影象處理的專案,有時候需要快速的知道影象的最大畫素值和最小畫素值是多少,或者影象的最大最小畫素的座標在哪裡。需要快速的得到RGB影象中的R、G、B當中的某個通道。需要把RGB影象轉成YUV資料儲存。需要把YUV資料轉成RGB圖片儲存。當每次需要用到這

FFmpeg 將YUV數據RGB

分配內存 () alloc idt img yuv420 init() 復制 ext void init() //分配兩個Frame,兩段buff,一個轉換上下文 {  //為每幀圖像分配內存 m_pFrameYUV = av_frame_alloc();

FFmpeg 將YUV資料RGB

只要開始初始化一次,結束後釋放就好,中間可以迴圈轉碼  AVFrame *m_pFrameRGB,*m_pFrameYUV; uint8_t *m_rgbBuffer,*m_yuvBuffer; struct SwsContext *m_img_convert_ctx; void i

不同格式的YUVRGB

YUV色彩空間:        Y是亮度值,也就是說8位的灰度值即可組成一幅黑白影象,黑白電視機就是這樣的.        UV是色彩值,是給Y上色用的.U是Cb也就是RGB中的藍色分量,V是Cr也就是RGB中的紅色分量.        YUV444 指的是每四個畫素取樣中每個亮度Y分量都有一個色彩UV分

NV12格式RGB的CUDA實現

mic sof spa dex channel cnblogs lock microsoft eight NV12格式是yuv420格式的一種,NV12格式的u,v排布順序為交錯排布,假如一幅圖像尺寸為W*H,則先Y分量有W*H個,然後U分量和V分量交錯排布,U分量和V分

C語言--HSVRGB

void HSVtoRGB(uint8_t *r, uint8_t *g, uint8_t *b, uint16_t h, uint16_t s, uint16_t v) { // R,G,B from 0-255, H from 0-360, S,V from 0-100 int

SDL2---編譯SDL庫、測試播放簡單畫素資料(YUVRGB等)

本篇博文整理自雷神(雷霄驊https://blog.csdn.net/leixiaohua1020/article/list/3)多篇博文,多謝分享,在此致敬! SDL簡介: SDL庫的作用說白了就是封裝了複雜的視音訊底層操作,簡化了視音訊處理的難度。 以下轉自WiKi:

【穩定方案】集創北方ICN6211:MIPIRGB功能晶片方案

4.2、ICN6211 4.2.1 功能: ICN6211是一顆[email protected]轉RGB的橋晶片,其應用圖如下: 4.2.2產品特徵: 輸入:MIPI DSI 支援MIPI ® D-PHY Version 1.00.00 和 MIPI ® DSI Versio

YUVRGB調節色彩公式

1.YUV調節色彩公式(必須是量化後的YUV(16-235)),非量化後的YUV轉換有問題。 轉換公式為: 原始YUV(Y,U,V),轉換後YUV(Y',U',V'),亮度 :g_Bright (0-1),飽和度:g_Saturation(0-1),對比度:g_Contrast (0-1

彙總Tensorflow1.0執行之前版本程式碼報錯問題

注:在Tensorflow1.0執行之前版本,以及py2與py3檔案編碼遇到很多問題。 這裡轉發了網上的彙總報錯解決方法。 1.TypeError: Expected int32, got list containing Tensors of type ‘_Message’ instead.

YUVRGB 顏色格式

最近在學習視訊的顏色空間轉換,由於攝像機拍出來的視訊很多都是用YUV格式儲存的,而顏色空間的轉換必須在RGB顏色模型上才能完成,所以第一步自然就是將YUV顏色模型轉成RGB顏色模型。在網上查到了許多的YUV與RGB互轉的公式,但是總覺得有些雜亂,沒有系統的總結。 首先說一說YUV顏色模型,單單就YUV顏色模

php實現頁面跳方法彙總

一共有三種方法實現頁面跳轉,分別利用php提供的header()、html meta標籤、JavaScript指令碼。 header() header()方法通過設定http響應頭中的location域實現跳轉。這種跳轉實現對使用者是不可見的,有瀏覽器直接執行

android全平臺編譯libyuv庫實現YUVRGB的轉換

音視訊實踐學習 android全平臺編譯ffmpeg以及x264與fdk-aac實踐 ubuntu下使用nginx和nginx-rtmp-module配置直播推流伺服器 android全平臺編譯ffmpeg合併為單個庫實踐 android-studio使用c