Search code examples
c++mat

'cv::Mat::type': non-standard syntax; use '&' to create a pointer to member


I know that there are many same questions in the forum but I can't find the solution and I do not have strong c++ basic.

I have a class as below. When the detector function being called in main(), the error occurs at line Mat output = Mat::zeros(input.rows, input.cols, input.type);.

class CardDetector
{
    string const ORIGINAL = "original";
    string const OUTPUT = "output";
public:
    CardDetector()
    {
        cout << "testing";
    }
    void detect()
    {
        namedWindow(ORIGINAL, WINDOW_AUTOSIZE);
        namedWindow(OUTPUT, WINDOW_AUTOSIZE);
        Mat input = imread("top.jpg", 1);
        Mat output = edgeDetection(input);
        resize(input, input, Size(400, 500));
        imshow(ORIGINAL, input);
        imshow(OUTPUT, output);
        waitKey(0);
    }

private:
    Mat edgeDetection(Mat input) {
        Mat output = Mat::zeros(input.rows, input.cols, input.type);
        return output;
    }
};

int main()
{
    CardDetector detector;
    detector.detect();
    return 0;
}

Solution

  • Happens to all of us. In this line:

    Mat output = Mat::zeros(input.rows, input.cols, input.type);
    

    input.type is a function, so you want:

    Mat output = Mat::zeros(input.rows, input.cols, input.type());
    

    That will return the int you need.

    By the way, I have dabbled in OpenCV, but not very familiar with it. All I know is your code compiles fine making that adjustment.