opencv::imwrite
时间: 2023-09-09 10:09:21 浏览: 119
`opencv::imwrite` 是 OpenCV 库中的一个函数,用于将图像保存为文件。它的函数原型如下:
```cpp
bool cv::imwrite(const String& filename, InputArray img, const std::vector<int>& params = std::vector<int>())
```
它接受三个参数:
- `filename`:保存图像的文件名。- `img`:要保存的图像。
- `params`:可选参数,用于指定保存图像的格式和压缩选项。
`imwrite` 函数将图像保存到指定的文件,并返回一个布尔值,表示保存是否成功。如果成功保存,返回 `true`;否则返回 `false`。
示例用法:
```cpp
#include <opencv2/opencv.hpp>
int main() {
cv::Mat image = cv::imread("input.jpg"); // 读取图像
if (!image.empty()) {
bool success = cv::imwrite("output.jpg", image); // 保存图像
if (success) {
std::cout << "Image saved successfully!" << std::endl;
} else {
std::cout << "Failed to save image!" << std::endl;
}
} else {
std::cout << "Failed to load image!" << std::endl;
}
return 0;
}
```
以上代码将读取名为 `input.jpg` 的图像,然后将其保存为名为 `output.jpg` 的文件。如果保存成功,将输出 "Image saved successfully!";否则输出 "Failed to save image!"。如果读取图像失败,将输出 "Failed to load image!"。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)