What causes “OpenCV(4.0.1) Error : Assertion failed(m.dims <= 2)”

后端 未结 1 1705
时光说笑
时光说笑 2021-01-24 06:39

What causes this error?

OpenCV: terminate handler is called!The last OpenCV error is : OpenCV(4.0.1) Error : Assertion failed(m.dims <= 2) in cv::F

相关标签:
1条回答
  • 2021-01-24 07:06

    This error is on this line:

    cout << obj << endl;
    

    OpenCV, will only try to output 2D images (maybe 3D is too hard if it has more than 1 channel).

    A possible workaround is:

      int ordo[3] = { 2, 2, 2 };
      cv::Mat obj(2, 2, CV_8UC2, cv::Scalar::all(0));
      std::cout << obj << std::endl;
    

    Which is allowed and prints:

    [  0,   0,   0,   0;
       0,   0,   0,   0]
    

    First 2 numbers is the first "pixel". You can easily access the x,y,z coordinate doing something like:

    // obj.at<cv::Vec2b>(y, x)[z] = uchar value
    obj.at<cv::Vec2b>(1, 0)[0] = 255;
    

    Which will print out:

    [  0,   0,   0,   0;
     255,   0,   0,   0]
    

    Another possibility is to create a self made printing function which takes the matrix and draws it.

    0 讨论(0)
提交回复
热议问题