color_conversion.h
Go to the documentation of this file.
1 /*
2  * This file is part of Laustracker.
3  *
4  * Copyright (C) 2013 Christian Jann <christian.jann@ymail.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 /* Copyright (c) 2011 the authors listed at the following URL, and/or
21  * the authors of referenced articles or incorporated external code:
22  * http://en.literateprograms.org/RGB_to_HSV_color_space_conversion_(C)\
23  * ?action=history&offset=20110802173944
24  *
25  * Permission is hereby granted, free of charge, to any person obtaining
26  * a copy of this software and associated documentation files (the
27  * "Software"), to deal in the Software without restriction, including
28  * without limitation the rights to use, copy, modify, merge, publish,
29  * distribute, sublicense, and/or sell copies of the Software, and to
30  * permit persons to whom the Software is furnished to do so, subject to
31  * the following conditions:
32  *
33  * The above copyright notice and this permission notice shall be
34  * included in all copies or substantial portions of the Software.
35  *
36  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
38  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
39  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
40  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
41  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
42  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43  *
44  * Retrieved from:
45  * http://en.literateprograms.org/RGB_to_HSV_color_space_conversion_(C)?oldid=17206
46  */
47 
48 #ifndef HEADER_LAUSTRACKER_COLOR_CONVERSATION_H_INCLUDED
49 #define HEADER_LAUSTRACKER_COLOR_CONVERSATION_H_INCLUDED
50 
57 #include <stdlib.h>
58 #include <stdio.h>
59 #include <opencv2/core/core.hpp>
60 
61 using namespace cv;
63 #define MIN3(x,y,z) ((y) <= (z) ? \
64  ((x) <= (y) ? (x) : (y)) \
65  : \
66  ((x) <= (z) ? (x) : (z)))
67 #define MAX3(x,y,z) ((y) >= (z) ? \
69  ((x) >= (y) ? (x) : (y)) \
70  : \
71  ((x) >= (z) ? (x) : (z)))
72 
74 struct rgb_color
75 {
77  unsigned char r; /* Channel intensities between 0 and 255 */
78 
80  unsigned char g;
81 
83  unsigned char b;
84 };
85 
87 struct hsv_color
88 {
90  unsigned char hue;
92  unsigned char sat;
94  unsigned char val;
95 };
96 
102 struct hsv_color rgb_to_hsv(struct rgb_color rgb);
103 
104 
117 Scalar bgr_to_cv_hsv(Scalar rgb);
118 
131 Scalar bgr_to_gimp_hsv(Scalar rgb);
132 
133 
145 Scalar bgr_to_kcc_hsv(Scalar rgb);
146 
147 #endif
unsigned char sat
Saturation between 0 (gray) and 255.
unsigned char hue
Hue degree between 0 and 255.
Scalar bgr_to_cv_hsv(Scalar rgb)
Convert a color from RGB to HSV.
Contains a HSV color.
unsigned char val
Value between 0 (black) and 255.
Scalar bgr_to_kcc_hsv(Scalar rgb)
Convert a color from RGB to HSV (KColorChooser) HSV colors KColorChooser: H: 0..359 S: 0...
unsigned char r
Value for red.
unsigned char b
Value for blue.
unsigned char g
Value for green.
Contains a RGB color.
Scalar bgr_to_gimp_hsv(Scalar rgb)
Convert a color from RGB to HSV (Gimp)
struct hsv_color rgb_to_hsv(struct rgb_color rgb)
Convert a color from RGB to HSV.