openCV学习之路(2-5)---深度解析imwrite函数

代码如下:

#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>());
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

工地码哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值