Mat img1 = imread("hello.jpg", 1);
Mat img2(img1.rows, img1.cols, CV_8UC3);
img1(Rect(0, 0, 200, 200)).copyTo(img2);
我正在用C++学习opencv。
但是我不理解img1(Rect())的语法。 根据我的理解,对于函数调用,它应该像img1.rect()。
用()表示对象的任何术语? 这里是img1(xxxxxx);
我不知道opencv,但它看起来像一个operator()
调用。 有些运算符可能是重载的,operator()
就是其中之一:
struct foo {
void operator() {
std::cout << "hello world";
}
};
int main() {
foo f;
f(); // calls operator() and prints "hello world"
}
事实上,如果我们查看opencv文档,我们可以发现:
Mat operator() (const Rect &roi) const
PS:实际上带有operator()
的对象相当常见。 例如,考虑一个lambda:
auto bar = [](){ std::cout << "hello world"; };
bar(); // prints "hello world"
它是一个可调用的对象,具有运算符()
。