How to fill Matrix with zeros in OpenCV?

前端 未结 8 937
-上瘾入骨i
-上瘾入骨i 2020-12-15 03:36

The code below causes an exception. Why?

#include 
#include 

using namespace cv;
using namespace std;

void mai         


        
相关标签:
8条回答
  • 2020-12-15 04:34

    Mat img;

    img=Mat::zeros(size of image,CV_8UC3);

    if you want it to be of an image img1

    img=Mat::zeros(img1.size,CV_8UC3);

    0 讨论(0)
  • 2020-12-15 04:37

    Because the last parameter is optional and also the data pointer should point somewhere appropriate:

    //inline Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step)
    double mydata[1];
    Mat m1 = Mat(1,1, CV_64F, mydata); 
    m1.at<double>(0,0) = 0;
    

    But better do it directly with this template-based constructor:

    //inline Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s)
    Mat m1 = Mat(1,1, CV_64F, cvScalar(0.));
    
    //or even
    Mat m1 = Mat(1,1, CV_64F, double(0));
    
    0 讨论(0)
提交回复
热议问题