C++opencv显示图像
时间: 2023-12-14 10:34:13 浏览: 176
以下是使用C++和OpenCV显示图像的示例代码:
```cpp
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
// 读取图像
Mat image = imread("example.jpg");
// 检查图像是否成功读取
if (image.empty())
{
cout << "Could not open or find the image" << endl;
return -1;
}
// 创建窗口并显示图像
namedWindow("Display window", WINDOW_NORMAL);
imshow("Display window", image);
// 等待用户按下任意按键
waitKey(0);
return 0;
}
```
这段代码首先使用`imread`函数读取名为`example.jpg`的图像文件。然后,它创建一个名为“Display window”的窗口,并使用`imshow`函数在该窗口中显示图像。最后,它使用`waitKey`函数等待用户按下任意按键,然后关闭窗口并退出程序。
相关问题
C++ opencv
C++ OpenCV是一个流行的开源计算机视觉库,提供了许多用于图像处理和计算机视觉任务的功能。它支持多种操作系统,包括Windows、Linux和Mac OS X。
使用C++ OpenCV可以实现各种功能,如图像和视频处理、特征检测和匹配、目标跟踪、人脸识别、文字识别等等。
以下是一个使用C++ OpenCV读取图像并显示的简单示例代码:
```c++
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat img = cv::imread("image.jpg"); // 读取图像
cv::imshow("Image", img); // 显示图像
cv::waitKey(0); // 等待按键
return 0;
}
```
这将显示名为“Image”的窗口,并在其中显示指定名称的图像。通过按任意键退出程序。
学习C++ OpenCV需要一些计算机视觉基础知识,如图像处理、线性代数和计算机视觉算法。有许多教程和资源可用于学习OpenCV,如官方文档、书籍、博客和在线课程。
阅读全文
相关推荐











