iOS 上的拼接全景崩溃与 cvflann::anyimpl::bad_any_cast

Stitching panorama on iOS crashes with cvflann::anyimpl::bad_any_cast

本文关键字:cast anyimpl bad cvflann any 拼接 全景 崩溃 iOS      更新时间:2023-10-16

我没有使用 c++ 的经验,但我需要在 iOS 应用程序中与 OpenCV 交互。我正确地构建了它,但在调用一些 c++ 代码时它崩溃了。

下面的代码崩溃并显示以下消息:libc++abi.dylib: libc++abi.dylib: terminating with uncaught exception of type cvflann::anyimpl::bad_any_cast terminating with uncaught exception of type cvflann::anyimpl::bad_any_cast

bool stitch(const std::vector <cv::Mat> & images, cv::Mat &result) {
    Stitcher stitcher = Stitcher::createDefault(false);
    Stitcher::Status status = stitcher.stitch(images, result); <-- Crash!
    if (status != Stitcher::OK) {
        return false;
    }
    return true;
}

我认为这是因为stitch(...)的输入或输出是不正确的类型,但我无法弄清楚我需要给它什么或如何转换它。

我调用的函数定义如下:

Status stitch(InputArrayOfArrays images, OutputArray pano); 

其中InputArrayOfArraysOutputArray都是_InputArray的别名

怎么办?

编辑:这是使用OpenCV 3.0,我认为我使用的示例代码是用于OpenCV 2.4的。也许这就是问题所在。

我在IOS中遇到了与导入相关的类似问题,并添加了

#import <opencv2/opencv.hpp>

导致一堆链接器警告,最终每次调用任何 OpenCV 函数都因上述错误而失败,在我用更具体的导入替换上面的导入后,问题消失了:

#import <opencv2/imgcodecs.hpp>

我认为问题可能与导入订购或导入重复有关,请注意希望它有所帮助......

这在

openCV 中已经存在了一段时间,它仅在调试模式下输出此错误时崩溃。尝试产品 ->方案 ->编辑方案,并将"运行"的构建配置从调试更改为发布。

放弃opencv.hpp的包含以支持最小的包含集也对我有用。 以下是我最终在我的案例中得到的包含。

#import <opencv2/calib3d.hpp>
#import <opencv2/features2d.hpp>
#import <opencv2/xfeatures2d.hpp>
#import <opencv2/imgproc/imgproc.hpp>

当时,我从拨打FlannBasedMatcher::knnMatch的某个地方获得了bad_any_cast,并且在找到此解决方案之前尝试了许多"更正"。

谢谢!

相同的崩溃 修复了使用以下代码的问题:

使用适用于 iOS 应用程序的开放式 cv 2.4.9 版本的拼接。另外,使用此代码它将非常适合iOS应用程序

https://github.com/foundry/OpenCVSwiftStitch

我已经花太多时间来修复崩溃,但现在它得到了修复。