c_cpp 将不同类型的矩阵转换为opencv矩阵

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 将不同类型的矩阵转换为opencv矩阵相关的知识,希望对你有一定的参考价值。

// From GLM matrix to OpenCV matrix and vicebersa
// Link: https://stackoverflow.com/a/45106875/1407528
void fromCV2GLM(const cv::Mat& cvmat, glm::mat4* glmmat) {
    if (cvmat.cols != 4 || cvmat.rows != 4 || cvmat.type() != CV_32FC1) {
        cout << "Matrix conversion error!" << endl;
        return;
    }
    memcpy(glm::value_ptr(*glmmat), cvmat.data, 16 * sizeof(float));
}

void fromGLM2CV(const glm::mat4& glmmat, cv::Mat* cvmat) {
    if (cvmat->cols != 4 || cvmat->rows != 4) {
        (*cvmat) = cv::Mat(4, 4, CV_32F);
    }
    memcpy(cvmat->data, glm::value_ptr(glmmat), 16 * sizeof(float));
}
// NOTE: These functions are only to convert the data types, but the data 
// structure is not changed. If you have to use the glm matrix in a OpenCV 
// based method, you should transpose the matrix.

以上是关于c_cpp 将不同类型的矩阵转换为opencv矩阵的主要内容,如果未能解决你的问题,请参考以下文章

将openCV矩阵转换为向量

如何使用opencv将图像转换为Python中的矩阵

如何用opencv提取一张图片的像素矩阵

opencv中如何将两个类型为Mat的矩阵合为一个矩阵?

opencv编程中cvMat到Mat如何进行数据转换?

c_cpp 从3channel矩阵opencv中减去矩阵