iPhone 的 OpenCV / SURF 跟踪:创建结构时值错误

发布于 2024-11-19 15:04:55 字数 1506 浏览 7 评论 0原文

我正在使用 Objective-C 中的 OpenCV 库(交叉编译),它基本上工作得很好。

不幸的是,当使用 find_obj.cpp 中找到的示例时,我得到了 CvSURFParams 的奇怪值,必须将其作为参数传递给 cvExtractSURF 功能。

features2d.hpp (openCV 的一部分):

typedef struct CvSURFParams
{
    int    extended;
    double hessianThreshold;

    int    nOctaves;
    int    nOctaveLayers;

} CvSURFParams;

surf.cpp (openCV 的一部分):

CvSURFParams cvSURFParams(double threshold, int extended)
{
    CvSURFParams params;
    params.hessianThreshold = threshold;
    params.extended = extended;
    params.upright = 0;
    params.nOctaves = 4;
    params.nOctaveLayers = 2;
    return params;
}

ViewController.mm (我的主视图控制器):

CvSURFParams params = cvSURFParams(500, 1);

之后调用ViewController.mm中的cvSURFParams函数,参数值为:

extended         = (int)    1
hessianThreshold = (double) 0
nOctaves         = (int)    1082081280
nOctaveLayers    = (int)    4

修正hessianThreshold的值,一旦我将params传递给我的cvExtractSURFViewController.mm中的nOctaves,..就没有帮助函数,在 surf.cpp 中调试此函数时出现错误值:

extended         = (int)    1
upright          = (int)    0
hessianThreshold = (double) 500
nOctaves         = (int)    4
nOctaveLayers    = (int)    0

有人可以帮忙吗?

提前致谢,

--斯蒂芬

I'm using the OpenCV library in Objective-C (cross-compiled), which works fine basically.

Unfortunately, when using the example which can be found in find_obj.cpp, I get strange values for the CvSURFParams that has to be passed as an argument to the cvExtractSURF function.

features2d.hpp (part of openCV):

typedef struct CvSURFParams
{
    int    extended;
    double hessianThreshold;

    int    nOctaves;
    int    nOctaveLayers;

} CvSURFParams;

surf.cpp (part of openCV):

CvSURFParams cvSURFParams(double threshold, int extended)
{
    CvSURFParams params;
    params.hessianThreshold = threshold;
    params.extended = extended;
    params.upright = 0;
    params.nOctaves = 4;
    params.nOctaveLayers = 2;
    return params;
}

ViewController.mm (my main view controller):

CvSURFParams params = cvSURFParams(500, 1);

After calling the cvSURFParams function in ViewController.mm, the valus of params are:

extended         = (int)    1
hessianThreshold = (double) 0
nOctaves         = (int)    1082081280
nOctaveLayers    = (int)    4

Correcting the values for hessianThreshold, nOctaves, .. in ViewController.mm doesn't help, as soon as I pass params to my cvExtractSURF function, the wrong values appear when debugging this function in surf.cpp:

extended         = (int)    1
upright          = (int)    0
hessianThreshold = (double) 500
nOctaves         = (int)    4
nOctaveLayers    = (int)    0

Can anyone help please?

Thanks in advance,

-- Stephan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃素的狼 2024-11-26 15:04:55

听起来 OpenCV 中结构的表示与 ViewController.mm 的表示方式不同。要么 hessianThreshold 大小不同,要么存在对齐问题。需要检查的一些事项:

  1. 在 ViewController.mm 中输出 sizeof(CvSURFParams) 作为一些调试代码。也可以从 OpenCV 库执行此操作。它们很可能不一样。
  2. 您还可以在两个项目中输出 sizeof(double) 。它们应该是相同的,如果不是,那么您就发现了问题,并且需要指示编译器在两个项目中使用相同的 sizeof(double) 。
  3. 如果两个项目中的 sizeof(double) 相同,则问题似乎是编译器在每个项目中以不同方式对齐结构。同样,这很可能是编译器设置,尽管如果您不想要默认值,通常可以使用 #pragma 指令来指定特定的对齐方案。

It sounds like the representation of the structure in OpenCV is different from how your ViewController.mm represents it. Either hessianThreshold is a different size, or else there is an alignment problem. Some things to check:

  1. Output sizeof(CvSURFParams) in your ViewController.mm as some debug code. Also do this from the OpenCV library. Most likely they are not the same.
  2. You can also output sizeof(double) in both projects. They should be the same, if not then you found the problem and you'll need to instruct the compiler to use the same sizeof(double) in both projects.
  3. If sizeof(double) is the same in both projects, then the problem appears to be that the compiler is aligning the structures differently in each project. Again, this is most likely compiler settings, although typically there are #pragma instructions that can be used to specify a particular alignment scheme if you don't want the default.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文