Skip to content

Commit

Permalink
testing matrix and cameraProjmatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
kalwalt committed Nov 16, 2023
1 parent 47e102f commit 8cc8572
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
36 changes: 29 additions & 7 deletions WebARKit/WebARKitPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include <opencv2/calib3d.hpp>

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;
}

Expand All @@ -16,20 +17,41 @@ void WebARKitPatternTrackingInfo::computePose(std::vector<cv::Point3f>& 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<double>(row, col) = rMat.at<double>(row, col);
}
pose3d.at<double>(row, 3) = tvec.at<double>(row, 0);
}
pose3d.at<double>(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<double>(j, 0) = pose3d.at<double>(j, 0);
invertPose.at<double>(j, 1) = -pose3d.at<double>(j, 1);
invertPose.at<double>(j, 2) = -pose3d.at<double>(j, 2);
invertPose.at<double>(j, 3) = pose3d.at<double>(j, 3) * m_scale * 0.001f * 1.64f;
}

pose3d = invertPose;
//invertPose.at<double>(j, 3) = pose3d.at<double>(j, 3) * m_scale * 0.001f * 1.64f;
invertPose.at<double>(j, 3) = pose3d.at<double>(j, 3);
}*/

cv::Mat cvToGl = cv::Mat::zeros(4, 4, CV_64F);
cvToGl.at<double>(0, 0) = 1.0f;
cvToGl.at<double>(1, 1) = -1.0f; // Invert the y axis
cvToGl.at<double>(2, 2) = -1.0f; // invert the z axis
cvToGl.at<double>(3, 3) = 1.0f;
// viewMatrix = cvToGl * viewMatrix;
pose3d = cvToGl * pose3d;

// pose3d = invertPose;
}
3 changes: 3 additions & 0 deletions WebARKit/include/WebARKitPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WebARKitPatternTrackingInfo {
cv::Mat homography;
std::vector<cv::Point2f> points2d;
cv::Mat pose3d;
cv::Mat glViewMatrix;

void setScale(const float scale) { m_scale = scale; }

Expand All @@ -36,6 +37,8 @@ class WebARKitPatternTrackingInfo {
void computePose(std::vector<cv::Point3f>& treeDPoints, std::vector<cv::Point2f>& imgPoints, cv::Mat& caMatrix,
cv::Mat& distCoeffs);

void computeGLviewMatrix();

private:
float m_scale;
void invertPose();
Expand Down

0 comments on commit 8cc8572

Please sign in to comment.