'cv::Mat::type':非标准语法;使用 '&' 创建指向成员的指针

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

本文关键字:成员 创建 指针 非标准 cv Mat type 语法 使用      更新时间:2023-10-16

我知道论坛中有很多相同的问题,但我找不到解决方案,而且我没有强大的 c++ 基础知识。

我有一个课程如下。当在main((中调用检测器函数时,错误发生在行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;
}

发生在我们所有人身上。在这一行中:

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

input.type 是一个函数,所以你需要:

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

这将返回您需要的 int。

顺便说一下,我涉足过OpenCV,但不是很熟悉。我所知道的是你的代码编译得很好,可以进行调整。