有没有办法将OpenCV Mat_与自定义类一起使用
Is there a way to use OpenCV Mat_ with custom class?
我在OpenCV中有一些算法,我想使用定点值表示来重写它。我在这里找到了定点算术的类:https://github.com/eteran/cpp-utilities。我想知道是否有一些优雅的方法可以将模板类与固定类对象(或任何自定义类)一起使用Mat_ Mat 的内容。当我使用:
cv::Mat_<cv::Vec<Fixed<12, 4>, 3>> num;
我收到以下错误:
Error C2039 'value' : is not a member of 'cv::DataDepth<numeric::Fixed<0x0c,0x04>>' opencv_hog D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp 1134
Error C2065 'value' : undeclared identifier opencv_hog D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp 1134
Error C2039 'fmt' : is not a member of 'cv::DataDepth<numeric::Fixed<0x0c,0x04>>' opencv_hog D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp 1135
Error C2065 'fmt' : undeclared identifier opencv_hog D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp 1135
Error C2056 illegal expression opencv_hog D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp 1135
正如评论中提到的,我需要定义模板专用化:
template<size_t I, size_t F> class cv::DataType<Fixed<I, F>>
{
public:
typedef Fixed<I, F> value_type;
typedef Fixed<I, F> work_type;
typedef Fixed<I, F> channel_type;
enum {
channels = 1,
depth = I + F,
type = CV_MAKETYPE(depth, channels)
};
};
到目前为止,它似乎工作正常。例如,我可以写:
cv::Mat_<Fixed<13, 3>> fixed = cv::Mat_<Fixed<13, 3>>::zeros(10, 10);
fixed(1, 1) = 2.4;
std::cout << fixed(0, 0) << std::endl;
std::cout << fixed(1, 1) << std::endl;
这将输出:
0.0
2.375
相关文章:
- 将 exprtk 与自定义类的对象一起使用
- 如何将自定义记录器与websocketpp一起使用?
- 如何将来自 Boost.Python 的map_indexing_suite与自定义而不是标准对象一起使用?
- 是否可以将 std::basic_ifstream 和 std::basic_ofstream 与自定义缓冲区一起使用?
- gtest 期望无序元素与自定义比较器/匹配器一起使用
- 如何将unordered_set与自定义结构一起使用?
- 如何在 C++11 中将 std::max 与自定义比较器一起使用?
- 如何将 std::num_put 与自定义迭代器一起使用?
- 将 OpenGL VBO 与自定义类/数据结构一起使用
- 与自定义命名空间一起使用时实现 std::error_category、名称解析问题
- 如何将重新绑定与自定义分配器和自定义列表一起使用
- 设置要与无序集合一起使用的自定义类 - 在集合中找不到元素
- 将 boost odeint 与 std::map 和自定义向量空间代数一起使用时,没有可行的重载'='
- shared_ptr自定义分配器与自定义删除器一起
- 创建自定义迭代器结构以与CSTDIO一起使用
- 将CloudViewer与自定义Pointt类型一起使用
- 将 std::make_unique 与自定义删除器一起使用
- 将 std::find 与自定义 Book 类一起使用
- 将运算符new和运算符delete与自定义内存池/分配器一起使用
- 将 at() 与自定义对象的向量一起使用时的分割错误