在 OpenCV 和 C/C++ 中将 Mat 转换为 IplImage*
在我的应用程序中,我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么尝试将 C 接口与 C++ 数据类型一起使用?使用C++接口。
Why do you try to use the C interface with C++ datatypes? Use the C++ interface.
试试这个:
顺便说一句。也许使用 C++ OpenCV 函数来显示图像确实会更好,它应该更容易,而且您不会担心是否已清理所有分配的内存(最好看一下这里的示例代码: http://opencv.willowgarage.com/documentation/cpp/introduction.html )。
Try this:
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).