c – 用户定义类型的OpenCV Matrix

前端之家收集整理的这篇文章主要介绍了c – 用户定义类型的OpenCV Matrix前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法在OpenCV 2.x中有一个用户定义类型的矩阵?就像是 :
cv::Mat_<KalmanRGBPixel> backgroundModel;

我知道cv :: Mat<>是用于图像和数学,但我想以矩阵形式保存数据.我不打算使用逆,转置,乘法等,它只用于存储数据.我希望它是矩阵形式,因为视频的每个帧的pixel_ij将链接到backgroundModel_ij.

我知道有一个DataType< _Tp> core.hpp中的类需要为我的类型定义,但我不知道该怎么做.

编辑:KalmanRGBPixel只是cv :: KalmanFilter类的包装器.至于现在,它是唯一的成员.

... some functions ...
private:
    cv::KalmanFilter kalman;

谢谢你的帮助.

解决方法

在OpenCV文档中,解释了如何向OpenCV矩阵添加自定义类型.您需要定义相应的cv :: DataType.

https://docs.opencv.org/master/d0/d3a/classcv_1_1DataType.html

The DataType class is basically used to provide a description of such primitive data types without adding any fields or methods to the corresponding classes (and it is actually impossible to add anything to primitive C/C++ data types). This technique is known in C++ as class traits. It is not DataType itself that is used but its specialized versions […] The main purpose of this class is to convert compilation-time type information to an OpenCV-compatible data type identifier […]

(是的,最后我在这个帖子中回答了问题!)

猜你在找的C&C++相关文章