- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 QTKit.framework 将所有帧写入磁盘以进行相机输入。但我得到的所有图像都是半透明的并且没有一些颜色,也许是色彩空间问题? ;(它们在预览 View 中看起来不错,但是当我编写它们时,“某些事情”发生了。我想知道那是什么。
-(void)savePNGImage:(CGImageRef)imageRef path:(NSString *)path {
NSURL *outURL = [[NSURL alloc] initFileURLWithPath:path];
CGImageDestinationRef dr = CGImageDestinationCreateWithURL ((CFURLRef)outURL, (CFStringRef)@"public.png" , 1, NULL);
CGImageDestinationAddImage(dr, imageRef, NULL);
CGImageDestinationFinalize(dr);
[outURL release];
}
-(void)saveJPEGImage:(CGImageRef)imageRef path:(NSString *)path {
CFMutableDictionaryRef mSaveMetaAndOpts = CFDictionaryCreateMutable(nil, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(mSaveMetaAndOpts, kCGImageDestinationLossyCompressionQuality,
[NSNumber numberWithFloat:1.0]); // set the compression quality here
NSURL *outURL = [[NSURL alloc] initFileURLWithPath:path];
CGImageDestinationRef dr = CGImageDestinationCreateWithURL ((CFURLRef)outURL, (CFStringRef)@"public.jpeg" , 1, NULL);
CGImageDestinationAddImage(dr, imageRef, mSaveMetaAndOpts);
CGImageDestinationFinalize(dr);
[outURL release];
}
- (void)captureOutput:(QTCaptureOutput *)captureOutput
didOutputVideoFrame:(CVImageBufferRef)videoFrame
withSampleBuffer:(QTSampleBuffer *)sampleBuffer
fromConnection:(QTCaptureConnection *)connection{
CVPixelBufferLockBaseAddress(videoFrame,0);
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(videoFrame);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(videoFrame);
size_t width = CVPixelBufferGetWidth(videoFrame);
size_t height = CVPixelBufferGetHeight(videoFrame);
CVPixelBufferUnlockBaseAddress(videoFrame,0);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef newContext = CGBitmapContextCreate(baseAddress,
width, height, 8,
bytesPerRow,
colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGImageRef frame = CGBitmapContextCreateImage(newContext);
CGContextRelease(newContext);
CGColorSpaceRelease(colorSpace);
[self savePNGImage:frame path:[NSString stringWithFormat:@"/Users/nacho4d/Desktop/framesCam/frame%003d.png", frameNum++]];
[self saveJPEGImage:frame path:[NSString stringWithFormat:@"/Users/nacho4d/Desktop/framesCam/frame%003d.jpeg", frameNum++]];
CGImageRelease(frame);
}
Capturer 属性只是帧大小和像素格式,如下所示:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32ARGB], (id)kCVPixelBufferPixelFormatTypeKey
更新:
我也尝试过使用 JPEG,并且得到了相同类型的图像,就像图像中缺少一些 channel ,并且所有写入的帧都有白色背景。 (因为 JPEG 不允许透明??)
原件和书面(JPEG)一张:
(我没有显示 PNG,因为它是透明的并且很难在浏览器中看到)
提前致谢。
最佳答案
我不确定您的问题是什么,但这是我将图像保存到磁盘的方法。只需传递您从委托(delegate)方法中获得的 CVImageBufferRef,当然还有您自己的 URL,它应该可以正常工作。至少对我来说是这样。祝你好运!
-(void)saveImage:(CVImageBufferRef)image toURL:(NSURL*)url{
NSCIImageRep *imageRep = [NSCIImageRep imageRepWithCIImage:[CIImage imageWithCVImageBuffer:image]];
NSImage *_image = [[NSImage alloc] initWithSize:[imageRep size]];
[_image addRepresentation:imageRep];
NSData *bitmapData = [_image TIFFRep resentation];
NSBitmapImageRep *bitmapRep = [NSBitmapImageRep imageRepWithData:bitmapData];
NSData *imageData = [bitmapRep representationUsingType:NSJPEGFileType properties:nil];
[_image release];
_image = [[NSImage alloc] initWithData:imageData];
NSBitmapImageRep *imgRep = [[_image representations] objectAtIndex: 0];
NSData *data = [imgRep representationUsingType: NSPNGFileType properties: nil];
[data writeToFile: [self getSaveString] atomically: NO];
[_image release];
}
关于cocoa - 将 CVImageBufferRef 转换为 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4014396/
- (void)processPixelBuffer: (CVImageBufferRef)pixelBuffer { CVPixelBufferLockBaseAddress( pixelB
我想使用 QTKit.framework 将所有帧写入磁盘以进行相机输入。但我得到的所有图像都是半透明的并且没有一些颜色,也许是色彩空间问题? ;(它们在预览 View 中看起来不错,但是当我编写它们
我正在尝试从 QT 电影的各个帧中提取像素数据。 我想我需要使用 CV,因为 QTKit 和 NSImage 会 太慢了... 我需要比较包含网络摄像头 (iSight) 当前帧的缓冲区 (CVIma
我正在制作一个简单的管道,从 AVCaptureSession 获取图像,在 OpenCV 中处理它们,然后在 OpenGL 中渲染它们。它基于 RosyWriter 但没有音频和录音功能。 Open
我是 iOS 编程和多媒体的新手,我正在研究一个名为 RosyWriter 的示例项目,该项目由 apple 在 this link 提供。 .在这里,我看到在代码中有一个名为 captureOutp
在 objective-c 中,您可以轻松地将 CVImageBufferRef 转换为 CVPixelBufferRef: CMSampleBufferRef sampleBuffer = some
此代码大部分都有效,但生成的数据似乎失去了颜色 channel (这是我的想法),因为生成的图像数据在显示时是蓝色的! 代码如下: UIImage* myImage=[UIImage imageNam
我正在使用 AVFoundation 并从 AVCaptureVideoDataOutput 获取样本缓冲区,我可以使用以下方法将其直接写入 videoWriter: - (void)writeBuf
我正在尝试从相机捕获视频。我已经获得了要触发的 captureOutput:didOutputSampleBuffer: 回调,它为我提供了一个示例缓冲区,然后我将其转换为 CVImageBuffer
我想分析来自 iOS 相机的每帧像素。我想知道是否有任何理由从 CVImageBufferRef 转到 CGImageRef,然后从 CGImageRef 获取像素,或者这些数据是否基本相同。想到的事
我有 CMSampleBufferRef(s),我使用 VTDecompressionSessionDecodeFrame 对其进行解码,这会在帧解码完成后生成 CVImageBufferRef,所以
我正在开发一个使用 AVFoundation 和 iDevices 后置摄像头进行实时视频处理的应用程序。 AVCaptureSession 配置了 sessionPreset AVCaputeSes
我现在想合并两个成功的概念。我成功地将 CATextLayer 分层到 CVImageBufferRef 相机框架上,然后使用 AVAssetWriterInputPixelBufferAdaptor
我尝试从 CVImageBufferRef 加载纹理: func createTextureFromCVImageBufferRef(buffer: CVImageBufferRef) { l
我有两种算法可以检测 AR 标记(ARToolKit 和 Infi)。我让他们在 iPhone 上实时检测标记。在这个阶段,我想比较一下它们的速度和准确性。我想准备一系列图像并对其进行测试识别。我可以
我是一名优秀的程序员,十分优秀!