如何在opencv 2.1中从HSV图像获取单通道值图像?
我是opencv的初学者。我使用opencv v2.1。我已经将RGB图像转换为HSV图像。现在我想单独获得单通道的色相,值和饱和度。我该怎么办?我在这里看到过类似的问题,但没有人回答。请帮助。
I am a beginner in opencv. I am using opencv v2.1. I have converted an RGB image to HSV image. Now I want to obtain single channels Hue, Value and Saturation separately. What should I do? I have seen similar questions here but No-one answered that. Kindly help.
您可以访问与RGB图像相同的方式,第一个通道将用于H,第二通道
You can access the same way you were accessing for RGB image where 1st channel will be for H, 2nd channel for S and 3rd channel for V.
如果你使用的是OpenCV 2.1,你必须使用IplImage,然后,对吧?
如果您的HSV图像是 IplImage * src
。
If you are using OpenCV 2.1, you must be using IplImage then, right?
like if your HSV image is
IplImage *src
.
IplImage* h = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
IplImage* s = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
IplImage* v = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
// Split image onto the color planes
cvSplit( src, h, s, v, NULL );
cvSplit 函数将多通道数组分割成多个单通道。如果我错了,纠正我。
我建议使用OpenCV 2.4。它有像cvMat这样的结构,它们非常容易处理,就像2D数组一样。
cvSplit function splits a multichannel array into several single channels. Correct me if I am wrong. I would recommend using OpenCV 2.4. It has structs like cvMat which are very easy to handle just like 2D arrays.
编辑:
如果您使用Mat,那么您可以轻松地分离频道。
假设你的hsv mat是 Mat img_hsv
。
然后:
EDIT:
If you are using Mat then you can separate the channels out easily.
Let's say your hsv mat is Mat img_hsv
.
Then :
vector<Mat> hsv_planes;
split( img_hsv, hsv_planes );
hsv_planes[0] // H channel
hsv_planes[1] // S channel
hsv_planes[2] // V channel
看看你能不能用这个。