をグレースケールに変換してから元に戻そうとしてCVPixelBufferRef (YUV 4:2:0)
います。 IplImage
私の計画は、Y 平面を取得し、それを次のようbaseAddress
に設定することです。imageData
IplImage
- (IplImage*) CreateIplImageFromCVPixelBuffer:(CVPixelBufferRef) cvImageBuffer and:(int) outChannels
{
CVPixelBufferLockBaseAddress(cvImageBuffer, kCVPixelBufferLock_ReadOnly);
void *baseAddress = CVPixelBufferGetBaseAddressOfPlane(cvImageBuffer, 0);
size_t width = CVPixelBufferGetWidth(cvImageBuffer);
size_t height = CVPixelBufferGetHeight(cvImageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(cvImageBuffer);
IplImage *iplImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
//Fill it in.
iplImage->nSize = sizeof(IplImage);
iplImage->ID = 0;
iplImage->nChannels = 1;
iplImage->depth = IPL_DEPTH_8U;
iplImage->dataOrder = 0;
iplImage->origin = 0;
iplImage->width = width;
iplImage->height = height;
iplImage->roi = 0;
iplImage->maskROI = 0;
iplImage->imageId = 0;
iplImage->tileInfo = 0;
iplImage->imageSize = CVPixelBufferGetDataSize(cvImageBuffer);
iplImage->imageData = (char*)baseAddress;
iplImage->widthStep = bytesPerRow;
iplImage->imageDataOrigin = (char*)baseAddress;
CVPixelBufferUnlockBaseAddress(cvImageBuffer, kCVPixelBufferLock_ReadOnly);
return iplImage;
}
元に戻すには、次のように呼び出します。
- (void) writeIplImage:(IplImage*) iplImage toPixelBufferRef:(CVPixelBufferRef) output
{
CVPixelBufferCreateWithBytes(NULL,
iplImage->width,
iplImage->height,
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
iplImage->imageData,
iplImage->widthStep,
releaseImage,
iplImage,
NULL,
&output);
}
これはかなり簡単だと思っていましたが、うまくいきません。私の結果の画像は空です。
私が間違っているかもしれないアイデアはありますか?