關於 YUV to RGB 然後 display 的小問題 |
答題得分者是:istillloving
|
itisbeautiful_2
一般會員 發表:2 回覆:3 積分:1 註冊:2009-12-18 發送簡訊給我 |
各位大大們好
我現在想做的動作如下 讀入一個 YUV420 的檔案 然後利用 Addition 裡面的 Image 做播放 讀檔的部份已經寫沒好問題了 但是我在把它 display 出來的時候感覺顏色似乎整個都偏掉了 YUV to RGB 的公式也使用了好幾種 但 ~ 似乎都是如此 我的程式碼如下 可以麻煩各位高手幫我解惑 void __fastcall TForm1::Button1Click(TObject *Sender) { Button1->Enabled=false; unsigned char *input_y; unsigned char *input_u; unsigned char *input_v; unsigned char *depth_y; unsigned char *depth_u; unsigned char *depth_v; unsigned char *output_y; unsigned char *output_u; unsigned char *output_v; unsigned char *output; float *R; float *G; float *B; input_y = new unsigned char [720*576]; input_u = new unsigned char [720*576/4]; input_v = new unsigned char [720*576/4]; depth_y = new unsigned char [720*576]; depth_u = new unsigned char [720*576/4]; depth_v = new unsigned char [720*576/4]; output_y = new unsigned char [720*576]; output_u = new unsigned char [720*576/4]; output_v = new unsigned char [720*576/4]; R = new float [720*576]; G = new float [720*576]; B = new float [720*576]; output = new unsigned char [720*576*3]; int i,j; Byte *pt; FILE *fin, *fout, *depth_in; fin = fopen("Inter.yuv","rb"); depth_in = fopen("InterD.yuv","rb"); fout = fopen("Inter_L.yuv","wb"); for(i=0;i<20;i ) { fread(input_y,1,720*576,fin); fread(input_u,1,720*576/4,fin); fread(input_v,1,720*576/4,fin); fread(depth_y,1,720*576,depth_in); fread(depth_u,1,720*576/4,depth_in); fread(depth_v,1,720*576/4,depth_in); for(j=0;j<720*576;j ) { output_y[j] = input_y[j]; } for(j=0;j<720*576/4;j ) { output_u[j] = input_u[j]; output_v[j] = input_v[j]; } fwrite(output_y,1,720*576,fout); fwrite(output_u,1,720*576/4,fout); fwrite(output_v,1,720*576/4,fout); //-------------------- YUV RGB for(j=0;j<720*576;j ) { R[j] = int(input_y[j] (1.4075*(input_v[j/4]-128))); G[j] = int(input_y[j] - (0.3455*(input_u[j/4]-128)) - (0.7169*(input_v[j/4]-128))); B[j] = int(input_y[j] (1.779*(input_u[j/4]-128))); if ( G[j]<0){ G[j]=0;} if ( B[j]<0){ B[j]=0;} if ( R[j]<0){ R[j]=0;} if ( G[j]>255){ G[j]=255;} if ( B[j]>255){ B[j]=255;} if ( R[j]>255){ R[j]=255;} } //-------------------- display pic { Image1->Picture->Bitmap->Width=720; Image1->Picture->Bitmap->Height=576; Image1->Picture->Bitmap->PixelFormat=pf24bit; for(int y=0;y<576;y ) { pt=(Byte*)Image1->Picture->Bitmap->ScanLine[y]; for(int x=0;x<720;x ) { pt[3*x 0] = B[y*720 x]; pt[3*x 1] = G[y*720 x]; pt[3*x 2] = R[y*720 x]; } } Image1->Refresh(); } //-------------------------------------------- } fclose(fin); fclose(fout); fclose(depth_in); Button1->Enabled=true; } [code cpp] 請在此區域輸入程式碼 [/code] |
istillloving
高階會員 發表:33 回覆:182 積分:183 註冊:2008-10-09 發送簡訊給我 |
http://realchecko.blogspot.com/2009/02/yuv420-rgb565.html
我試看看 但是看它裡面的說明...你應該不能用 無號整數 宣告double看看吧 貼一段維基百科 Y'UV444大多數 YUV 格式平均使用的每像素位數都少於24位元。YUV444是最逼真的格式,一格不刪(24 bits),即每4個Y,配上4個 U,還有4個 V;YUV422則是在UV格式上減半,即每4個Y,配2個U,2個V ;YUV420則是在UV上減1/4之格式,即每4個Y,配1個U,再配1個V。這些公式是基於 NTSC standard; [code cpp] for(j=0;j for(i=0;i color=Form1->Image1->Picture->Bitmap->Canvas->Pixels[i][j]; CR[i w*j] = GetRValue(color); CG[i w*j] = GetGValue(color); CB[i w*j] = GetBValue(color); FirstCR[i w*j] = CR[i w*j]; FirstCG[i w*j] = CG[i w*j]; FirstCB[i w*j] = CB[i w*j]; buffy[i w*j] = 0.299 *CR[i w*j] 0.587 *CG[i w*j] 0.114 *CB[i w*j] ; buffu[i w*j] = -0.14713 *CR[i w*j] - 0.28886 *CG[i w*j] 0.436 *CB[i w*j] ; buffv[i w*j] = 0.615 *CR[i w*j] - 0.51499 *CG[i w*j] - 0.10001 *CB[i w*j] ; } } [/code] 照維基的說法UV都變成(1/4) 所以我個人覺得色偏是正常的
------
恩...
編輯記錄
istillloving 重新編輯於 2009-12-20 11:15:06, 註解 無‧
istillloving 重新編輯於 2009-12-20 11:16:21, 註解 無‧ istillloving 重新編輯於 2009-12-20 11:18:59, 註解 無‧ istillloving 重新編輯於 2009-12-20 11:23:00, 註解 無‧ istillloving 重新編輯於 2009-12-20 11:29:34, 註解 無‧ |
itisbeautiful_2
一般會員 發表:2 回覆:3 積分:1 註冊:2009-12-18 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |