使用openCV Mat c ++加载图像

编程入门 行业动态 更新时间:2024-10-28 22:31:46
本文介绍了使用openCV Mat c ++加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在openCV中使用Mat加载图片

I want to load an image using Mat in openCV

我的代码是:

Mat I = imread("C:/images/apple.jpg", 0); namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display. imshow( "Display window", I );

我在一个消息框中收到以下错误:

I am getting the following error in a message box:

Unhandled exception at 0x70270149 in matching.exe: 0xC0000005: Access violation reading location 0xcccccccc.

请注意,我包括:

#include <cv.h> #include <cxcore.h> #include <highgui.h> #include <iostream> #include <math.h>

请帮忙。谢谢。

推荐答案

我有已经谈过这个这么多次,我想这是没有意义,但再次,但代码防御:如果方法/函数调用失败,请确保知道发生的时间:

I've talked about this so many times before, I guess it's pointless to do it again, but code defensively: if a method/function call can fail, make sure you know when it happens:

Mat I = imread("C:\\images\\apple.jpg", 0); if (I.empty()) { std::cout << "!!! Failed imread(): image not found" << std::endl; // don't let the execution continue, else imshow() will crash. } namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display. imshow( "Display window", I ); waitKey(0);

请注意,Windows的路径使用反斜杠 \ 而不是在* nix系统上使用的标准 / 。您需要在传递文件名时转义反斜杠: C:\\images\\apple.jpg

Note that Windows' path uses backslash \ instead of the standard / used on *nix systems. You need to escape the backslash when passing the filename: C:\\images\\apple.jpg

如果使用 imshow()。

Calling waitKey() is mandatory if you use imshow().

EDIT :

如果是 cv :: imread()这是抛出异常我知道唯一的解决方案是下载OpenCV源并构建在机器上,因为重新安装OpenCV不能解决这个问题。

If it's cv::imread() that is throwing the exception the only solution I know to work is downloading OpenCV sources and building it on the machine, since re-installing OpenCV doesn't fix the issue.

更多推荐

使用openCV Mat c ++加载图像

本文发布于:2023-05-26 09:50:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/252293.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   加载   openCV   Mat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!