Size of Matrix OpenCV

后端 未结 5 936
遇见更好的自我
遇见更好的自我 2020-12-07 11:36

I know this might be very rudimentary, but I am new to OpenCV. Could you please tell me how to obtain the size of a matrix in OpenCV?. I googled and I am still searching, bu

5条回答
  •  没有蜡笔的小新
    2020-12-07 12:18

    For 2D matrix:

    mat.rows – Number of rows in a 2D array.

    mat.cols – Number of columns in a 2D array.

    Or: C++: Size Mat::size() const

    The method returns a matrix size: Size(cols, rows) . When the matrix is more than 2-dimensional, the returned size is (-1, -1).

    For multidimensional matrix, you need to use

    int thisSizes[3] = {2, 3, 4};
    cv::Mat mat3D(3, thisSizes, CV_32FC1);
    // mat3D.size tells the size of the matrix 
    // mat3D.size[0] = 2;
    // mat3D.size[1] = 3;
    // mat3D.size[2] = 4;
    

    Note, here 2 for z axis, 3 for y axis, 4 for x axis. By x, y, z, it means the order of the dimensions. x index changes the fastest.

提交回复
热议问题