Cut Frame From Decoding Stream To Show As a RGB Form Picture
来源:互联网 发布:python进程和线程 编辑:程序博客网 时间:2024/06/05 08:21
YUV to RGB formula:
/* R = Y + 1.14V,G = Y - 0.39U - 0.58V,B = Y + 2.03U YUV对应YCbCr
r = y + 1.14*cr;
g = y - 0.39*cb - 0.58*cr;
b = y + 2.03*cb; */
/* YCbCr与RGB的关系 */
r = 1.164*(y-16) + 1.596*(cr-128);
g = 1.164*(y-16) - 0.813*(cr-128) - 0.392*(cb-128);
b = 1.164*(y-16) + 2.017*(cb-128);
/* r=1.0*y+1.402*(cr-128) ;
g=1.0*y-0.34413*(cb-128)-0.71414*(cr-128);
b=1.0*y+1.772*(cb-128);*/
http://www.cnblogs.com/h2-database/archive/2011/09/29/2572580.html
http://m.blog.csdn.net/blog/zhengtu009/17221247
Sometimes All White or Black
imshow(uint8(A));
If the format is double, the value will be 0 or 1.
Or U can: imshow(I,[])
http://blog.csdn.net/sdlyjzh/article/details/8246752
http://zhidao.baidu.com/link?url=2CHdAHNvp_93IjpnZI_nA4-W5aPdp3ojPXSo5rCv5glYdXGLLPjBJLs7rSlqy5SqMuQ8LVRNPevtknUkueyYKK
http://www.360doc.com/content/13/1105/10/12085465_326756155.shtml
Whole Function
% Function: Draw arrow array for motion vector field.% Input: % fn: YUV data filename% Output:% pic:RGB picture.%author:Chen Yu%school:Carnegie Mellon Universityfunction CutFrame fid=fopen('————input interface YUV data————.txt','r'); if(fid == -1) disp(['Open File ',fp,' Fail']); else ArrayData = fscanf(fid, '%d'); if(ArrayData(3) == 1) ChromWidth = ArrayData(1)/2; ChromHeight = ArrayData(2)/2; elseif(ArrayData(3) == 2) ChromWidth = ArrayData(1)/2; ChromHeight = ArrayData(2); elseif(ArrayData(3) == 3) ChromWidth = ArrayData(1); ChromHeight = ArrayData(2); end YPart = cat(1); UVPart = cat(2); for i = 1:ArrayData(2) for j = 1:ArrayData(1) index = (i - 1)*ArrayData(1) + j + 3; YPart(i,j,1) = ArrayData(index); end end imshow(uint8(YPart)); for i = 1:2 for j = 1:ChromHeight for k = 1:ChromWidth index = ArrayData(2)*ArrayData(1) + 3 + (j - 1)*ChromWidth + k + ChromHeight*ChromWidth*(i - 1); UVPart(j, k, i) = ArrayData(index); end end end % imshow(uint8(UVPart(:, :, 1))); RGB = cat(3); for i = 1:ArrayData(2) for j = 1:ArrayData(1) tempi = ceil(i/2); tempj = ceil(j/2); RGB(i, j, 1) = 1.164*(YPart(i,j, 1)-16) + 1.596*(UVPart(tempi, tempj, 2)-128); RGB(i, j, 2) = 1.164*(YPart(i,j, 1)-16) - 0.813*(UVPart(tempi, tempj, 1)-128) - 0.392*(UVPart(tempi, tempj, 2)-128); RGB(i, j, 3) = 1.164*(YPart(i,j, 1)-16) + 2.017*(UVPart(tempi, tempj, 1)-128); %RGB(i, j, 1) = YPart(i,j) + 1.4075*(UVPart(tempi, tempj, 1)-128); %RGB(i, j, 2) = YPart(i,j) - 0.3455*(UVPart(tempi, tempj, 2)-128) - 0.7169*(UVPart(tempi, tempj, 1)-128); %RGB(i, j, 3) = YPart(i,j) + 1.779*(UVPart(tempi, tempj, 2)-128); if(RGB(i, j, 1) > 255) RGB(i, j, 1) = 255; elseif(RGB(i, j, 1) < 0) RGB(i, j, 1) = 0; end if(RGB(i, j, 2) > 255) RGB(i, j, 2) = 255; elseif(RGB(i, j, 2) < 0) RGB(i, j, 2) = 0; end if(RGB(i, j, 3) > 255) RGB(i, j, 3) = 255; elseif(RGB(i, j, 3) < 0) RGB(i, j, 3) = 0; end end end imwrite(uint8(RGB(1:ArrayData(2),1:ArrayData(1),:)),'E:/ErrorConcealment/Bat/myPic.bmp');%写图片 %imshow(uint8(RGB(1:ArrayData(2),1:ArrayData(1),:))); %imview(RGB(1:ArrayData(2),1:ArrayData(1),:)); end if(fid ~= -1) fclose(fid); end end
Version Two:
% Function: Draw arrow array for motion vector field.% Input: % fn: YUV data filename% Output:% pic:RGB picture.%author:Chen Yu%school:Carnegie Mellon Universityfunction CutFrame fid=fopen('D:/CY/JM18.6_RC/jm18.6/build/vs version1.0/YuvDataOfAFrame.txt','r'); if(fid == -1) disp(['Open File ',fp,' Fail']); else ArrayData = fscanf(fid, '%d'); if(ArrayData(3) == 1) ChromWidth = ArrayData(1)/2; ChromHeight = ArrayData(2)/2; elseif(ArrayData(3) == 2) ChromWidth = ArrayData(1)/2; ChromHeight = ArrayData(2); elseif(ArrayData(3) == 3) ChromWidth = ArrayData(1); ChromHeight = ArrayData(2); end YPart = cat(1); UVPart = cat(2); for i = 1:ArrayData(2) for j = 1:ArrayData(1) index = (i - 1)*ArrayData(1) + j + 3; YPart(i,j,1) = ArrayData(index); end end figure; imshow(uint8(YPart)); for i = 1:2 for j = 1:ChromHeight for k = 1:ChromWidth index = ArrayData(2)*ArrayData(1) + 3 + (j - 1)*ChromWidth + k + ChromHeight*ChromWidth*(i - 1); UVPart(j, k, i) = ArrayData(index); end end end figure; imshow(uint8(UVPart(:, :, 1))); figure; imshow(uint8(UVPart(:, :, 2))); RGB = cat(3); for i = 1:ArrayData(2) for j = 1:ArrayData(1) tempi = ceil(i/2); tempj = ceil(j/2); RGB(i, j, 1) = 1.164*(YPart(i,j, 1)-16) + 1.596*(UVPart(tempi, tempj, 2)-128); RGB(i, j, 2) = 1.164*(YPart(i,j, 1)-16) - 0.813*(UVPart(tempi, tempj, 1)-128) - 0.392*(UVPart(tempi, tempj, 2)-128); RGB(i, j, 3) = 1.164*(YPart(i,j, 1)-16) + 2.017*(UVPart(tempi, tempj, 1)-128); %RGB(i, j, 1) = YPart(i,j) + 1.4075*(UVPart(tempi, tempj, 1)-128); %RGB(i, j, 2) = YPart(i,j) - 0.3455*(UVPart(tempi, tempj, 2)-128) - 0.7169*(UVPart(tempi, tempj, 1)-128); %RGB(i, j, 3) = YPart(i,j) + 1.779*(UVPart(tempi, tempj, 2)-128); if(RGB(i, j, 1) > 255) RGB(i, j, 1) = 255; elseif(RGB(i, j, 1) < 0) RGB(i, j, 1) = 0; end if(RGB(i, j, 2) > 255) RGB(i, j, 2) = 255; elseif(RGB(i, j, 2) < 0) RGB(i, j, 2) = 0; end if(RGB(i, j, 3) > 255) RGB(i, j, 3) = 255; elseif(RGB(i, j, 3) < 0) RGB(i, j, 3) = 0; end end end imwrite(uint8(RGB(1:ArrayData(2),1:ArrayData(1),:)),'E:/ErrorConcealment/Bat/directiveAverage.bmp');%写图片 figure; imshow(uint8(RGB(1:ArrayData(2),1:ArrayData(1),:))); end if(fid ~= -1) fclose(fid); end end
YUV component as below:
RGB picture:
http://www.cnblogs.com/h2-database/archive/2011/09/29/2572580.html
http://blog.csdn.net/velanjun/article/details/20643545
http://zhidao.baidu.com/link?url=SErTJmLny82Fj94o3vG44-VHrLYC1qV_K_3v_2fqwMgs6TD7GcC4knTdM3EyTAvIF12323gh1TkkFIITe4HQX201o6TF_Iw79WoYIbNHCmG
http://m.blog.csdn.net/blog/zhengtu009/17221247
http://blog.csdn.net/jerrytong/article/details/5658818
http://www.cnblogs.com/hoys/archive/2012/08/01/2619144.html
http://www.xuebuyuan.com/867587.html
http://www.cnblogs.com/liwenbin/archive/2012/10/18/2728759.html
- Cut Frame From Decoding Stream To Show As a RGB Form Picture
- How to save a picture (take screenshot) from a camera
- Via OpenCore decoding H.264 ES stream(RTP) from net
- A Fast Method to Stream Data from Big Data Sources
- How to read a frame from YUV file in OpenCV?
- A picture from notepad++ site.
- Use FFMPEG and SDL to show a frame of YUV (4:2:0)
- How to Get the Frequency Table of a Categorical Variable as a Data Frame in R
- Grab a picture from a FLV file
- Add a logo from a SharePoint library to an InfoPath browser form
- CheckStyle unable to read from stream
- Loading HTML content from a Stream
- Insert a png picture to QTableWidgetItem
- How to remove background of a picture?
- picture show-ui
- OpenCV show picture
- Send event to Host (Windows Form) from a WPF Control -Part 1
- Send Custom Event to Host (Windows Form) from a WPF Control -Part 2
- Android Studio工程中添加移动广告平台广告条代码教程
- Android 自定义Dialog无法Dismiss
- ffmpeg调试需要使用的一些比较有用的命令
- flex设置DataGrid文本按内容自动换行
- javascript 正则表达式过滤sql关键字
- Cut Frame From Decoding Stream To Show As a RGB Form Picture
- strncpy函数的危险性
- 如何判断一段程序是由C编译程序还是C++编译程序编译的?
- RoboBinding探究二:ImageView及自定义控件实现
- 使用java.util.Properties类读写配置文件
- 记录一个问题 lua_tinker中load_file 的lua文件包含require报错解决办法
- Android 内存管理系列之二:内存溢出
- C++11function函数用法
- linux下安装boost