OpenCV matrix element type.type() and its access method.at<>()

  1. The member function type() of cv::Mat can obtain the data type of the Mat matrix elements, but the type() function returns an int value, and further table lookup is required to obtain the corresponding data type.

    cv symbol c++ type
    8U unsigned char
    8S char
    16U unsigned short
    16S short
    32s int
    32F float
    64F double

    C(n) indicates the number of channels

    type C1 C2 C3 C4
    CV_8U 0 8 16 24
    CV_8S 1 9 17 25
    CV_16U 2 10 18 26
    CV_16S 3 11 19 27
    CV_32S 4 12 20 28
    CV_32F 5 13 21 29
    CV_64F 6 14 22 30
  2. .at<>() to access elements
    . at<>() needs to know the element type to access.
    Taking the single channel as an example, the data type accepted by the at method is uchar, not CV_8U, that is, img.at<uchar>(2,3)
    taking three-channel CV8SC3 as an example, img.at<cv::Vec<uchar,3>>(行,列), orimg.at<cv::Vec3i>(行,列)

    type of data C1 C2 C3 C4 C6
    CV_8U fly cv::Vec2b cv::Vec3b cv::Vec<uchar,4> cv::Vec<uchar,6>
    CV_8S char cv::Vec<char,2> cv::Vec<char,3> cv::Vec<char,4> cv::Vec<char,6>
    CV_16U ushort cv::Vec<ushort,2> cv::Vec<ushort,3> cv::Vec<ushort,4> cv::Vec<ushort,6>
    CV_16S short cv::Vec2s cv::Vec3s cv::Vec4s cv::Vec<short,6>
    CV_32S int cv::Vec2i cv::Vec3i cv::Vec4i cv::Vec<int,6>
    CV_32F float cv::Vec2f cv::Vec3f cv::Vec4f cv::Vec6f
    CV_64F double cv::Vec2d cv::Vec3d cv::Vec4d cv::Vec6d

Guess you like

Origin blog.csdn.net/qq_41253960/article/details/129984569