diff --git a/WebARKit/WebARKitPattern.cpp b/WebARKit/WebARKitPattern.cpp index 0dbc4b3..653718e 100644 --- a/WebARKit/WebARKitPattern.cpp +++ b/WebARKit/WebARKitPattern.cpp @@ -2,7 +2,8 @@ #include WebARKitPatternTrackingInfo::WebARKitPatternTrackingInfo() { - pose3d = cv::Mat::zeros(3, 4, CV_64FC1); + pose3d = cv::Mat::zeros(4, 4, CV_64FC1); + glViewMatrix = cv::Mat::zeros(4, 4, CV_64F); m_scale = 1.0f; } @@ -16,20 +17,41 @@ void WebARKitPatternTrackingInfo::computePose(std::vector& treeDPoi cv::Mat rMat; cv::Rodrigues(rvec, rMat); - cv::hconcat(rMat, tvec, pose3d); + //cv::hconcat(rMat, tvec, pose3d); + + for (unsigned int row = 0; row < 3; ++row) { + for (unsigned int col = 0; col < 3; ++col) { + pose3d.at(row, col) = rMat.at(row, col); + } + pose3d.at(row, 3) = tvec.at(row, 0); + } + pose3d.at(3, 3) = 1.0f; invertPose(); } +void WebARKitPatternTrackingInfo::computeGLviewMatrix() { + cv::transpose(pose3d , glViewMatrix); +} + void WebARKitPatternTrackingInfo::invertPose() { - cv::Mat invertPose(3, 4, CV_64FC1); + /*cv::Mat invertPose(3, 4, CV_64FC1); for (auto j = 0; j < 3; j++) { invertPose.at(j, 0) = pose3d.at(j, 0); invertPose.at(j, 1) = -pose3d.at(j, 1); invertPose.at(j, 2) = -pose3d.at(j, 2); - invertPose.at(j, 3) = pose3d.at(j, 3) * m_scale * 0.001f * 1.64f; - } - - pose3d = invertPose; + //invertPose.at(j, 3) = pose3d.at(j, 3) * m_scale * 0.001f * 1.64f; + invertPose.at(j, 3) = pose3d.at(j, 3); + }*/ + + cv::Mat cvToGl = cv::Mat::zeros(4, 4, CV_64F); + cvToGl.at(0, 0) = 1.0f; + cvToGl.at(1, 1) = -1.0f; // Invert the y axis + cvToGl.at(2, 2) = -1.0f; // invert the z axis + cvToGl.at(3, 3) = 1.0f; + // viewMatrix = cvToGl * viewMatrix; + pose3d = cvToGl * pose3d; + + // pose3d = invertPose; } \ No newline at end of file diff --git a/WebARKit/include/WebARKitPattern.h b/WebARKit/include/WebARKitPattern.h index 47e833f..16a7eed 100644 --- a/WebARKit/include/WebARKitPattern.h +++ b/WebARKit/include/WebARKitPattern.h @@ -25,6 +25,7 @@ class WebARKitPatternTrackingInfo { cv::Mat homography; std::vector points2d; cv::Mat pose3d; + cv::Mat glViewMatrix; void setScale(const float scale) { m_scale = scale; } @@ -36,6 +37,8 @@ class WebARKitPatternTrackingInfo { void computePose(std::vector& treeDPoints, std::vector& imgPoints, cv::Mat& caMatrix, cv::Mat& distCoeffs); + void computeGLviewMatrix(); + private: float m_scale; void invertPose();