在我正在进行项目时,我注意到我无法加载图像。这里是我用来检查的简单代码:OpenCV无法加载图像
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if(argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
Mat gray_image;
cv::cvtColor(image, gray_image, CV_RGB2GRAY);
imwrite("Gray_Image.jpg",gray_image);
return 0;
}
下面是它的输出,当我执行它:
[email protected]:~# ./tryit lena.jpg
Could not open or find the image
我试图直接使用图像的地址(“/家/根/lena.jpg“)而不是argv [1],但没有任何改变。
可能是什么问题?
ps:我正在交叉编译这个OpenCV程序,然后在安装了Angstrom Linux的BeagleBone上运行它。这个问题可以与它相关吗?
您的Angstrom Linux安装有可能不支持JPEG文件的OpenCV设置。你可以使用'fopen'之类的东西来确保你可以访问文件,并且可以在BeagleBone上查找JPEG库吗? – 2012-07-26 10:17:07
@RajeshJAdvani我打开它与fopen并检查它是否为NULL,它不是。所以我没有任何问题访问文件。顺便说一下,我的Angstrom Linux上没有OpenCV设置。我使用OpenCV库交叉编译PC上的程序,这些库也是为ARM Cortex A8交叉编译的,然后在我的beaglebone上执行。 – 2012-07-26 12:29:51
@RajeshJAdvani我开始认为这个问题与我的OpenCV库有关。也许我无法成功交叉编译它们。如果是这样的话,我可以通过下面的方法搞清楚:我可以发送一个字节数组而不是图像,然后让OpenCV处理它。你有一个想法如何将图片转换为字节数组? – 2012-07-26 12:57:14