Opencv C++ 声明一个类型为 uint8 的矩阵

Opencv C++ Declaring a matrix of type uint8

本文关键字:类型 uint8 一个 声明 C++ Opencv      更新时间:2023-10-16

相当简单的问题:我想知道如何在opencv中指定矩阵的类型。 我 https://docs.opencv.org/trunk/dc/d84/group__core__basic.html 查看此页面,它为 cv::Mat1f 等的浮点矩阵指定了 typedef。 我不熟悉C++;我可以使用他们在 typedefs 中做的类似事情来制作我自己的 uint8 矩阵吗?

Mat_< uint8 > mymatrix;或类似的东西? 我可以制作自己的类型定义吗?

C++中的标准类型是 uint8_t ,即 Mat_< uint8_t > mymatrix; .你需要#include <cstdint>.

你也可以制作自己的类型定义

typedef Mat_< uint8_t > uint8_matrix_type;

或类似的东西。

您应该使用内置的:

cv::Mat1b

mat.hpp中定义为:

typedef Mat_<uchar> Mat1b;

其中ucharinterface.h中定义:

//! - uchar  - unsigned 1 byte integer
typedef unsigned char uchar;

您也可以typedef具有首选类型的矩阵,但您可能会遇到奇怪的错误,因为它的DataType(traits.hpp(不会被指定,因此它可能与某些OpenCV函数不兼容。