OpenCV实现彩色图片的读取,进行RGB通道分离,并转化为HSV通道
代码
#include<opencv2/opencv.hpp>
using namespace cv;
class RGB_Channels
{
private:
Mat RGB_Color_Channels[3];
public:
Mat* Set_RGB_Color_Channels(void)
{
return RGB_Color_Channels;
}
Mat Get_R(void) const
{
return RGB_Color_Channels[2];
}
Mat Get_G(void) const
{
return RGB_Color_Channels[1];
}
Mat Get_B(void) const
{
return RGB_Color_Channels[0];
}
};
class HSV_Channels
{
private:
Mat HSV_Color_Channels[3];
public:
Mat* Set_HSV_Color_Channels(void)
{
return HSV_Color_Channels;
}
Mat Get_V(void) const
{
return HSV_Color_Channels[2];
}
Mat Get_S(void) const
{
return HSV_Color_Channels[1];
}
Mat Get_H(void) const
{
return HSV_Color_Channels[0];
}
};
int main(int argc,char* argv[])
{
Mat image = imread("./test.jpg");
RGB_Channels my_rgb;
split(image,my_rgb.Set_RGB_Color_Channels());
imshow("RGB",image);
imshow("R",my_rgb.Get_R());
imshow("G",my_rgb.Get_G());
imshow("B",my_rgb.Get_B());
Mat image_hsv;
cvtColor(image, image_hsv, COLOR_BGR2HSV_FULL);
HSV_Channels my_hsv;
split(image_hsv,my_hsv.Set_HSV_Color_Channels());
imshow("RGB",image);
imshow("H",my_hsv.Get_H());
imshow("S",my_hsv.Get_S());
imshow("V",my_hsv.Get_V());
waitKey(0);
return 1;
}
运行结果
|