我正在使用最新的 SDK 开发一个 iOS 应用程序。
这个应用程序将与 OpenCV 一起使用,我必须在相机上进行缩放,但这在 iOS SDK 上不可用,所以我想以编程方式进行。
我必须对每个视频帧进行“缩放”。这是我必须这样做的地方:
#pragma mark - AVCaptureSession delegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
/*Lock the image buffer*/
CVPixelBufferLockBaseAddress(imageBuffer,0);
/*Get information about the image*/
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
//size_t stride = CVPixelBufferGetBytesPerRow(imageBuffer);
//put buffer in open cv, no memory copied
cv::Mat image = cv::Mat(height, width, CV_8UC4, baseAddress);
// copy the image
//cv::Mat copied_image = image.clone();
_lastFrame = [NSData dataWithBytes:image.data
length:image.elemSize() * image.total()];
[DataExchanger postFrame];
/*We unlock the image buffer*/
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
}
你知道如何放大 aNSData
或 aCMSampleBufferRef
吗?