Convert a single color with cvtColor

匿名 (未验证) 提交于 2019-12-03 03:08:02

问题:

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 cv::Mat and populating it with that pixel, using cvtColor on the cv::Mat, then getting the only pixel out of the output? I have tried the following, but it doesn't seem to like getting passed a vector.

Any suggestions?

#include   #include   int main(int, char*[]) {     cv::Vec3f hsv;     hsv[0] = .9;     hsv[1] = .8;     hsv[2] = .7;      std::cout 

I also tried this, but get a different error:

#include   #include   int main(int, char*[]) {     cv::Mat_<:vec3f> hsv(cv::Vec3f(0.7, 0.7, 0.8));      std::cout  bgr;      cvtColor(hsv, bgr, CV_HSV2BGR); // OpenCV Error: Assertion failed (!fixedType() || ((Mat*)obj)->type() == mtype) in create      std::cout 

回答1:

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 

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

typedef Mat_ Mat3f; 


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