Convert a single color with cvtColor

Your second approach is correct, but you have source and destination of different types in cvtColor, and that causes the error.

Be sure to have both hsv and bgr of the same type, CV_32F here:

#include <opencv2/opencv.hpp>
#include <iostream>

int main()
{
    cv::Mat3f hsv(cv::Vec3f(0.7, 0.7, 0.8));

    std::cout << "HSV: " << hsv << std::endl;

    cv::Mat3f bgr;
    cvtColor(hsv, bgr, CV_HSV2BGR); 

    std::cout << "BGR: " << bgr << std::endl;

    return 0;
}

You can use Mat3f for brevity. It’s just a typedef:

typedef Mat_<Vec3f> Mat3f;

Leave a Comment