代码如下:
int main() //hsv++yuv++rgb show
{
Mat img_h, img_s, img_v, imghsv;
Mat image;
string filepath01 = "E:\\xunleixx11\\pictures\\cio07.jpg"; //原图
string savepath001 = "E:\\xunleixx11\\txtxtxt\\txt525\\save_data001.txt";//路径1
string savepath002 = "E:\\xunleixx11\\txtxtxt\\txt525\\save_data002.txt";//路径2
string savepath003 = "E:\\xunleixx11\\txtxtxt\\txt525\\save_data003.txt";//路径3
image = imread(filepath01);
vector<cv::Mat> hsv_vec;
cvtColor(image, imghsv,COLOR_BGR2HSV);
//输入rgb图像,转换成yuv并分离
Mat imagey(image.rows, image.cols, 1);
Mat imageu(image.rows, image.cols, 1);
Mat imagev(image.rows, image.cols, 1);
Mat imageyuv;
cvtColor(image, imageyuv, COLOR_BGR2YUV);
vector<Mat> mv2;
split(image, (vector<Mat>&)mv2);
imagey = mv2[0].clone();
imageu = mv2[1].clone();
imagev = mv2[2].clone();
ofstream mycout001(savepath001);
mycout001 << imagey << endl;
mycout001.close();
ofstream mycout002(savepath002);
mycout002 << imageu << endl;
mycout002.close();
ofstream mycout003(savepath003);
mycout003 << imagev << endl;
mycout003.close();
for (int i = 0; i < 3; i++)
{
Mat bgr(image.rows, image.cols, CV_8UC3, Scalar(0, 0, 0));
Mat temp(image.rows, image.cols, CV_8UC1);
Mat out[] = { bgr };
int from_to[] = { i, i };
mixChannels(&image, 1, out, 1, from_to, 1);
//分别显示bgr
//imshow("bgr", bgr);
//waitKey();
}
//显示
//imshow("y", imagey);
//waitkey();
//imshow("u", imageu);
//waitkey();
//imshow("y_v", imagev);
//waitkey();
//imshow("h", img_h);
//waitkey();
//imshow("s", img_s);
//waitkey();
//imshow("h_v", img_v);
//waitkey();
system("pause");
return 0;
}
其中的自定义路径分别代表队含义是YUV的矩阵数值:
string filepath01 = “E:\xunleixx11\pictures\cio07.jpg”; //原图
string savepath001 = “E:\xunleixx11\txtxtxt\txt525\save_data001.txt”;//路径1
string savepath002 = “E:\xunleixx11\txtxtxt\txt525\save_data002.txt”;//路径2
string savepath003 = “E:\xunleixx11\txtxtxt\txt525\save_data003.txt”;//路径3
直接用cout打印输出即可。
备注,不能使用printf…fprint…打印,不是%d那几种类型的数据。。
矩阵的输出,特殊的矩阵,CV::Mat的。。。