概述
代码如下:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
// 读入一张图片
Mat img = imread("D:\faceDetection.png",1);
if (img.data == NULL) {
cout << "could not load image..." << endl;
getchar();
return -1;
}
// 创建一个名为 "图片"窗口
namedWindow("图片");
// 在窗口中显示图片
imshow("图片", img);
imwrite("save.jpg", img);
// 等待6000 ms后窗口自动关闭
waitKey(6000);
return 0;
}
Saves an image to a specified file.
将图像保存到指定文件。
The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see cv::imread for the list of extensions). Only 8-bit (or 16-bit unsigned (CV_16U) in case of PNG, JPEG 2000, and TIFF) single-channel or 3-channel (with ‘BGR’ channel order) images can be saved using this function. If the format, depth or channel order is different, use Mat::convertTo , and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O functions to save the image to XML or YAML format.
函数 imwrite 将图像保存到指定文件。 图像格式是根据文件扩展名选择的(有关扩展名列表,请参阅 cv::imread)。 使用此功能只能保存 8 位(或 16 位无符号 (CV_16U),在 PNG、JPEG 2000 和 TIFF 的情况下)单通道或 3 通道(具有“BGR”通道顺序)图像。 如果格式、深度或通道顺序不同,请在保存前使用 Mat::convertTo 和 cv::cvtColor 进行转换。 或者,使用通用 FileStorage I/O 函数将图像保存为 XML 或 YAML 格式。
It is possible to store PNG images with an alpha channel using this function. To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535.
使用此功能可以存储带有 alpha 通道的 PNG 图像。 为此,请创建 8 位(或 16 位)4 通道图像 BGRA,Alpha 通道位于最后。 完全透明像素应将 alpha 设置为 0,完全不透明像素应将 alpha 设置为 255/65535。
The sample below shows how to create such a BGRA image and store to PNG file. It also demonstrates how to set custom compression parameters :
下面的示例显示了如何创建这样的 BGRA 图像并存储为 PNG 文件。 它还演示了如何设置自定义压缩参数:
@include snippets/imgcodecs_imwrite.cpp
@param filename Name of the file.
@param 文件名 文件的名称。
@param img Image to be saved.
@param img 要保存的图像。
@param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags
@param params 格式特定的参数编码为对(paramId_1,paramValue_1,paramId_2,paramValue_2,...)见 cv::ImwriteFlags
CV_EXPORTS_W bool imwrite( const String& filename, InputArray img,const std::vector<int>& params = std::vector<int>());
最后
以上就是合适芒果为你收集整理的openCV学习之路(2-5)---深度解析imwrite函数的全部内容,希望文章能够帮你解决openCV学习之路(2-5)---深度解析imwrite函数所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复