Multi channel Mat display function

后端 未结 1 1001
礼貌的吻别
礼貌的吻别 2021-01-25 21:28

I want to write a short function to display OpenCV Mat matrix type. I\'m closed to finish it. This is my code:

template 
int MATmtxdisp(con         


        
相关标签:
1条回答
  • 2021-01-25 22:15

    What about this?

    cv::Mat myMat(2,3, CV_8UC3, cv::Scalar(1, 2, 3));
    std::cout << myMat << std::endl;
    

    Anyway, your code is much easier if you use cout:

    template <class T>
    int MATmtxdisp(const Mat& mtx)
    {   
        uchar chan = mtx.channels();
        int step = mtx.step();
        T* ptr = (T*)mtx.data;
    
        for(int i = 0; i < mtx.rows; i++)
            for(int k = 0; k < chan; k++)
            {
                for(int l = 0; l < mtx.cols; l++)
                {
                    cout << ptr[ /* calculate here the index */];
                }
                cout << endl;
        }
    }
    
    0 讨论(0)
提交回复
热议问题