首页 > 编程知识 正文

venn图是什么意思,jet和plane图片的区别

时间:2023-05-06 15:36:45 阅读:143856 作者:3952

stride可以翻译成跨度

stride是内存中每行像素所占的区域。 为了实现内存对齐,每行像素在内存中所占的空间不是图像的宽度,如下图所示。

plane一般以luma plane、chroma plane的形式出现,但实际上是luma层和chroma层,像RGB一样,需要用3个plane来储存。

我最近在做HI5321的项目。 其中遇到了重要的技术问题。 我们的图像处理程序需要rgb888格式的图像文件,而我从hi3521获取的视频流是yuv420sp格式的图像帧。 发生了问题。 现在需要将yuv420sp格式的1帧图像转换为rgb888格式的图像。 其实我的目的是rgb888形式的图像。把yuv420sp的yuv成分保存在存储器里的方式,是y成分单独保存,uv成分进行交叉存储。 是的,我可以。 但是,打印yuv420sp的帧信息时,这个720*576的1帧图像的stride (也就是跨度)竟然是768。 即使现在成功地将yuv420sp的1帧图像转换成bmp位图,也不知道这大量出现的768-720=48字节是什么。 在没有考虑跨度的情况下,直接从yuv分量的地址中取出分量,取得rgb数据并保存为bmp位图,但bmp完全混乱,有什么问题。 一定是跨度,跨度:一定是帧宽度以上且4的倍数。 720和768之间4的倍数变多了。 为什么是768? 好吧! 如果小于4的倍数,则必须在行末补0,所以我认为这48个字节在每行的末尾。 读取yuv成分时,请务必错开地址。 请试试看。 bmp真的保存成功了。 就像拍摄的照片一样。 当然,其中技术细节众所周知。 我知道三个以上把yuv换算成rgb的公式。

因为写这个记录的目的是想说这个stride的问题,所以在进行yuv420p、yuv420sp等的视频帧变换的时候必须注意跨度stride这个参数。

whenavideoimageisstoredinmemory,thememorybuffermightcontainextrapaddingbytesaftereachrowofpixels.thepaddingbytesaffecthowttthowtttttextextrapred

thestrideisthenumberofbytesfromonerowofpixelsinmemory.strideisalsocalledpitch.ifpaddingbytesa rofpixelsinmemory thestrideiswiderthanthewidthoftheimage,asshowninthefollowingillustration。

twobuffersthatcontainvideoframeswithequaldimensionscanhavetwodifferentstrides.ifyouprocessavideoimage,youmusttakethestride

In addition,therearetwowaysthatanimagecanbearrangedinmemory.in atop-down image,thetoprowofpixelsintheimageappearsfirstinmage thelastrowofpixelsappearsfirstinmemory.thefollowingillustrationshowsthedifferencebetweenatop-downimageandabottom-upimage

a bottom-upimagehasanegativestride、becausestrideisdefinedasthenumberofbytesneedtomovedownarowofpixels、 relativetothedisplayedimage.yuvimagesshouldalwaysbetop-down,andanyimagethatiscontainedinadirect3dsurfacemustbetop-down

videotransformsinparticularneedtohandlebufferswithmismatched

strides, because the input buffer might not match the output buffer. For example, suppose that you want to convert a source image and write the result to a destination image. Assume that both images have the same width and height, but might not have the same pixel format or the same image stride.

The following example code shows a generalized approach for writing this kind of function. This is not a complete working example, because it abstracts many of the specific details.

 

下面是一个转换的例子,可以通过它很好的理解

最近拿到了一块液晶显示屏,采用NTSC隔行扫描制式输出图像,其采用的颜色格式为YUV4:2:2的UYVY格式,可是某视频解码器输出的颜色格式是YUV4:2:0的I420格式。那么,就必须在两者之间进行一次转换,其中I420是以平面(planner)格式存放的,而UYVY则是以紧缩(packet)格式存放的。这个转换过程并不复杂,原理如图 1所示。

图2中的每一个颜色分量都采用一个字节表示,U0Y0V0Y1这样一个存放序列表示的实际上是两个像素点,总共需要4个字节表示。因此,每一个像素点平均占据的空间是2字节。YUV这种颜色格式的理论依据是HVS(Human Visual System,人类视觉系统)对亮度敏感,而对色度的敏感程度次之。因此通过对每一行像素点的色差分量亚采样来减少所需的存储空间。YUV4:2:2紧缩格式的颜色占据的存储空间是YUV4:4:4格式占据的存储空间的2/3。比如,如果采用YUV4:4:4格式,则每个像素点都需要用三个分量表示,也即需要用3字节表示一个像素点。

代码实现

void rv_csp_i420_uyvy( uint8_t *y_plane, // Y plane of I420 uint8_t *u_plane, // U plane of I420 uint8_t *v_plane, // V plane of I420 int y_stride, // Y stride of I420, in pixel int uv_stride, // U and V stride of I420, in pixel uint8_t *image, // output UYVY image int width, // image width int height) // image height{ int row; int col; uint8_t *pImg = image; for (row = 0; row < height; row = row+1)
{ for (col = 0; col < width; col = col+2)
{ pImg[0] = u_plane[row/2 * uv_stride + col/2]; pImg[1] = y_plane[row * y_stride + col]; pImg[2] = v_plane[row/2 * uv_stride + col/2]; pImg[3] = y_plane[row * y_stride + col + 1]; pImg += 4; } }}

代码好像有点问题,保存的时候没有考虑YUV4:2:2的stride,不过上面的代码已经把原理说的很清除了。

 

转载于:https://www.cnblogs.com/welhzh/p/4939613.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。