How to fill Matrix with zeros in OpenCV?

前端 未结 8 988
-上瘾入骨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: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(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));
    

提交回复
热议问题