简体   繁体   English

rectangle() 抛出错误,表示没有匹配的函数调用

[英]rectangle() throwing error that says there is no matching function call

I am testing out an example code where you make a button for a program in OpenCV (using rectangles that you can click and will basically mimic a button) and I am running into an error when trying to call我正在测试一个示例代码,您可以在其中为 OpenCV 中的程序创建一个按钮(使用可以单击的矩形,并且基本上模拟按钮),并且在尝试调用时遇到错误

rectangle(canvas(button), button, Scalar(0,0,255));

I looked at the pop-up functions that show up when I type rectangle() and it says that the proper format is我查看了在输入 rectangle() 时显示的弹出函数,它说正确的格式是

rectangle(<Mat &img>, <Rect rec>, <const Scalar &color>);

How did I call the function incorrectly?我是如何错误地调用函数的? I am new to C++ and OpenCV and any help will be appreciated!我是 C++ 和 OpenCV 的新手,任何帮助将不胜感激!

Here is the example program:下面是示例程序:

#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <tuple>
using namespace cv;
using namespace std;


Mat3b canvas;
string buttonText("Click me!");
string winName = "My cool GUI v0.1";

Rect button;


void callBackFunc(int event, int x, int y, int flags, void* userdata)
{
    if (event == EVENT_LBUTTONDOWN)
    {
        if (button.contains(Point(x, y)))
        {
            cout << "Clicked!" << endl;
            rectangle(canvas(button), button, Scalar(0,0,255)); //Help! This is where I get the "no matching function to call" error
        }
    }
    if (event == EVENT_LBUTTONUP)
    {
        rectangle(canvas, button, Scalar(200, 200, 200));
    }

    imshow(winName, canvas);
    waitKey(1);
}

int main()
{
    // An image
    Mat3b img(300, 300, Vec3b(0, 255, 0));

    // Your button
    button = Rect(0,0,img.cols, 50);

    // The canvas
    canvas = Mat3b(img.rows + button.height, img.cols, Vec3b(0,0,0));

    // Draw the button
    canvas(button) = Vec3b(200,200,200);
    putText(canvas(button), buttonText, Point(button.width*0.35, button.height*0.7), FONT_HERSHEY_PLAIN, 1, Scalar(0,0,0));

    // Draw the image
    img.copyTo(canvas(Rect(0, button.height, img.cols, img.rows)));

    // Setup callback function
    namedWindow(winName);
    setMouseCallback(winName, callBackFunc);

    imshow(winName, canvas);
    waitKey();

    return 0;
}

I expected to get a green image with a button on top that says "Click me!"我希望得到一个绿色图像,顶部有一个按钮,上面写着“点击我!” and when clicked will say "Clicked" but I am getting an error when I call the rectangle() function that says "No matching function for call to 'rectangle'"单击时会显示“已单击”,但是当我调用 rectangle() 函数时出现错误,显示“没有匹配的函数可以调用 'rectangle'”

Please pay attention to the method rectangle.请注意方法矩形。 It accepts the parameter like this.它接受这样的参数。

rectangle(<Mat &img>, <Rect rec>, <const Scalar &color>);

By the way, you are calling like this and canvas method returns Mat3b.顺便说一下,你是这样调用的,canvas 方法返回 Mat3b。

rectangle(canvas(button), button, Scalar(0,0,255));

Regarding the following reference, Mat3b is derived from Mat, hence you can use it by casting or overriding to Mat.关于以下参考,Mat3b 派生自 Mat,因此您可以通过强制转换或覆盖到 Mat 来使用它。

rectangle((Mat)canvas(button), button, Scalar(0,0,255));

https://docs.opencv.org/3.4/dc/d84/group__core__basic.html https://docs.opencv.org/3.4/dc/d84/group__core__basic.html

class   cv::Mat
    n-dimensional dense array class

class   cv::Mat_< _Tp >
    Template matrix class derived from Mat.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM