// 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.