2012-02-09 13 views
0

ビデオのピクセルの輝度値にアクセスできません。私が使用しているビデオはすべて黒であるため、輝度値は0に近いと予想されます。ビデオの上半分のピクセルには当てはまりますが、下半分にはそれほど多くはありません。私は物事を間違った方法で読んでいる。上記の設定AVFoundationを使用したビデオピクセルの処理輝度値(Y ')

ビデオ設定:

[videoSettings setObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8Planar] forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey]; 

ここに私のコードです:

CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 

    // Lock the image buffer 
    CVPixelBufferLockBaseAddress(imageBuffer,0); 

    // Get information of the image 
    uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); 
    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 
    size_t width = CVPixelBufferGetWidth(imageBuffer); 
    size_t height = CVPixelBufferGetHeight(imageBuffer); 

    NSLog(@"dimensions: %lu x %lu", width, height); 

    for (uint y = 0; y < height; y += pixelSkipHeight) 
    { 
     uint8_t *p = baseAddress + y * bytesPerRow; // this gets Y' in YUV 

     for (uint x = 0; x < width; x += pixelSkipWidth) 
     { 

      if (x == 33 * 20) 
       NSLog(@"color at %dx%d: %u", x, y, p[0]); 

     } 


    } 

    // Unlock the image buffer 
    CVPixelBufferUnlockBaseAddress(imageBuffer,0); 


    CMSampleBufferInvalidate(sampleBuffer); 
    CFRelease(sampleBuffer); 
    sampleBuffer = nil; // NULL? 

ここに私の出力です:

2012-02-08 10:29:12.142 MyApp[5193:15103] dimensions: 1920 x 1080 
2012-02-08 10:29:12.143 MyApp[5193:15103] color at 660x0: 0 
2012-02-08 10:29:12.144 MyApp[5193:15103] color at 660x33: 5 
2012-02-08 10:29:12.145 MyApp[5193:15103] color at 660x66: 3 
2012-02-08 10:29:12.146 MyApp[5193:15103] color at 660x99: 4 
2012-02-08 10:29:12.146 MyApp[5193:15103] color at 660x132: 4 
2012-02-08 10:29:12.147 MyApp[5193:15103] color at 660x165: 4 
2012-02-08 10:29:12.148 MyApp[5193:15103] color at 660x198: 4 
2012-02-08 10:29:12.149 MyApp[5193:15103] color at 660x231: 5 
2012-02-08 10:29:12.150 MyApp[5193:15103] color at 660x264: 5 
2012-02-08 10:29:12.151 MyApp[5193:15103] color at 660x297: 3 
2012-02-08 10:29:12.152 MyApp[5193:15103] color at 660x330: 5 
2012-02-08 10:29:12.154 MyApp[5193:15103] color at 660x363: 4 
2012-02-08 10:29:12.156 MyApp[5193:15103] color at 660x396: 6 
2012-02-08 10:29:12.157 MyApp[5193:15103] color at 660x429: 6 
2012-02-08 10:29:12.158 MyApp[5193:15103] color at 660x462: 7 
2012-02-08 10:29:12.159 MyApp[5193:15103] color at 660x495: 5 
2012-02-08 10:29:12.160 MyApp[5193:15103] color at 660x528: 3 
2012-02-08 10:29:12.161 MyApp[5193:15103] color at 660x561: 6 
2012-02-08 10:29:12.162 MyApp[5193:15103] color at 660x594: 2 
2012-02-08 10:29:12.163 MyApp[5193:15103] color at 660x627: 4 
2012-02-08 10:29:12.164 MyApp[5193:15103] color at 660x660: 4 
2012-02-08 10:29:12.165 MyApp[5193:15103] color at 660x693: 6 
2012-02-08 10:29:12.166 MyApp[5193:15103] color at 660x726: 128 
2012-02-08 10:29:12.168 MyApp[5193:15103] color at 660x759: 129 
2012-02-08 10:29:12.169 MyApp[5193:15103] color at 660x792: 128 
2012-02-08 10:29:12.171 MyApp[5193:15103] color at 660x825: 129 
2012-02-08 10:29:12.172 MyApp[5193:15103] color at 660x858: 128 
2012-02-08 10:29:12.175 MyApp[5193:15103] color at 660x891: 128 
2012-02-08 10:29:12.177 MyApp[5193:15103] color at 660x924: 128 
2012-02-08 10:29:12.177 MyApp[5193:15103] color at 660x957: 128 
2012-02-08 10:29:12.198 MyApp[5193:15103] color at 660x990: 128 
2012-02-08 10:29:12.199 MyApp[5193:15103] color at 660x1023: 128 
2012-02-08 10:29:12.200 MyApp[5193:15103] color at 660x1056: 127 

任意のアイデア?前もって感謝します!

答えて

0

私はこのピクセル形式の詳細を知らないが、それは平面である場合、その後のようなものになるだろうイメージではないん

Plane 1 [Y0 Y1 ... YN] 
Plane 2 [U0 U1 ... UN/4] 
Plane 3 [V0 V1 ... VN/4] 

あなたの出力では最初の三分の二は、輝度サンプルであり、最後の3分の1は、私が期待しているように、それぞれ1/4解像度の2つのクロミナンス部分です。あなたはインタリーブされたサンプルを期待しているようです。

を参照してください。http://en.wikipedia.org/wiki/YUV#Y.27UV420p_.28and_Y.27V12_or_YV12.29色付きの表は、私がかなりよく言っていることを説明していると思います。

+0

また、クロミナンスサンプルは、クロマが通常は中央値にオフセットされるため、無色と同じ約128です。 – koan

+0

私は決して専門家でもありません。色空間:YUV、 クロマサブサンプリング:4:2:0、 ビット深度:8ビット –

+0

あなたはすでにそれが 'kCVPixelFormatType_420YpCbCr8Planar'であると言っています。 – koan

関連する問題