来自“645 PRO"等相机的原始图像数据 [英] Raw image data from camera like "645 PRO"

查看:15
本文介绍了来自“645 PRO"等相机的原始图像数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

A time ago I already asked this question and I also got a good answer:

我一直在搜索这个论坛,但我找不到我想要的真的需要.我想从相机获取原始图像数据.至目前为止我试图从中获取 imageDataSampleBuffer 中的数据方法captureStillImageAsynchronouslyFromConnection:completionHandler: 和将其写入 NSData 对象,但这不起作用.也许我在错误的轨道,或者我只是做错了.我不想要的是以任何方式压缩图像.

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.

简单的方法是使用 jpegStillImageNSDataRepresentation: fromAVCaptureStillImageOutput,但就像我说的我不希望它是压缩.

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

谢谢!

来自相机的原始图像数据

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

I thought I could work with this, but I finally noticed that I need to get raw image data more directly in a similar way as it is done in "645 PRO".

645 PRO:RAW Redux

该网站上的图片显示他们在任何 jpeg 压缩完成之前获得了原始数据.这就是我想做的.我的猜测是我需要转换 imageDataSampleBuffer 但我没有看到完全不压缩的方法.645 PRO"还将其图片保存在 TIFF 中,因此我认为它至少使用了一个额外的库.

The pictures on that site show that they get the raw data before any jpeg compression is done. That is what I want to do. My guess is that I need to transform imageDataSampleBuffer but I don't see a way to do it completely without compression. "645 PRO" also saves its pictures in TIFF so I think it uses at least one additional library.

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

I don't want to make a photo app but I need the best quality I get to check for certain features in a picture.

谢谢!

编辑 1:因此,在尝试并在不同的方向搜索了一段时间后,我决定更新状态.

Edit 1: So after trying and searching in different directions for a while now I decided to give a status update.

这个项目的最终目标是检查图片中的某些特征,这将在 opencv 的帮助下发生.但在应用程序能够在手机上执行此操作之前,我会尝试从手机中获取大部分未压缩的图片,以便在计算机上对其进行分析.

The final goal of this project is to check for certain features in a picture which will happen with the help of opencv. But until the app is able to do it on the phone I'm trying to get mostly uncompressed pictures out of the phone to analyse them on the computer.

因此,我想将 Brad Larson 的代码保存为 bmp 或 TIFF 文件的包含从相机返回的未压缩 BGRA 字节的 NSData 实例".正如我在评论中所说,我尝试为此使用 opencv(无论如何都需要它).但我能做的最好的事情就是把它变成一个 UIImage ,它的函数来自 计算机视觉讲座.

Therefore I want to save the "NSData instance containing the uncompressed BGRA bytes returned from the camera" I'm able to get with Brad Larson's code as bmp or TIFF file. As I said in a comment I tried using opencv for this (it will be needed anyway). But the best I could do was turning it into a UIImage with a function from Computer Vision Talks.

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 - 方法

我尝试的另一件事是按照 another post<中的建议使用 ImageMagick/a>.但是如果不使用 UIImagePNGRepresentationUIImageJPEGRepresentation 之类的东西,我找不到办法.

Another thing I tried was using ImageMagick as suggested in another post. But I couldn't find a way to do it without using something like UIImagePNGRepresentationor UIImageJPEGRepresentation.

现在我正在尝试使用这个 tutorial 对 libtiff 做一些事情.

For now I'm trying to do something with libtiff using this tutorial.

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

Maybe someone has an idea or knows a much easier way to convert my buffer object into an uncompressed picture. Thanks in advance again!

编辑 2:

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

I found something! And I must say I was very blind.

void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
cv::Mat frame(height, width, CV_8UC4, (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-Polarisation 之后直接获得大约 30 MB 的 TIFF 文件!

I just have to use the imwrite function from opencv. This way I get TIFF-files around 30 MB directly after the beyer-Polarisation!

推荐答案

我可以用 OpenCV 解决它.感谢所有帮助过我的人.

I could solve it with OpenCV. Thanks to everyone who helped me.

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

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

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

cv::imwrite(newPaths, frame);

我只需要使用 opencv 中的 imwrite 函数.这样我就可以在拜耳过滤器之后直接获得大约 24 MB 的 BMP 文件!

I just have to use the imwrite function from opencv. This way I get BMP-files around 24 MB directly after the bayer-filter!

这篇关于来自“645 PRO"等相机的原始图像数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆