title: HSV image in openCV for color recognition
body: <p>I have the following BGR image (a car's front), I want to recognize its color</p>
  
  <p><a href="https://i.stack.imgur.com/sH3P3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sH3P3.png" alt="enter image description here"></a></p>
  
  <p>I converted it to HSV (I know imshow() doesn't understand the HSV and will print it as BGR)
  <a href="https://i.stack.imgur.com/TvJpj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TvJpj.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/sH3P3.png" rel="nofollow noreferrer">1</a>: 
  Now, I want to get the hue value and know in which range it lies to recognize the color</p>
  
  <ul>
  <li>how to calculate the number or value of hue? </li>
  <li>how to specify ranges? using scalar method gives me bgr ranges</li>
  </ul>
  
  <p>Code</p>
  
  <pre><code>int main()
  {
      Mat image;
      image = imread("carcolor.png", CV_LOAD_IMAGE_COLOR);
  
      if (!image.data)
      {
          cout &lt;&lt; "Could not open or find the image" &lt;&lt; std::endl;
          return -1;
      }
  
      // Create a new matrix to hold the HSV image
      Mat HSV;
  
      // convert RGB image to HSV
      cvtColor(image, HSV, CV_BGR2HSV);
  
      namedWindow("Display window", CV_WINDOW_AUTOSIZE);
      imshow("Display window", image);
  
      namedWindow("Result window", CV_WINDOW_AUTOSIZE);
      imshow("Result window", HSV);
  
  
      vector&lt;Mat&gt; hsv_planes;
      split(HSV, hsv_planes);
      Mat h = hsv_planes[0]; // H channel
      Mat s = hsv_planes[1]; // S channel
      Mat v = hsv_planes[2]; // V channel
  
      namedWindow("hue", CV_WINDOW_AUTOSIZE);
      imshow("hue", h);
      namedWindow("saturation", CV_WINDOW_AUTOSIZE);
      imshow("saturation", s);
      namedWindow("value", CV_WINDOW_AUTOSIZE);
      imshow("value", v);
  
  
  
      //// red color range
      Scalar hsv_l(170, 150, 150);
      Scalar hsv_h(180, 255, 255);
      Mat bw;
      inRange(HSV, hsv_l, hsv_h, bw);
      imshow("Specific Colour", bw);
      ////
  
      // hue value
  
      //define ranges
  
      waitKey(0);
      return 0;
  }
  </code></pre>