C++ opencv
时间: 2023-06-28 10:03:56 浏览: 71
C++和OpenCV的结合是非常强大的图像处理工具。下面是一个简单的示例,展示如何使用C++和OpenCV来加载图像、进行灰度处理并显示图像。
```c++
#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
// 读取图像
cv::Mat img = cv::imread("lena.jpg", cv::IMREAD_COLOR);
// 转换为灰度图像
cv::Mat grayImg;
cv::cvtColor(img, grayImg, cv::COLOR_BGR2GRAY);
// 显示原始图像和灰度图像
cv::imshow("Original Image", img);
cv::imshow("Gray Image", grayImg);
// 等待按键
cv::waitKey(0);
return 0;
}
```
在这个示例中,我们首先使用`cv::imread()`函数读取图像。然后,通过调用`cv::cvtColor()`函数将图像转换为灰度图像。最后,通过调用`cv::imshow()`函数来显示原始图像和灰度图像。最后,通过调用`cv::waitKey()`函数等待用户按下任意键来退出程序。
这只是一个简单的示例,OpenCV还包含了许多其他的功能,例如特征检测、目标跟踪、图像分割等等。
阅读全文
相关推荐












