作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
一般来说,我是 openCV 和 C/C++ 的新手。我正在研究 this教程并使用 CMake 生成我的 makefile。我构建第一个程序(读取和显示)没有问题,但是当我运行可执行文件时,没有任何反应,我必须关闭我的终端,因为它只是挂起。即使我只使用以下代码也会发生这种情况:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, const char** argv )
{
cout << "start\n";
Mat img = imread("MyPic.jpg");
return 0;
}
当我删除 Mat img
行时,会输出“start”,但当我包含它时,即使这样也不会发生。 MyPic.jpg 肯定与 ReadDisplay.cpp 和 CMakeLists.txt 在同一个目录中。我正在运行 Ubuntu 14.04。最后,这是 CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project( ReadDisplay )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( ReadDisplay ReadDisplay.cpp )
target_link_libraries( ReadDisplay ${OpenCV_LIBS} )
关于这导致问题的原因有什么见解吗?
编辑
上面的代码是为了解释我是如何调试的,以及是什么导致了问题;我已经尝试通过检查图像大小和其他方法来捕捉故障,将其隔离为系统/配置问题。根据 this帖子,我正在从源代码重建 openCV,看看是否能解决任何问题。
最佳答案
首先你需要确定问题出在找图片上,所以请不要跳过这部分代码:
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
因此,如果问题出在查找图像上,为避免混淆,您可以传递绝对路径,例如:/home/user/my_pic.jpg
关于c++ - OpenCV imread 默默失败的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34684760/
我是一名优秀的程序员,十分优秀!