Convert a single color with cvtColor

后端 未结 1 1344
抹茶落季
抹茶落季 2020-11-29 10:49

I have a color that I want to convert to a different color space. Is it possible to use cvtColor on a cv::Vec3f directly without creating a 1x1

1条回答
  •  情歌与酒
    2020-11-29 11:00

    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 
    #include 
    
    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_ Mat3f;
    

    0 讨论(0)
提交回复
热议问题