[英]MS Visual Studio 2012 and OpenCV 2.4.5 - Image is not displayed
I'm using MS Visual Studio 2012 and OpenCV 2.4.5. 我正在使用MS Visual Studio 2012和OpenCV 2.4.5。 I tried to run the following code.
我试图运行以下代码。 I'm
我
using OpenCV for the first time. 首次使用OpenCV。 I got this piece of code from the internet.
我从互联网上获得了这段代码。 I just want to
我只想
check whether OpenCV is working fine on my laptop. 检查OpenCV在笔记本电脑上是否工作正常。
As the output, a window is popped up ( gray-colured blank window) but the image is not 作为输出,将弹出一个窗口(灰色空白窗口),但图像不
displayed in it. 显示在其中。 Can you point out where I have gone wrong ?
您能指出我哪里出问题了吗?
#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;
}
clearly , it did not find your image. 显然,它没有找到您的图像。
try an absolute path instead 尝试使用绝对路径
sidenote: 边注:
you're trying to use the outdated c-api. 您正在尝试使用过时的c-api。 it's only being kept around for maintenance / portability reasons,
仅出于维护/便携性原因而保留它,
you should not develop any new code like that ! 您不应该开发任何类似的新代码!
you should not develop any new code like that ! 您不应该开发任何类似的新代码!
you should not develop any new code like that ! 您不应该开发任何类似的新代码!
(was that clear enough ?) (足够清楚了吗?)
instead use the 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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.