在 OpenCV 和 C/C++ 中将 Mat 转换为 IplImage*

发布于 2024-11-10 11:32:36 字数 820 浏览 0 评论 0原文

在我的应用程序中,我有一个 Mat 文件,我想在带有 cvShowImage 的窗口中显示该文件,其定义为:

void cvShowImage( const char* name, const CvArr* image )

现在,问题是,如果我直接传递 Mat 图像,它会给我一个错误转换:

cannot convert 'cv::Mat' to 'const CvArr*' for argument '2' to 'void cvShowImage(const char*, const CvArr*)'

我尝试搜索在这个论坛中,对于有同样问题的人,我找到了这个 opencv 文档: http://opencv.willowgarage.com/documentation/cpp/c++_cheatsheet .html

但我不明白如何使用它。

有人能给我一个如何将 Mat 图像转换为 IplImage 的例子吗?

这是我的代码:

Mat file;
Mat hogResultFrame = hogStep(temp2);
file = hogResultFrame;

  cvShowImage(window_title, (const CvArr*)(file));

但它给了我一个错误转换。

我希望你能帮助我,

非常感谢!

in my application I have a Mat file which i'd like to show in a window with cvShowImage which is defined as:

void cvShowImage( const char* name, const CvArr* image )

Now, the problem is that if i pass directly the Mat image, it gives me an error conversion:

cannot convert 'cv::Mat' to 'const CvArr*' for argument '2' to 'void cvShowImage(const char*, const CvArr*)'

I tryed to search in this forum for someone with the same problem and i found this opencv documentation:
http://opencv.willowgarage.com/documentation/cpp/c++_cheatsheet.html

But i didn't understand how to use it.

Can someone give me an example of how to convert Mat image to IplImage, please?

This is my code:

Mat file;
Mat hogResultFrame = hogStep(temp2);
file = hogResultFrame;

  cvShowImage(window_title, (const CvArr*)(file));

but it gives me an error coversion.

I hope you can help me,

thanks a lot!

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

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

发布评论

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

评论(2

不爱素颜 2024-11-17 11:32:36

为什么尝试将 C 接口与 C++ 数据类型一起使用?使用C++接口。

cv::namedWindow(window_title, 1);
cv::imshow(window_title, file);

Why do you try to use the C interface with C++ datatypes? Use the C++ interface.

cv::namedWindow(window_title, 1);
cv::imshow(window_title, file);
Saygoodbye 2024-11-17 11:32:36

试试这个:

IplImage image = file;
cvShowImage(window_title, &image);

顺便说一句。也许使用 C++ OpenCV 函数来显示图像确实会更好,它应该更容易,而且您不会担心是否已清理所有分配的内存(最好看一下这里的示例代码: http://opencv.willowgarage.com/documentation/cpp/introduction.html )。

Try this:

IplImage image = file;
cvShowImage(window_title, &image);

BTW. Maybe it would really be better to use C++ OpenCV functions for showing images, it should be easier and you won't get yourself concerns on whether you have cleaned all allocated memory or not (it is good to take a look at sample code here: http://opencv.willowgarage.com/documentation/cpp/introduction.html).

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