gpt4 book ai didi

c++ - MS Visual Studio 2012 和 OpenCV 2.4.5 - 图像不显示

转载 作者:行者123 更新时间:2023-11-28 07:07:52 25 4
gpt4 key购买 nike

我使用的是 MS Visual Studio 2012 和 OpenCV 2.4.5。我试图运行以下代码。我是

第一次使用 OpenCV。我从互联网上得到了这段代码。我只想

检查 OpenCV 在我的笔记本电脑上是否正常运行。

作为输出,弹出一个窗口(灰色空白窗口)但图像不是

显示在其中。你能指出我哪里出错了吗?

#include "stdafx.h"

#include "opencv/cv.h"

#include "opencv2/highgui/highgui.hpp"

int main(int argc, char** argv)
{

IplImage* img = cvLoadImage( "image.jpg" );

cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );

cvShowImage("Example1", img);

cvWaitKey(0);

cvReleaseImage( &img );

cvDestroyWindow( "Example1" );

return 0;
}

最佳答案

很明显,它没有找到您的图片。

试试绝对路径

旁注:

您正在尝试使用过时的 c-api。它只是出于维护/便携性的原因而保留,

你不应该像那样开发任何新代码!

你不应该像那样开发任何新代码!

你不应该像那样开发任何新代码!

(够清楚了吗?)

改为使用 c++ api:

#include "opencv2/core/core.hpp"    
#include "opencv2/highgui/highgui.hpp"

int main(int argc, char** argv)
{

cv::namedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cv::Mat img = cv::imread( "d:/some/dir/some.png" );
if ( img. empty() ) // only idiots *don't check* resource loading ...
return -1;

cv::imshow("Example1", img);
cv::waitKey(0);

// no cleanup required with c++ ..
return 0;
}

关于c++ - MS Visual Studio 2012 和 OpenCV 2.4.5 - 图像不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21503687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com