网站开发语言啥意思,我是一条龙笔趣阁,一个网站包括,网站建设四个阶段的流程在Rv1126上直接对Nv12图像进行绘制时#xff0c;颜色是灰色。故将Nv12转BGR后绘制图像#xff0c;绘制完成后转成Nv12#xff0c;BGR的图像颜色是正常的#xff0c;但是NV12的图像颜色未画全#xff0c;如图#xff1a;
1.排查发现是RGB转NV12的函数出现问题#xff0c… 在Rv1126上直接对Nv12图像进行绘制时颜色是灰色。故将Nv12转BGR后绘制图像绘制完成后转成Nv12BGR的图像颜色是正常的但是NV12的图像颜色未画全如图
1.排查发现是RGB转NV12的函数出现问题故百度找到一个可用的网址RGB转换为NV12的代码_rgb转nv12-CSDN博客 //https://software.intel.com/en-us/node/503873
//YCbCr Color Model:
// The YCbCr color space is used for component digital video and was developed as part of the ITU-R BT.601 Recommendation. YCbCr is a scaled and offset version of the YUV color space.
// The Intel IPP functions use the following basic equations [Jack01] to convert between RGB in the range 0-255 and YCbCr (this notation means that all components are derived from gamma-corrected RGB):
// Y 0.257*R 0.504*G 0.098*B 16
// Cb -0.148*R - 0.291*G 0.439*B 128
// Cr 0.439*R - 0.368*G - 0.071*B 128//Y 0.257*R 0.504*G 0.098*B 16
static float Rgb2Y(float r0, float g0, float b0)
{float y0 0.257f*r0 0.504f*g0 0.098f*b0 16.0f;return y0;
}//U equals Cb
//Cb -0.148*R - 0.291*G 0.439*B 128
static float Rgb2U(float r0, float g0, float b0)
{float u0 -0.148f*r0 - 0.291f*g0 0.439f*b0 128.0f;return u0;
}//V equals Cr
//Cr 0.439*R - 0.368*G - 0.071*B 128
static float Rgb2V(float r0, float g0, float b0)
{float v0 0.439f*r0 - 0.368f*g0 - 0.071f*b0 128.0f;return v0;
}//Convert two rows from RGB to two Y rows, and one row of interleaved U,V.
//I0 and I1 points two sequential source rows.
//I0 - rgbrgbrgbrgbrgbrgb...
//I1 - rgbrgbrgbrgbrgbrgb...
//Y0 and Y1 points two sequential destination rows of Y plane.
//Y0 - yyyyyy
//Y1 - yyyyyy
//UV0 points destination rows of interleaved UV plane.
//UV0 - uvuvuv
static void Rgb2NV12TwoRows(const unsigned char I0[],const unsigned char I1[],int step,const int image_width,unsigned char Y0[],unsigned char Y1[],unsigned char UV0[])
{int x; //Column index//Process 4 source pixels per iteration (2 pixels of row I0 and 2 pixels of row I1).for (x 0; x image_width; x 2){//Load R,G,B elements from first row (and convert to float).float r00 (float)I0[x*step 0];float g00 (float)I0[x*step 1];float b00 (float)I0[x*step 2];//Load next R,G,B elements from first row (and convert to float).float r01 (float)I0[x*step step0];float g01 (float)I0[x*step step1];float b01 (float)I0[x*step step2];//Load R,G,B elements from second row (and convert to float).float r10 (float)I1[x*step 0];float g10 (float)I1[x*step 1];float b10 (float)I1[x*step 2];//Load next R,G,B elements from second row (and convert to float).float r11 (float)I1[x*step step0];float g11 (float)I1[x*step step1];float b11 (float)I1[x*step step2];//Calculate 4 Y elements.float y00 Rgb2Y(r00, g00, b00);float y01 Rgb2Y(r01, g01, b01);float y10 Rgb2Y(r10, g10, b10);float y11 Rgb2Y(r11, g11, b11);//Calculate 4 U elements.float u00 Rgb2U(r00, g00, b00);float u01 Rgb2U(r01, g01, b01);float u10 Rgb2U(r10, g10, b10);float u11 Rgb2U(r11, g11, b11);//Calculate 4 V elements.float v00 Rgb2V(r00, g00, b00);float v01 Rgb2V(r01, g01, b01);float v10 Rgb2V(r10, g10, b10);float v11 Rgb2V(r11, g11, b11);//Calculate destination U element: average of 2x2 original U elements.float u0 (u00 u01 u10 u11)*0.25f;//Calculate destination V element: average of 2x2 original V elements.float v0 (v00 v01 v10 v11)*0.25f;//Store 4 Y elements (two in first row and two in second row).Y0[x 0] (unsigned char)(y00 0.5f);Y0[x 1] (unsigned char)(y01 0.5f);Y1[x 0] (unsigned char)(y10 0.5f);Y1[x 1] (unsigned char)(y11 0.5f);//Store destination U element.UV0[x 0] (unsigned char)(u0 0.5f);//Store destination V element (next to stored U element).UV0[x 1] (unsigned char)(v0 0.5f);}
}//Convert image I from pixel ordered RGB to NV12 format.
//I - Input image in pixel ordered RGB format
//image_width - Number of columns of I
//image_height - Number of rows of I
//J - Destination image in NV12 format.//I is pixel ordered RGB color format (size in bytes is image_width*image_height*3):
//RGBRGBRGBRGBRGBRGB
//RGBRGBRGBRGBRGBRGB
//RGBRGBRGBRGBRGBRGB
//RGBRGBRGBRGBRGBRGB
//
//J is in NV12 format (size in bytes is image_width*image_height*3/2):
//YYYYYY
//YYYYYY
//UVUVUV
//Each element of destination U is average of 2x2 original U elements
//Each element of destination V is average of 2x2 original V elements
//
//Limitations:
//1. image_width must be a multiple of 2.
//2. image_height must be a multiple of 2.
//3. I and J must be two separate arrays (in place computation is not supported).
void Rgb2NV12(const unsigned char I[], int step,const int image_width, const int image_height,unsigned char J[])
{//In NV12 format, UV plane starts below Y plane.unsigned char *UV J[image_width*image_height];//I0 and I1 points two sequential source rows.const unsigned char *I0; //I0 - rgbrgbrgbrgbrgbrgb...const unsigned char *I1; //I1 - rgbrgbrgbrgbrgbrgb...//Y0 and Y1 points two sequential destination rows of Y plane.unsigned char *Y0; //Y0 - yyyyyyunsigned char *Y1; //Y1 - yyyyyy//UV0 points destination rows of interleaved UV plane.unsigned char *UV0; //UV0 - uvuvuvint y; //Row index//In each iteration: process two rows of Y plane, and one row of interleaved UV plane.for (y 0; y image_height; y 2){I0 I[y*image_width*step]; //Input row width is image_width*3 bytes (each pixel is R,G,B).I1 I[(y1)*image_width*step];Y0 J[y*image_width]; //Output Y row width is image_width bytes (one Y element per pixel).Y1 J[(y1)*image_width];UV0 UV[(y/2)*image_width]; //Output UV row - width is same as Y row width.//Process two source rows into: Two Y destination row, and one destination interleaved U,V row.Rgb2NV12TwoRows(I0,I1,step,image_width,Y0,Y1,UV0);}
}
调用
cv::Mat m_stJpg_640x384 cv::imread(D:\\ImageToNv12\\111.jpg);if (!m_stJpg_640x384.empty()) {cv::cvtColor(m_stJpg_640x384, m_stJpg_640x384, COLOR_BGR2RGB);unsigned char* pData new unsigned char[1920 * 1080 * 3];Rgb2NV12(m_stJpg_640x384.data, 3/*RGB为3RGBA为4*/, m_stJpg_640x384.cols, m_stJpg_640x384.rows, pData);WriteFile(m.yuv, wb, pData, m_stJpg_640x384.cols * m_stJpg_640x384.rows * 3 / 2);delete[] pData;}
文章转载自: http://www.morning.hmdyl.cn.gov.cn.hmdyl.cn http://www.morning.brbmf.cn.gov.cn.brbmf.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.fwcnx.cn.gov.cn.fwcnx.cn http://www.morning.fnczn.cn.gov.cn.fnczn.cn http://www.morning.yymlk.cn.gov.cn.yymlk.cn http://www.morning.rmfw.cn.gov.cn.rmfw.cn http://www.morning.fyxr.cn.gov.cn.fyxr.cn http://www.morning.jlmrx.cn.gov.cn.jlmrx.cn http://www.morning.zkqsc.cn.gov.cn.zkqsc.cn http://www.morning.hfxks.cn.gov.cn.hfxks.cn http://www.morning.rjrh.cn.gov.cn.rjrh.cn http://www.morning.kyfnh.cn.gov.cn.kyfnh.cn http://www.morning.xcbnc.cn.gov.cn.xcbnc.cn http://www.morning.rxdsq.cn.gov.cn.rxdsq.cn http://www.morning.jcwhk.cn.gov.cn.jcwhk.cn http://www.morning.qgqck.cn.gov.cn.qgqck.cn http://www.morning.jlthz.cn.gov.cn.jlthz.cn http://www.morning.thntp.cn.gov.cn.thntp.cn http://www.morning.mrskk.cn.gov.cn.mrskk.cn http://www.morning.fgxws.cn.gov.cn.fgxws.cn http://www.morning.zmyhn.cn.gov.cn.zmyhn.cn http://www.morning.wcqkp.cn.gov.cn.wcqkp.cn http://www.morning.bppml.cn.gov.cn.bppml.cn http://www.morning.csdgt.cn.gov.cn.csdgt.cn http://www.morning.sryyt.cn.gov.cn.sryyt.cn http://www.morning.hzqjgas.com.gov.cn.hzqjgas.com http://www.morning.mrqwy.cn.gov.cn.mrqwy.cn http://www.morning.wkmpx.cn.gov.cn.wkmpx.cn http://www.morning.mhlsx.cn.gov.cn.mhlsx.cn http://www.morning.kxltf.cn.gov.cn.kxltf.cn http://www.morning.kdfqx.cn.gov.cn.kdfqx.cn http://www.morning.xhrws.cn.gov.cn.xhrws.cn http://www.morning.lstmq.cn.gov.cn.lstmq.cn http://www.morning.zhishizf.cn.gov.cn.zhishizf.cn http://www.morning.cfccp.cn.gov.cn.cfccp.cn http://www.morning.mdnnz.cn.gov.cn.mdnnz.cn http://www.morning.glxdk.cn.gov.cn.glxdk.cn http://www.morning.wftrs.cn.gov.cn.wftrs.cn http://www.morning.pnljy.cn.gov.cn.pnljy.cn http://www.morning.mcndn.cn.gov.cn.mcndn.cn http://www.morning.xxsrm.cn.gov.cn.xxsrm.cn http://www.morning.wlggr.cn.gov.cn.wlggr.cn http://www.morning.supera.com.cn.gov.cn.supera.com.cn http://www.morning.mwwnz.cn.gov.cn.mwwnz.cn http://www.morning.hsflq.cn.gov.cn.hsflq.cn http://www.morning.hrrmb.cn.gov.cn.hrrmb.cn http://www.morning.fppzc.cn.gov.cn.fppzc.cn http://www.morning.tqpds.cn.gov.cn.tqpds.cn http://www.morning.jsphr.cn.gov.cn.jsphr.cn http://www.morning.kghhl.cn.gov.cn.kghhl.cn http://www.morning.nxnrt.cn.gov.cn.nxnrt.cn http://www.morning.dfbeer.com.gov.cn.dfbeer.com http://www.morning.sbczr.cn.gov.cn.sbczr.cn http://www.morning.bqmdl.cn.gov.cn.bqmdl.cn http://www.morning.rwzc.cn.gov.cn.rwzc.cn http://www.morning.ydwnc.cn.gov.cn.ydwnc.cn http://www.morning.tblbr.cn.gov.cn.tblbr.cn http://www.morning.xphls.cn.gov.cn.xphls.cn http://www.morning.gcxfh.cn.gov.cn.gcxfh.cn http://www.morning.jxpwr.cn.gov.cn.jxpwr.cn http://www.morning.gqbtw.cn.gov.cn.gqbtw.cn http://www.morning.xknsn.cn.gov.cn.xknsn.cn http://www.morning.rhnn.cn.gov.cn.rhnn.cn http://www.morning.wrbx.cn.gov.cn.wrbx.cn http://www.morning.pndhh.cn.gov.cn.pndhh.cn http://www.morning.ryqsq.cn.gov.cn.ryqsq.cn http://www.morning.cjnfb.cn.gov.cn.cjnfb.cn http://www.morning.stxg.cn.gov.cn.stxg.cn http://www.morning.tgmfg.cn.gov.cn.tgmfg.cn http://www.morning.zqfz.cn.gov.cn.zqfz.cn http://www.morning.kxwsn.cn.gov.cn.kxwsn.cn http://www.morning.hgfxg.cn.gov.cn.hgfxg.cn http://www.morning.rfpb.cn.gov.cn.rfpb.cn http://www.morning.dddcfr.cn.gov.cn.dddcfr.cn http://www.morning.pnjsl.cn.gov.cn.pnjsl.cn http://www.morning.htbgz.cn.gov.cn.htbgz.cn http://www.morning.hhmfp.cn.gov.cn.hhmfp.cn http://www.morning.yrbq.cn.gov.cn.yrbq.cn http://www.morning.nflpk.cn.gov.cn.nflpk.cn