lesson2:图像色彩空间转换
1.知识点
使用cvcolor
对图像色彩空间进行转换,imwrite
保存图像
2.代码实现
quickopencv.h
1 2 3 4 5 6 7 8 9 10
| # 创建一个QuickDemo类 #pragma once #include <opencv2/opencv.hpp>
using namespace cv;
class QuickDemo { public: void colorSpace_Demo(Mat &image); };
|
quickdemo.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream> #include "quickopencv.h"
void QuickDemo::colorSpace_Demo(Mat &image) { Mat gray,hsv; cvtColor(image,hsv,COLOR_BGR2HSV); cvtColor(image,gray,COLOR_BGR2GRAY); imshow("hsv",hsv); imshow("gray", gray); imwrite("D:/hsv.png", hsv); imwrite("D:/gray.png", gray); }
|
day02.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <iostream> #include "quickopencv.h"
using namespace std;
int main(int argc, char** argv) { Mat src = imread("C:/Users/csl/Desktop/lena.jpg"); if (src.empty()) { printf("There is not image..\n"); return -1; } namedWindow("输入窗口", WINDOW_FREERATIO); imshow("输入窗口", src); QuickDemo qd; qd.colorSpace_Demo(src); waitKey(0); destroyAllWindows(); return 0; }
|
3.结果展示
结果展示
保存结果