Question

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?

Was it helpful?

Solution 2

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 );
}

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top