我只想在 C++ 项目中显示此“img1.jpg”图像,并在未来的进程中使用 opencv 库,但它只显示一个空的灰色窗口。这是什么原因。这段代码有错误吗?请帮忙!
这是代码;
Mat img1;
char imagePath[256] = "img1.jpg";
img1 = imread(imagePath, CV_LOAD_IMAGE_GRAYSCALE);
namedWindow("result", 1);
imshow("result", img1);
谢谢...
最佳答案
我遇到了同样的问题并解决了将 waitKey(1);
放在 imshow()
之后的问题。 OpenCV 文档解释了原因:
This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing, unless HighGUI is used within some environment that takes care of event processing.
关于image - OpenCV cv::Mat 显示空的灰色图像?找不到原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5845460/