1

I have to convert a component color from HSV to RGB and viceversa in OpenCV.

For example if I have the vector hsvcomponent = { 30, 80, 100 } I want the same color in RGB

How can I do this in OpenCV? I know that opencv has the cvtColor with CV_BGR2HSV but this function works with images. I want something simpler.

What can I do?

Hadi
  • 5,328
  • 11
  • 46
  • 67
Elvis Dukaj
  • 7,142
  • 12
  • 43
  • 85
  • 3
    http://docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_colorspaces/py_colorspaces.html#how-to-find-hsv-values-to-track – Abid Rahman K Apr 22 '14 at 10:41

2 Answers2

0

There is no implemented function that I know of in OpenCV, but I suggest you should check this out: How to change RGB color to HSV?

Community
  • 1
  • 1
Øystein W.
  • 517
  • 3
  • 16
0

I found a simple solution to my problem:

cv::Vec3b ConvertColor( cv::Vec3b src, int code, int dstCn )
{
    cv::Mat srcMat(1, 1, CV_8UC3 );
    *srcMat.ptr< cv::Vec3b >( 0 ) = src;

    cv::Mat resMat;
    cv::cvtColor( srcMat, resMat, code, dstCn );

    return *resMat.ptr< cv::Vec3b >( 0 );
}
Elvis Dukaj
  • 7,142
  • 12
  • 43
  • 85