opencv笔记2-图像色彩空间转换

图像色彩空间转换

#include
#include

using namespace std;
using namespace cv;

//图像色彩空间转换
void colorSpace(Mat &image)
{
	Mat gray, hsv;

	//色彩空间转换
	cvtColor(image, hsv, COLOR_BGR2HSV);
	cvtColor(image, gray, COLOR_BGR2GRAY);

	//图片显示
	imshow("HSV", hsv);
	imshow("灰度", gray);

	//图片保存
	imwrite("C:\\Users\\四明\\Pictures\\hsv.jpg", hsv);
	imwrite("C:\\Users\\四明\\Pictures\\gray.jpg", gray);
}


int main()
{
	string path = "C:\\Users\\四明\\Pictures\\QQ图片20200608155343.jpg";
	Mat img = imread(path);
	if (img.empty())
	{
		cout << "加载图片失败" << endl;
		return -1;
	}
	namedWindow("image", WINDOW_FREERATIO);
	imshow("image", img);
	colorSpace(img);
	waitKey(0);
	destroyAllWindows();
	return 0;
}

效果图
opencv笔记2-图像色彩空间转换_第1张图片

你可能感兴趣的:(opencv笔记,笔记,c++,opencv)