convertTo()函数中的一个小陷阱,以及type()函数返回值的类型映射表

convertTo()函数中的一个小陷阱,以及type()函数返回值的类型映射表

  1. convertTo只能改变Mat的数据类型,无法改变通道数
cv::Mat img_input = cv::imread(path_input, cv::IMREAD_COLOR);
cout << "before convertTo(), img_guided type is " << img_input.type() << endl;
img_input.convertTo(img_input, CV_32FC1, 1.0 / 255, 0);
cout << "after convertTo(), img_guided type is " << img_input.type() << endl;

输出结果如下:

before convertTo(), img_guided type is 16  //CV8UC3
after convertTo(), img_guided type is 21  //CV32FC3, 而不是CV32FC1

想要改变Mat的通道数,可以利用cvtColor()函数

  1. imshow()也可以显示float类型的Mat矩阵,但是该矩阵的数据范围应在(0.0 ~1.0),像素值>1.0的像素点会显示为白色。

  1. opencv类型映射表:
    如:CV8UC3对应的整型值是16

First blood!

posted @ 2021-02-26 16:28  刘振友  阅读(148)  评论(0)    收藏  举报