sangwoo3 / cvblob

Automatically exported from code.google.com/p/cvblob
GNU Lesser General Public License v3.0
0 stars 0 forks source link

_HSV2RGB_(H, S, V, R, G, B) into cvblob.cpp #12

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. on cvblob.cpp

What is the expected output? What do you see instead?
I have a warning : 
">.\cvBlob\cvblob.cpp(285) : warning C4244: 'initialisation' : conversion de 
'double' en 'int', perte possible de données".
So I add a cast : int _hf = (int)floor(_h);

I think so, you can delete a line, because : 
int _hf = (int)floor(_h);
int _hi = ((int)_h)%6; (delete this line?)
have same result, (to my mind), see http://www.alvyray.com/Papers/hsv2rgb.htm

What version of the product are you using? On what operating system?
v0.10.1

Please provide any additional information below.

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  // Based on http://en.wikipedia.org/wiki/HSL_and_HSV
  // see also http://www.alvyray.com/Papers/hsv2rgb.htm
  // hue: H -> [0, 360] ; saturation: S -> [0, 1] ; value: V -> [0, 1]

  /// \def _HSV2RGB_(H, S, V, R, G, B)
  /// \brief Color translation between HSV and RGB.
#define _HSV2RGB_(H, S, V, R, G, B) \
  { \
    double _h = H/60.; \
    int _hf = (int)floor(_h); \ //I add the cast (int)
    int _hi = ((int)_h)%6; \    //_hi=_hf ... //no need _hi... (delete?)
    double _f = _h - _hf; \
    \
    double _p = V * (1. - S); \
    double _q = V * (1. - _f * S); \        //if _hf is odd
    double _t = V * (1. - (1. - _f) * S); \ //if _hf is even
    \
    switch (_hf) \ //switch (_hi)
    { \
      case 0: \
          R = 255.*V; G = 255.*_t; B = 255.*_p; \
      break; \
      case 1: \
          R = 255.*_q; G = 255.*V; B = 255.*_p; \
      break; \
      case 2: \
          R = 255.*_p; G = 255.*V; B = 255.*_t; \
      break; \
      case 3: \
          R = 255.*_p; G = 255.*_q; B = 255.*V; \
      break; \
      case 4: \
          R = 255.*_t; G = 255.*_p; B = 255.*V; \
      break; \
      case 5: \
          R = 255.*V; G = 255.*_p; B = 255.*_q; \
      break; \
    } \
  }
  ///////////////////////////////////////////////////////////////////////////////////////////////////

Original issue reported on code.google.com by mathias....@gmail.com on 12 Jul 2010 at 9:52

GoogleCodeExporter commented 8 years ago
Hi mathias.ferraton,

I've added the "int" casting to the repository but I don't have deleted the 
line of the module. I prefer to leave that line because it allows more freedom 
in the input. In other case I think "H" is restricted to [0, 360] (correct me 
if I'm wrong). Although I do not need this feature now :-S

Thank you very much Mathias for your help!

Original comment by grendel....@gmail.com on 14 Jul 2010 at 8:58