How to fill Matrix with zeros in OpenCV?

前端 未结 8 995
-上瘾入骨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:16

    How to fill Matrix with zeros in OpenCV?

    To fill a pre-existing Mat object with zeros, you can use Mat::zeros()

    Mat m1 = ...;
    m1 = Mat::zeros(1, 1, CV_64F);
    

    To intialize a Mat so that it contains only zeros, you can pass a scalar with value 0 to the constructor:

    Mat m1 = Mat(1,1, CV_64F, 0.0);
    //                        ^^^^double literal
    

    The reason your version failed is that passing 0 as fourth argument matches the overload taking a void* better than the one taking a scalar.

提交回复
热议问题