OpenCV 与 std::vector 不兼容? (_crtIsValidHeapPointer 错误)

发布于 2025-01-02 06:16:34 字数 561 浏览 0 评论 0原文

我无法在向量中获取 OpenCV 中的类/结构,并使函数保持活动状态而不会出现任何堆损坏。每当我打开本机 OpenCV 对象向量时,垃圾收集期间都会出现可怕的 _crtIsValidHeapPointer 错误。

上下文:尝试使用 ORB 来比较对象和场景图像中的匹配点。在 C++ 中使用 OpenCV 2.3.1。

代码示例:

vector< KeyPoint > objImageKeypoints;
Mat objImageDescriptors;
OrbFeatureDetector detector = orbFeatureDetector( 1000 );

detector.detect( objImage, objImageKeypoints );

... // There's more, but I've commented out the rest
}

在我通过了 detector() 方法之后,就没有回头路了。以后还是会给我带来麻烦。

一旦我到达函数末尾,系统就会崩溃。我是否遗漏了一些东西,或者我是否通过使用向量犯了 OpenCV 的一些大罪?

I'm having trouble getting classes/structs in OpenCV in a vector and leaving the function alive without any heap corruption. Any time I have a vector of native OpenCV objects open, the dreaded _crtIsValidHeapPointer error comes up during garbage collection.

Context: Trying to use ORB to compare matching points in a Object and Scene images. Using OpenCV 2.3.1 in C++.

Code example:

vector< KeyPoint > objImageKeypoints;
Mat objImageDescriptors;
OrbFeatureDetector detector = orbFeatureDetector( 1000 );

detector.detect( objImage, objImageKeypoints );

... // There's more, but I've commented out the rest
}

After I've passed the detect() method, there's no turning back. After that, it'll still give me trouble.

System blows up once I hit the end of the function. Am I missing something, or have I committed some cardinal sin of OpenCV by using vectors?

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

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

发布评论

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

评论(4

星星的軌跡 2025-01-09 06:16:34

我在使用 Visual Studio 2012(版本 11)和最初仅为 2010(版本 10)构建的 OpenCV2.4.3 时遇到了这个问题。
我使用的是版本 10 的 lib 和 dll。
我是在 2012 年构建的,现在它可以正常工作,没有堆损坏错误。

PS:在此之前(当使用为版本 10 构建时),我在 opencv 函数中使用之前调整了向量的大小。

I had this problem when using Visual Studio 2012(version 11) with OpenCV2.4.3 originally build only for 2010 (version 10).
I was using lib and dll for version 10.
Than I build it for 2012 nad now it works without heap corruption error.

P.S.: Before it (when using built for version 10), I resized vector before used in opencv function.

逆光下的微笑 2025-01-09 06:16:34

我今天在使用 HoughLinesP 函数时遇到了这个问题。

通过在网上搜索并查看诸如此类的问题,我终于找到了答案。 VisionC在这里的回答似乎是在正确的轨道上,但缺乏一点解释。我想您不再需要答案,但这可能对其他人有帮助。

问题是什么:

我不是专家,但是感谢 Michael在这里的回答,据我了解,用于构建OpenCV的Platform Toolset是v100(即Visual Studio 10中使用的工具集)。在 Visual Studio 11 (2012) 中,项目默认使用较新的 v110 平台工具集。 (我找不到任何说明新版本的 OpenCV 使用 v110 的内容。)

似乎发生的情况是,您为 OpenCV 函数(使用某些 v100 dll)提供一个向量,然后该函数会修改该向量。当您的程序(使用 v110 dll)清理矢量时,由于 OpenCV 对其进行了修改,因此存在不兼容性,从而导致错误。

抱歉,这太模糊了,但正如我所说,我不太了解它的来龙去脉。

如何解决它:

无论如何,我找到的关于这个问题的答案并没有真正好的解决方案。他们会谈论重建 OpenCV 和其他乏味的事情。正如您所发现的,返回到 VS2010 可以解决该问题,但是必须转换项目并返回到旧的 IDE 并不是很有趣。如果您像我一样使用 C++/CLI,则无法在 VS2010 中获得 IntelliSense。 :(

您需要做的就是转到 VS2012 中的项目属性。确保配置设置为“所有配置”。然后,在“配置属性 -> 常规 -> 平台工具集”下选择“Visual Studio 2010” (v100)”。这应该可以解决问题,并且将来您可以根据需要轻松更改设置。

如上所述 此处 不过,您仍然需要安装 VS 2010(或Windows Platform SDK)能够做到这一点。

I was having this problem today, with the HoughLinesP function.

From searching the internet and looking at questions like these, I have finally found the answer. VisionC's answer here seems to be on the right track, but lacks a bit of explanation. I imagine you don't still need the answer anymore, but this might be helpful to others maybe.

What the problem is:

I'm no expert, but thanks to Michael's answer here, as I understand it, the Platform Toolset used to build OpenCV is v100 (i.e. the toolset used in Visual Studio 10). In Visual Studio 11 (2012), projects default to using the newer v110 Platform Toolset. (I haven't been able to find anything that says if new versions of OpenCV use v110.)

What seems to be happening is that you give an OpenCV function (which is using some v100 dll's) a vector, which the function then modifies. When the vector is cleaned up by your program (using v110 dll's) there's an incompatibility, due to it being modified by OpenCV, which causes the error.

Sorry that's so vague, but as I said I don't really understand the ins-and-outs of it.

How to fix it:

Anyway, answers I've found on this didn't really have good solutions. They'd talk about rebuilding OpenCV and other tedious things. As you've discovered, going back to VS2010 fixes the issue, but having to convert the project and go back to the old IDE isn't too much fun. And if you're using C++/CLI like I am, you don't get IntelliSense in VS2010. :(

All you need to do to is go to your project properties in VS2012. Make sure the configuration is set to "All Configurations". Then, under "Configuration Properties->General->Platform Toolset" choose "Visual Studio 2010 (v100)". This should fix the problem, and in the future you can easily change the setting back if needed.

As described here though, you do still need to have VS 2010 installed (or the Windows Platform SDK) to be able to do this.

触ぅ动初心 2025-01-09 06:16:34

我在 OpenCV3 中遇到了同样的问题,我找到了答案。
在我的例子中,问题是我使用发布中的库而不是调试
您需要确保使用正确的 Lib/Dll
当您进行调试时,请确保使用调试库/DLL。

i was have the same problem in OpenCV3 and i found the answer.
the problem in my case that i use Libs from Release and not debug
you need to make sure to use the correct Libs/Dlls
when you are in debug please make sure to use Debug Libs/Dlls.

猫卆 2025-01-09 06:16:34

由于 OpenCV 文档还 使用 vector (在第一个代码块的 readwrite 函数中)这不应该是问题的根源。

可能您在该函数中执行的其他操作都会导致错误。

Since the OpenCV documentation also uses vector<KeyPoint> (in the read and write functions in the first code block) this shouldn't be the source of your problem.

Probably whatever else you are doing in that function causes the error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文