OpenCV inRange 更改了垫子类型
OpenCV inRange changes Mat type
我无法摆脱OpenCV中的此错误:
OpenCV 错误:输入参数的大小不匹配(操作为 既不是"数组操作数组"(数组具有相同的大小和类型), 也不是"数组操作标量",也不是"标量操作数组")
我Mat.type();
发现我所有的Mat(img)
都有类型 16,但在函数inRange
之后,我的img3
将类型更改为 0。然后我不能使用函数bitwise_and
因为它的类型不同。
如何将其转换为相同类型?
Mat img1 = imread(argv[1], 1);
Mat img2, img3, img4;
cvtColor(img1, img2, CV_BGR2HSV);
GaussianBlur(img2, img2, Size(15,15), 0);
inRange(img2, Scalar(h_min_min,s_min_min,v_min_min), Scalar(h_max_min,s_max_min,v_max_min), img3); // now img3 changed type to 0
bitwise_and(img1, img3, img4); // img1.type()=16, img3.type()=0 ERROR
这是
正常的,因为inRange
返回一个 1 通道掩码(每个像素的值),因此要执行按位运算,只需将掩码转换回 3 通道图像:
cvtColor(img3,img3,CV_GRAY2BGR);
bitwise_and(img1, img3, img4);// now both images are CV_8UC3 (=16)
编辑:正如Berak所说,要更改频道数量,您必须使用cvtColor
,而不是Mat::convertTo
。对此感到抱歉。
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 模板元程序查找相似的连续类型名称
- 是否可以从int转换为enum类类型
- 构造函数正在调用一个使用当前类类型的函数
- 我应该使用什么来代替void作为变体中的替代类型之一
- OpenCV inRange 更改了垫子类型