OpenCV C++ Mat 类行和列 - 它们是成员变量(和相关问题)吗?
OpenCV C++ Mat class rows and cols - are they member variables (and related questions)?
我对如何在OpenCV的Mat类中实现行和列感到困惑,希望有人可以提供一些澄清。
使用 Mat 类时,行和列后面不能有 ((,即:
cv::Mat imgSomeImage;
imgSomeImage = cv::imread("some_image.png");
// this line works
std::cout << "num rows = " << imgSomeImage.rows << "n";
// this line does not compile, only difference is the () after rows
std::cout << "num rows = " << imgSomeImage.rows() << "n";
熟悉 .NET 后,我起初认为行和列必须是属性,但在阅读本文后:
C++11 是否具有 C# 样式的属性?
似乎C++没有等价物,至少没有添加一个类来模仿 .NET 属性,据我所知,OpenCV 没有这样做。
所以,我认为 Mat 行和 cols 必须是成员变量,并转到 OpenCV 源代码进行确认。
检查mat.hpp:
https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/mat.hpp
第 217 和 218 行:
int cols(int i=-1) const;
int rows(int i=-1) const;
是我不清楚的地方。 我已经看过很多次了:
// declare a member variable with a default value of -1
int cols = -1;
或者这个:
const int SOME_CONSTANT = 123;
如果 cols 应该对外界只读,我会想到这样的事情:
// member variable
private:
int _cols;
// getter
public:
int cols() { return _cols; }
查看矩阵中行和列的用法.cpp:
https://github.com/opencv/opencv/blob/master/modules/core/src/matrix.cpp
例如,第 395 行:
if( d == 2 && rows == _sizes[0] && cols == _sizes[1] )
或第 498 行:
cols = _colRange.size();
还有许多类似的例子,似乎这些确实是成员变量,但我仍然不清楚 217 和 218 行的语法:
int cols(int i=-1) const;
int rows(int i=-1) const;
有人可以澄清这些是否是成员变量以及声明行上的语法方面发生了什么吗?
你正在查看_InputArray
.
如果您查看Mat
,您将在第 2047 行看到rows
和cols
实际上是成员变量:
int rows, cols;
相关文章:
- 为"adjacent"变量赋值时出现问题
- C++理解计算字符变量的问题
- 在通知提升间处理条件变量时未按住锁会导致问题
- C++线程安全:如果只有一个线程可以写入非原子变量,但多个线程从中读取. 会遇到问题吗?
- 将十六进制值设置为用于填充的字符变量时出现问题
- 初学者问题:如何访问此变量?
- 关于仅正确使用二传手和变量的问题
- 为什么在分配给成员变量之前获取unique_ptr的返回是一个问题?
- C++ 多线程中的锁和条件变量问题
- C++grpc的一些变量问题
- 我如何加载多个脚本而没有变量问题
- 未初始化的变量问题C++
- C++和引脚工具 - IF语句非常奇怪的双变量问题
- 如何通过引用捕获异常来解决局部变量问题
- sscanf写入变量问题
- 影子变量问题Qt
- C++ 中的局部变量问题
- 跨平台条件变量问题
- Makefile变量问题,make想要创建"*.o"而不是foo.o bar.o等
- c++变量问题