day2 :xml/yaml文件读写及几个函数

一:

FileStorage 类支持xml/yaml文件读写,FileStorage(const string&filename,int flags,const string& encoding)

filename 打开的文件名称.

flags 对文件进行的操作类型标志,常用参数及含义在表 2-8 中给出.

 encoding 编码格式,目前不支持 UTF-16XML 编码 需要使用 8XML 编码.

 

类实现:

void visionagin::YmlOperate(string& str)
{
	FileStorage fwrite(str, FileStorage::WRITE);//写模式打开文件
	Mat temp = Mat::zeros(20, 30, CV_8UC1);
	fwrite.write("mymat", temp);//写入Mat数据
	double num = 13.2;
	fwrite << "num" << num;//存入名为num的double类型 13.2
	string mystr = "opencvlearning";
	fwrite << "str" << mystr;
	fwrite << "num_arr" << "[" <<1<<2<<3<<5 << "]";//存入int类型的数组
	fwrite.release();//关闭文件
	
	FileStorage fread(str, FileStorage::READ);
	if (!fread.isOpened())
	{
		cout << "open failed !" << endl;
	}
	fread["mymat"] >> temp;
	cout << "mymat is :" << temp << endl;
	fread["num"] >> num;
	cout << "num is : " << num << endl;
	fread["str"] >> mystr;
	cout << "mystr is : " << mystr << endl;
	fread.release();




}

二:

颜色空间变换:

三:几个函数:

1:convertTo(...,...,...,):

img1为cv_8u,

img1. convertTo (img32 , CV_32F, 1.0, 1/255); //将 CV 8U 类型转换成 CV_32F(0-1)

limg32. convertTo (img1, CV_ 8U ,255) // CV_32F 类型转换成 CV_8U 类型 

2: split()通道分离,merge()

void visionagin::ChannelOperate(string& str)
{
	Mat mymat=imread(str);
	imshow("source", mymat);
	std::vector<Mat>vin;
	split(mymat, vin);
	imshow("channelb", vin[0]);
	imshow("channelg", vin[1]);
	imshow("channelr", vin[2]);
	vin[0] = 0;
	
	Mat unionmat;
	merge(vin, unionmat);
	imshow("union", unionmat);
	waitKey(0);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值