Convert a single color with cvtColor

心不动则不痛 提交于 2019-11-27 02:06:28

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!