一:
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);
}