[英]Size of Matrix (image) OpenCV
How to get the dimensions of an image (width and height)?如何获取图像的尺寸(宽度和高度)?
I just saw this answer , which shows two methods, and doesn't explicitly state if they are completely equivalent:我刚刚看到了这个答案,它显示了两种方法,并且没有明确说明它们是否完全等效:
cv::Mat mat; int rows = mat.rows; int cols = mat.cols; cv::Size s = mat.size(); rows = s.height; cols = s.width;
Are those two methods completely equivalent in every case?这两种方法在每种情况下都完全等效吗?
What are the differences if there are any?如果有的话,有什么区别?
OpenCV version: 4 OpenCV 版本:4
The two methods are exactly the same.这两种方法完全一样。 I believe these functions exist for convenience since there are several cases where each method is useful.我相信这些函数的存在是为了方便,因为有几种情况下每种方法都有用。
For example, to create a new cv::Mat
of the same size as another, its more convenient to write and easier to read例如,创建一个与另一个相同大小的新cv::Mat
,它更易于编写和阅读
cv::Mat new_mat = cv::Mat(old_mat.size(), old_mat.type())
than比
cv::Mat new_mat = cv::Mat(old_mat.rows, old_mat.cols, old_mat.type()
Also, fewer function calls I believe.此外,我相信更少的函数调用。 And it's more convenient to use and easier to read with fewer function calls使用更方便,更易于阅读,函数调用更少
for(int i=0; i<old_mat.rows; i++)
for(int j=0; l< old_mat.cols; j++)
than比
for(int i=0; i<old_mat.size().width; i++)
for(int j=0; j<old_mat.size().height; j++)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.