1

I want to detect a white/grey object in OpenCV and therefore I need to convert #B4BAB8 into a OpenCV HSV value. I tried so many things, but I don know how to calculate the lowerb and upperb of this color.. #B4BAB8 is the color of the object.

What values should I use in cv::inRange(frmHsv, cv::Scalar([WHAT VALUE?]), cv::Scalar([WHAT VALUE?]), rangeRes); ?

 cv::Mat frmHsv;
 cv::cvtColor(blur, frmHsv, CV_BGR2HSV);
 // <<<<< HSV conversion

 // >>>>> Color Thresholding
 // Note: change parameters for different colors
 cv::Mat rangeRes = cv::Mat::zeros(rgbmat.size(), CV_8UC1);
 cv::inRange(frmHsv, cv::Scalar([WHAT VALUE?]), cv::Scalar([WHAT VALUE?]), rangeRes);

enter image description here

Engo
  • 899
  • 3
  • 19
  • 49
  • #B4BAB8 - is for RGB, BGR, HSL, HSV/HSB, CMYK , CIE-LAB may be other color sheme image ? Anyway check http://colorizer.org/ and http://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#cvtcolor it may be useful for you. – Andrey Smorodov Dec 07 '16 at 11:56
  • I don't understand what you mean – Engo Dec 07 '16 at 14:12
  • I mean that hex value B4BAB8 is just a number. It may be R=B4 , G= BA, B=B8 or H=B4, S=BA, V=B8 or L=B4, a=BA, B=BA, or any other color space components, or even very HDR gray value. No such color space as "Hexadecimal" it just general number representation form. – Andrey Smorodov Dec 07 '16 at 14:17
  • #b4bab8 color RGB value is (180,186,184). – Engo Dec 07 '16 at 14:19
  • I need to convert this into a lowerb and upperb in order to detect my object. How can I do this using OpenCV? – Engo Dec 07 '16 at 14:19
  • upperb=Scalar(181,187,185), lowerb=Scalar(179,185,183) ? But it strongly depends on context. It will change with lighting, noise, other factors. To make it well you need collect some statistics or train classifier. – Andrey Smorodov Dec 07 '16 at 14:21
  • Possible duplicate of [Convert a single color with cvtColor](http://stackoverflow.com/questions/35737032/convert-a-single-color-with-cvtcolor) – Dan Mašek Dec 07 '16 at 15:09

1 Answers1

1

I ran into this when I was working with color spaces in OpenCV. As @Andrey Smorodov mentioned in the comment, the value #b4bab8 is a hex and can be interpreted in any color space. If you have the RGB value as you mention 180,186,184, follow this for the conversion OpenCV uses when using Imgproc.cvtcolor(). The conversion is different from ones on this and hence this would work for RGB to BGR but not for BGR2HSV. Also, make sure the conversion which you make corresponds to the correct Type of your Matrix.

For example, for a matrix of type CV_32FC3, RGB (245,172,127) would be LUV(2.55*76.3, 255*(134+53.3)/358.0, 255 * (39.5 +140) / 262.0). You can simply make an empty "RGB" image with color (180,186,184) of whatever type you want and use cvtcolor to change BGR2HSV (Note: OpenCV loads all RGB images as BGR) and check what the value in HSV color space is. Let me know if it helps!

Rick M.
  • 3,045
  • 1
  • 21
  • 39