<bdo id='z4tOD'></bdo><ul id='z4tOD'></ul>

    1. <legend id='z4tOD'><style id='z4tOD'><dir id='z4tOD'><q id='z4tOD'></q></dir></style></legend>

      <small id='z4tOD'></small><noframes id='z4tOD'>

    2. <tfoot id='z4tOD'></tfoot>
    3. <i id='z4tOD'><tr id='z4tOD'><dt id='z4tOD'><q id='z4tOD'><span id='z4tOD'><b id='z4tOD'><form id='z4tOD'><ins id='z4tOD'></ins><ul id='z4tOD'></ul><sub id='z4tOD'></sub></form><legend id='z4tOD'></legend><bdo id='z4tOD'><pre id='z4tOD'><center id='z4tOD'></center></pre></bdo></b><th id='z4tOD'></th></span></q></dt></tr></i><div id='z4tOD'><tfoot id='z4tOD'></tfoot><dl id='z4tOD'><fieldset id='z4tOD'></fieldset></dl></div>
    4. 如何在 OpenCV 中用零填充矩阵?

      时间:2023-09-18
    5. <tfoot id='OcJnc'></tfoot>
    6. <i id='OcJnc'><tr id='OcJnc'><dt id='OcJnc'><q id='OcJnc'><span id='OcJnc'><b id='OcJnc'><form id='OcJnc'><ins id='OcJnc'></ins><ul id='OcJnc'></ul><sub id='OcJnc'></sub></form><legend id='OcJnc'></legend><bdo id='OcJnc'><pre id='OcJnc'><center id='OcJnc'></center></pre></bdo></b><th id='OcJnc'></th></span></q></dt></tr></i><div id='OcJnc'><tfoot id='OcJnc'></tfoot><dl id='OcJnc'><fieldset id='OcJnc'></fieldset></dl></div>
        <tbody id='OcJnc'></tbody>
          <bdo id='OcJnc'></bdo><ul id='OcJnc'></ul>

              <legend id='OcJnc'><style id='OcJnc'><dir id='OcJnc'><q id='OcJnc'></q></dir></style></legend>

                <small id='OcJnc'></small><noframes id='OcJnc'>

                本文介绍了如何在 OpenCV 中用零填充矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                下面的代码导致异常.为什么?

                The code below causes an exception. Why?

                #include <opencv2/core/core.hpp>
                #include <iostream>
                
                using namespace cv;
                using namespace std;
                
                void main() {
                
                    try {
                        Mat m1 = Mat(1,1, CV_64F, 0);
                        m1.at<double>(0,0) = 0;
                    }
                    catch(cv::Exception &e) {
                        cerr << e.what() << endl;
                    }
                
                }
                

                错误如下:

                OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3
                ) - 1))*4) & 15) == elemSize1()) in unknown function, file %OPENCV_DIR%uildincludeopencv2coremat.hpp, line 537
                

                更新

                如果跟踪这段代码,我看到构造函数行调用了构造函数

                If tracing this code, I see that constructor line calls the constructor

                inline Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step)
                

                为什么?这个原型有 5 个参数,而我提供了 4 个参数.

                Why? This prototype has 5 parameters, while I am providing 4 arguments.

                推荐答案

                因为最后一个参数是可选的,而且数据指针应该指向适当的地方:

                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));
                

                这篇关于如何在 OpenCV 中用零填充矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:从基本矩阵中提取平移和旋转 下一篇:如何在 C++ 中读取不断增长的文本文件?

                相关文章

                最新文章

                    <bdo id='nAmeG'></bdo><ul id='nAmeG'></ul>
                1. <i id='nAmeG'><tr id='nAmeG'><dt id='nAmeG'><q id='nAmeG'><span id='nAmeG'><b id='nAmeG'><form id='nAmeG'><ins id='nAmeG'></ins><ul id='nAmeG'></ul><sub id='nAmeG'></sub></form><legend id='nAmeG'></legend><bdo id='nAmeG'><pre id='nAmeG'><center id='nAmeG'></center></pre></bdo></b><th id='nAmeG'></th></span></q></dt></tr></i><div id='nAmeG'><tfoot id='nAmeG'></tfoot><dl id='nAmeG'><fieldset id='nAmeG'></fieldset></dl></div>
                2. <small id='nAmeG'></small><noframes id='nAmeG'>

                    <legend id='nAmeG'><style id='nAmeG'><dir id='nAmeG'><q id='nAmeG'></q></dir></style></legend>

                    <tfoot id='nAmeG'></tfoot>