ios – 相机像“645 PRO”的原始图像数据

前段时间我已经问过这个问题,我也得到了一个很好的答案:

I’ve been searching this forum up and down but I couldn’t find what I
really need. I want to get raw image data from the camera. Up till now
I tried to get the data out of the imageDataSampleBuffer from that
method
captureStillImageAsynchronouslyFromConnection:completionHandler: and
to write it to an NSData object,but that didn’t work. Maybe I’m on
the wrong track or maybe I’m just doing it wrong. What I don’t want is
for the image to be compressed in any way.

The easy way is to use jpegStillImageNSDataRepresentation: from
AVCaptureStillImageOutput,but like I said I don’t want it to be
compressed.

Thanks!

Raw image data from camera

我以为我可以使用这个,但是我终于注意到,我需要像“645 PRO”中类似的方式更直接地获取原始图像数据.

645 PRO: RAW Redux

该网站上的图片显示,在任何jpeg压缩完成之前,它们都将获取原始数据.那就是我想做的我的猜测是,我需要转换imageDataSampleBuffer,但是我没有看到完全没有压缩的方法.
“645 PRO”也将其图片保存在TIFF中,所以我认为它至少使用一个附加库.

我不想制作照片应用程序,但我需要最好的质量来检查图片中的某些功能.

谢谢!

编辑1:
所以在不同的方向尝试和搜索一段时间后,我决定给一个状态更新.

该项目的最终目标是检查在opencv的帮助下会发生的图片中的某些功能.但是直到应用程序能够在手机上执行此操作,我试图将大部分未压缩的图像从手机中分离出来才能在计算机上进行分析.

因此,我想保存“NSData实例包含从相机返回的未压缩的BGRA字节”我可以使用Brad Larson的代码作为bmp或TIFF文件.
正如我在评论中所说的,我尝试使用opencv(这将是需要的).但是最好的办法就是把它变成一个从Computer Vision Talks起的一个UIImage.

void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
cv::Mat frame(height,width,CV_8UC4,(void*)baseAddress);
UIImage *testImag = [UIImage imageWithMat:frame andImageOrientation:UIImageOrientationUp];
//imageWithMat... being the function from Computer Vision Talks which I can post if someone wants to see it

ImageMagick – 方法

另一件我试过的是使用ImageMagick,如another post所示.
但是,如果没有使用像UIImagePNGRepresentation或UIImageJPEGRepresentation这样的东西,我找不到办法.

现在我试图用libtiff来做这个tutorial.

也许有人有一个想法,或者知道一个更简单的方法来将我的缓冲区对象转换成一个未压缩的图片.
再次感谢!

编辑2:

我发现了一些东西!我必须说我很盲目.

void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
cv::Mat frame(height,(void*)baseAddress);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"ocv%d.TIFF",picNum]];
const char* cPath = [filePath cStringUsingEncoding:NSMacOSRomanStringEncoding];

const cv::string newPaths = (const cv::string)cPath;

cv::imwrite(newPaths,frame);

我只需要使用opencv的imwrite函数.这样我可以在beyer-Polarization之后直接获得大约30 MB的TIFF文件!

解决方法

哇,那个博文是特别的.很多单词只是表示他们获取了Apple从静止图像中返回的示例缓冲区字节.他们的方法没有什么特别的创新,我知道一些这样做的相机应用程序.

您可以使用AVCaptureStillImageOutput拍摄的照片返回的原始字节,使用以下代码:

[photoOutput captureStillImageAsynchronouslyFromConnection:[[photoOutput connections] objectAtIndex:0] completionHandler:^(CMSampleBufferRef imageSampleBuffer,NSError *error) {
    CVImageBufferRef cameraFrame = CMSampleBufferGetImageBuffer(imageSampleBuffer);
    CVPixelBufferLockBaseAddress(cameraFrame,0);
    GLubyte *rawImageBytes = CVPixelBufferGetBaseAddress(cameraFrame);
    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(cameraFrame);
    NSData *dataForRawBytes = [NSData dataWithBytes:rawImageBytes length:bytesPerRow * CVPixelBufferGetHeight(cameraFrame)];
    // Do whatever with your bytes

    CVPixelBufferUnlockBaseAddress(cameraFrame,0);
}];

这将给你一个包含从相机返回的未压缩的BGRA字节的NSData实例.您可以将它们保存到磁盘,或者做任何你想要的.如果您真的需要自己处理这些字节,我将避免NSData创建的开销,并且只从像素缓冲区的字节数组中使用.

以上是来客网为你收集整理的ios – 相机像“645 PRO”的原始图像数据全部内容,希望文章能够帮你解决ios – 相机像“645 PRO”的原始图像数据所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。