在win32下新建一个OpenCV的工程,配置好OpenCV的环境后使用imshow()函数却显示不出图像,程序如下:
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
// 添加OpenCV图像处理库
#ifdef _DEBUG
# pragma comment(lib,"OpenCV/opencv_core249d.lib")
# pragma comment(lib,"OpenCV/opencv_highgui249d.lib")
# pragma comment(lib,"OpenCV/opencv_imgproc249d.lib")
#else
# pragma comment(lib,"OpenCV/opencv_core249.lib")
# pragma comment(lib,"OpenCV/opencv_highgui249.lib")
# pragma comment(lib,"OpenCV/opencv_imgproc249.lib")
#endif
int main(int argc, char** argv)
{
cv::Mat image = imread("test.jpg", 1);
cv::namedWindow("test1");
cv::imshow("test1", image);
system("pause");
return 0;
}
显示的图像如下:
经过多次尝试之后发现是system(“pause”)这句的问题,将其修改为waitKey()即可解决问题,修改后代码如下:
int main(int argc, char** argv)
{
cv::Mat image = imread("test.jpg", 1);
cv::namedWindow("test1");
cv::imshow("test1", image);
waitKay();//system("pause")
return 0;
}