错误C2664:“简历:Mat::Mat(int,int,int)”:不能将参数1从“cv::Size”转换为“int”

时间:2023-01-19 18:32:21

This is my first attempt at writing openCv C++ code. I am trying to create an image with all pixel values 200, and then draw a line:

这是我第一次尝试写openCv c++代码。我试图创建一个所有像素值为200的图像,然后画一条线:

#include <vector>
#include "opencv2/highgui/highgui.hpp"
#include <opencv\cv.h>
#include <iostream>
#include<conio.h>


using namespace cv;
using namespace std;


int main()

{



    std::vector<char> dataPtr(40000, 200);
    cv::Point p1(0,0);
    cv::Point p2(200, 200);
    cv::Size size(200,200); 
    cv::Mat image(size, CV_8U, dataPtr);
    if (image.empty()) //check whether the image is valid or not 
     {
          cout << "Error : Image cannot be created..!!" << endl;
          system("pause"); //wait for a key press
          return -1;
     }

    cv::line(image, p1, p2, 'r', 5, 8, 0); 

    namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"

    imshow("MyWindow", image); //display the image which is stored in the 'img' in the "MyWindow" window

    waitKey(0); //wait infinite time for a keypress
    destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
    return 0;
}

But this gives the error on the line :

但这给出了直线上的误差:

    cv::Mat image(size, CV_8U, dataPtr);
Error 3   error C2664: 'cv::Mat::Mat(int,int,int)' : cannot convert parameter 1 from 'cv::Size' to 'int'  in 2july.cpp    78

another error is this:

另一个错误是:

1 IntelliSense: no instance of constructor "cv::Mat::Mat" matches the argument list 2july.cpp 78

1智能感知:没有构造函数的实例“简历:Mat::Mat”匹配参数列表2july。cpp 78

It is having some issues with the first parameter 'size'. Why it is saying int, when I have nowhere used int? Why it is so?

它的第一个参数“size”有一些问题。为什么说int,当我没有使用int的时候?为什么它是如此?

1 个解决方案

#1


1  

After looking at the specifications on http://docs.opencv.org/modules/core/doc/basic_structures.html I couldn't find an instance of a constructor for cv::Mat that has cv::Size as its first parameter and has 3 parameters.

在查看了http://docs.opencv.org/modules/core/doc/basic_structures.html的规范之后,我找不到一个cv的构造函数的实例:有cv::Size作为它的第一个参数,并且有3个参数。

I'd change this

我想改变这一切

cv::Mat image(size, CV_8U, dataPtr);

to this

这个

cv::Mat image(size, CV_8U);

#1


1  

After looking at the specifications on http://docs.opencv.org/modules/core/doc/basic_structures.html I couldn't find an instance of a constructor for cv::Mat that has cv::Size as its first parameter and has 3 parameters.

在查看了http://docs.opencv.org/modules/core/doc/basic_structures.html的规范之后,我找不到一个cv的构造函数的实例:有cv::Size作为它的第一个参数,并且有3个参数。

I'd change this

我想改变这一切

cv::Mat image(size, CV_8U, dataPtr);

to this

这个

cv::Mat image(size, CV_8U);