iOS&MAC攝像頭采集格式

  kCVPixelFormatType_420YpCbCr8Planar = 'y420',  
 /* Planar Component Y'CbCr 8-bit 4:2:0.  baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrPlanar struct */

  kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange = '420v', 
/* Bi-Planar Component Y'CbCr 8-bit 4:2:0, video-range (luma=[16,235] chroma=[16,240]).  baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrBiPlanar struct */

  kCVPixelFormatType_420YpCbCr8BiPlanarFullRange  = '420f', 
/* Bi-Planar Component Y'CbCr 8-bit 4:2:0, full-range (luma=[0,255] chroma=[1,255]).  baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrBiPlanar struct */ 

YpCbCr

Y分量:Y,U分量:Cb,V分量:Cr。即YUV格式的數(shù)據(jù)。
#######8-bit
并且每個點(diǎn)采用8bit來保存一個Y的亮度。

4:2:0

YUV的詳細(xì)格式為:4:2:0。

baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrPlanar struct

YUV數(shù)據(jù)的地址在CVPlanarPixelBufferInfo_YCbCrPlanar中以大端的形式存儲。

Planar & Bi-Planar

第一個是Planar模式,第二個是BiPlanar模式。
Planar格式就是單平面模式,在這個模式下,一個buf存儲所有的數(shù)據(jù)。將Y、U、V分量分別打包,依次存儲。即YYYY...U...V...即I420.
BiPlanar格式就是雙平面模式,在這個模式下,亮度和色度被分成兩個buf來存儲。將Y和UV分別打包,一次存儲。即YYYY...UV...即NV12.

VideoRange & FullRange

亮度和色度的取值為8位,即2^8 = 256即可取值為【0-255】
VideoRange能取的值寬度為【16-235】
FullRange能取得值寬度為【0-255】

采集信息查看

查看采集到的信息。

CMSampleBufferGetFormatDescription(sampleBuffer);

#######如何從采集的CMSampleBufferRef中取得YUV數(shù)據(jù)
轉(zhuǎn)化為CVImageBufferRef:

CVImageBufferRef buffer = CMSampleBufferGetImageBuffer(sampleBuffer);

獲取寬高:

CVPixelBufferGetWidth(pixelBuffer);
CVPixelBufferGetHeight(pixelBuffer);

取得YUV數(shù)據(jù)地址:

CVPixelBufferGetBaseAddressOfPlane(pixelBuffer,Plane_index);
//這里的Plane_index與上文的Plane模式相關(guān)
如果是Plane模式則直接取到所有數(shù)據(jù)
如果是BiPlane則需要分兩次,即Plane_index=0取得Y分量地址與Plane_index=1取得UV分量的地址
注意事項(xiàng)

在操作pixelBuffer的時(shí)候記得加上鎖

    CVPixelBufferLockBaseAddress(pixelBuffer, lockFlag);
    //在這里操作
    CVPixelBufferUnlockBaseAddress(pixelBuffer, lockFlag);
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容