-2
    Mat img1 = imread("hello.jpg", 1);
    Mat img2(img1.rows, img1.cols, CV_8UC3);

    img1(Rect(0, 0, 200, 200)).copyTo(img2);

I am learning opencv using c++.

but I don't understand the syntax that img1(Rect()). From my understanding, for function call, it should like img1.rect().

Any terminlogy for a object with ()? here is img1(xxxxxx);

SamLi
  • 105
  • 2
  • 11
  • 1
    It is overloaded function call operator. [`Mat Mat::operator()(const Rect& roi)`](https://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#id6) (I didn't came up with more contents to post as answer...) – MikeCAT Jul 28 '20 at 13:34

1 Answers1

2

I do not know opencv, but that looks like a operator() call. Some operators can be overloaded, and operator() is one of them:

struct foo {
    void operator() {
        std::cout << "hello world";
    }
};

int main() {
    foo f;
    f();     // calls operator() and prints "hello world"
}

And indeed, if we look at opencv documentation we can find:

Mat   operator() (const Rect &roi) const

PS: Actually objects with operator() are rather common. Consider for example a lambda:

auto bar = [](){ std::cout << "hello world"; };
bar();                                           // prints "hello world"

Its a callable, an object with an operator().

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185