OpenCV--C++色彩空间转换

#include
#include
#include



using namespace std;
using namespace cv;

int main()
{
	Mat img = imread("colors.jpg");
	if (img.empty()) {
		cout << "读取图片失败" << endl;
		return -1;
	}

	Mat gray, HSV, YUV, Lab, img32;
	
	img.convertTo(img32, CV_32F, 1.0 / 255);  //将CV_8U转为CV_32F
	//img.convertTo(img32, CV_8U, 255);//将CV_32F转为CV_8U

	cvtColor(img32, HSV, COLOR_BGR2HSV);  //将RGB转为HSV
	cvtColor(img32, YUV, COLOR_BGR2YUV);  将RGB转为YUV
	cvtColor(img32, Lab, COLOR_BGR2Lab);
	cvtColor(img32, gray, COLOR_BGR2GRAY); //转为灰度图

	imshow("src", img32);
	imshow("hsv", HSV);
	imshow("yuv", YUV);
	imshow("lab", Lab);
	imshow("gray", gray);


	waitKey(0);
	return 0;
}

测试图片:

测试图片:

OpenCV--C++色彩空间转换_第1张图片

转换效果:

你可能感兴趣的:(opencv,c++,计算机视觉)