RGB to HSV 색상변환
- Library/opencv
- 2021. 1. 26.
RGB to HSV 색상변환
<코드>
#define MATH_MIN3(x,y,z) ( (y) <= (z) ? ((x) <= (y) ? (x) : (y)) : ((x) <= (z) ? (x) : (z)) )
#define MATH_MAX3(x,y,z) ( (y) >= (z) ? ((x) >= (y) ? (x) : (y)) : ((x) >= (z) ? (x) : (z)) )
struct hsv_color {
unsigned char h; // Hue: 0 ~ 255 (red:0, gree: 85, blue: 171)
unsigned char s; // Saturation: 0 ~ 255
unsigned char v; // Value: 0 ~ 255
};
hsv_color RGB2HSV(unsigned char r, unsigned char g, unsigned char b)
{
unsigned char rgb_min, rgb_max;
rgb_min = MATH_MIN3(b, g, r);
rgb_max = MATH_MAX3(b, g, r);
hsv_color hsv;
hsv.v = rgb_max;
if (hsv.v == 0) {
hsv.h = hsv.s = 0;
return hsv;
}
hsv.s = 255*(rgb_max - rgb_min)/hsv.v;
if (hsv.s == 0) {
hsv.h = 0;
return hsv;
}
if (rgb_max == r) {
hsv.h = 0 + 43*(g - b)/(rgb_max - rgb_min);
} else if (rgb_max == g) {
hsv.h = 85 + 43*(b - r)/(rgb_max - rgb_min);
} else /* rgb_max == rgb.b */ {
hsv.h = 171 + 43*(r - g)/(rgb_max - rgb_min);
}
return hsv;
}
Reference
블로그1 http://zeal74.tistory.com/1180
WIKI : http://ko.wikipedia.org/wiki/HSV_%EC%83%89_%EA%B3%B5%EA%B0%84
블로그3 : http://darkpgmr.tistory.com/66
'Library > opencv' 카테고리의 다른 글
| C#기반 openCV 2.4.5 사용하기 (0) | 2021.01.26 |
|---|---|
| OpenCV 2.4.4 Setting on Visual Studio 2010 (0) | 2021.01.26 |
| Setting the develop environment (0) | 2021.01.26 |
| How to set up opencv using various versions of the openCV library in Visual Studio (2) | 2021.01.26 |
| [opencv] Mat Depth (0) | 2021.01.26 |