【发布时间】:2016-03-04 19:01:20
【问题描述】:
我正在尝试在 iOS 上使用 openCV 3 从多次曝光中生成 HDR 图像,最终将输出为 EXR 文件。当我尝试创建 HDR 图像时,我注意到输出出现乱码。认为尝试创建相机响应是一个错误,我从头开始,将 openCV 上的 HDR 成像教程材料改编为 iOS,但它产生了类似的结果。以下 C++ 代码返回乱码:
cv::Mat mergeToHDR (vector<Mat>& images, vector<float>& times)
{
imgs = images;
Mat response;
//Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();
//calibrate->process(images, response, times);
Ptr<CalibrateRobertson> calibrate = createCalibrateRobertson();
calibrate->process(images, response, times);
// create HDR
Mat hdr;
Ptr<MergeDebevec> merge_debevec = createMergeDebevec();
merge_debevec->process(images, hdr, times, response);
// create LDR
Mat ldr;
Ptr<TonemapDurand> tonemap = createTonemapDurand(2.2f);
tonemap->process(hdr, ldr);
// create fusion
Mat fusion;
Ptr<MergeMertens> merge_mertens = createMergeMertens();
merge_mertens->process(images, fusion);
/*
Uncomment what kind of tonemapped image or hdr to return
Returning one of the images in the array produces ungarbled output
so we know the problem is unlikely with the openCV to UIImage conversion
*/
//give back one of the images from the image array
//return images[0];
//give back one of the hdr images
return fusion * 255;
//return ldr * 255;
//return hdr
}
图片是这样的:
我分析了图像,尝试了各种色彩空间转换,但数据似乎是垃圾。
openCV 框架是来自 openCV.org 网站的最新编译的 3.0.0 版本。 RC 和 alpha 产生相同的结果,并且当前版本不会构建(对于 iOS 或 OSX)。我在想我的下一步是尝试让框架从头开始编译,或者让示例在另一个平台下工作,以查看问题是特定于平台还是与 openCV HDR 函数本身有关。但在我这样做之前,我想我会把这个问题放在堆栈溢出上,看看是否有人遇到过同样的问题,或者我是否遗漏了一些非常明显的东西。
我已经将示例 xcode 项目上传到这里:
https://github.com/artandmath/openCVHDRSwiftExample
在 Github 上的用户代工厂的帮助下,让 openCV 与 swift 一起工作
【问题讨论】:
-
我可以确认示例代码在 OSX 下可以正常工作,而您的项目版本在 iOS 上却没有。这使问题范围缩小了一点。
-
更正上一条评论 - 代码在 OSX 上的工作方式相同,但使用 imshow() 可以正确转换格式。在 iOS 上,通过 wrapper 传回,存在格式转换问题...
-
谢谢@foundry。我重建了框架只是为了确定并遇到了同样的问题。回到 UIImage+OpenCV,initWithCVMat 期望每个像素有一个硬编码的 8 位通道,所以我想这个问题可以在这里解决,或者我可以在将图像交给 UIKit 之前在 openCV 中将图像转换为 8 位。