MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / rgb2hsv

Function rgb2hsv

jni/venus/color_space.cpp:30–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30cv::Vec3f rgb2hsv(const cv::Vec3f& rgb)
31{
32 float min, max;
33 minmax(min, max, rgb[0], rgb[1], rgb[2]);
34
35 float h, s, v = max;
36 float delta = max - min;
37 if(delta > 0.0001f)
38 {
39 s = delta / max;
40
41 if(rgb[0] == max)
42 {
43 h = (rgb[1] - rgb[2]) / delta;
44 if(h < 0.0f)
45 h += 6.0f;
46 }
47 else if(rgb[1] == max)
48 {
49 h = 2.0f + (rgb[2] - rgb[0]) / delta;
50 }
51 else
52 {
53 h = 4.0f + (rgb[0] - rgb[1]) / delta;
54 }
55
56 h /= 6;
57 }
58 else
59 {
60 s = 0.0f;
61 h = 0.0f;
62 }
63
64 return cv::Vec3f(h, s, v);
65}
66
67cv::Vec3f hsv2rgb(const cv::Vec3f& hsv)
68{

Callers

nothing calls this directly

Calls 1

minmaxFunction · 0.85

Tested by

no test coverage detected