cv::Mat是OpenCV库中用于处理图像和矩阵的主要数据结构。以下是一些常见的cv::Mat操作方法:
创建和初始化
cv::Mat::Mat(): 创建一个空的cv::Mat对象。cv::Mat::Mat(int rows, int cols, int type): 创建一个指定行数、列数和数据类型的cv::Mat对象。cv::Mat::Mat(int rows, int cols, int type, const Scalar& scalar): 创建一个指定行数、列数、数据类型和填充常量的cv::Mat对象。cv::Mat::fromFile(const String& filename, int type): 从文件中读取图像并创建一个cv::Mat对象。访问和修改元素
cv::Mat::at(int i, int j): 访问指定位置的元素。cv::Mat::at(int i, int j, T& value): 修改指定位置的元素值。cv::Mat::clone(): 克隆cv::Mat对象。矩阵运算
cv::Mat::resize(int new_rows, int new_cols): 调整矩阵大小。cv::Mat::rotate(double angle): 进行顺时针旋转。cv::Mat::transpose(): 求转置矩阵。cv::Mat::inv(): 求逆矩阵。通道和类型操作
cv::Mat::channels(): 获取通道数。cv::Mat::type(): 获取矩阵的数据类型。cv::Mat::convertTo(cv::Mat&dst, int rtype): 转换为其他数据类型的矩阵。文件读写
cv::imread(const String& filename, int flags): 从文件中读取图像并返回cv::Mat对象。cv::imwrite(const String& filename, const cv::Mat& src): 将图像写入文件。并行处理
cv::parallel_for_(const Range& range, const Handler& handler): 并行处理cv::Mat对象的每个元素。显示
cv::imshow(const String& winname, const cv::Mat& mat): 在窗口中显示图像。cv::waitKey(int delay = 0): 等待用户按键或指定延迟时间后窗口自动刷新。