Skip to content

Commit

Permalink
sphere is displayed but don't move
Browse files Browse the repository at this point in the history
- new getGLViewMatrix function
  • Loading branch information
kalwalt committed Nov 18, 2023
1 parent 8cc8572 commit a68af51
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
4 changes: 4 additions & 0 deletions WebARKit/WebARKitManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ cv::Mat WebARKitManager::getPoseMatrix() {
return m_tracker->getPoseMatrix();
}

cv::Mat WebARKitManager::getGLViewMatrix() {
return m_tracker->getGLViewMatrix();
}

std::array<double, 16> WebARKitManager::getTransformationMatrix() {
std::array<double, 16> transformationMatrix;
webarkit::arglCameraViewRHf(m_tracker->getPoseMatrix(), transformationMatrix, 1.0f);
Expand Down
11 changes: 6 additions & 5 deletions WebARKit/WebARKitPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ WebARKitPatternTrackingInfo::WebARKitPatternTrackingInfo() {
}

void WebARKitPatternTrackingInfo::computePose(std::vector<cv::Point3f>& treeDPoints,
std::vector<cv::Point2f>& imgPoints, cv::Mat& caMatrix,
cv::Mat& distCoeffs) {
cv::Mat rvec = cv::Mat::zeros(3, 1, CV_64FC1); // output rotation vector
cv::Mat tvec = cv::Mat::zeros(3, 1, CV_64FC1); // output translation vector
std::vector<cv::Point2f>& imgPoints, const cv::Matx33f& caMatrix,
const cv::Mat& distCoeffs) {
//cv::Mat rvec = cv::Mat::zeros(3, 1, CV_64FC1); // output rotation vector
//cv::Mat tvec = cv::Mat::zeros(3, 1, CV_64FC1); // output translation vector
cv::Mat rvec, tvec;

cv::solvePnPRansac(treeDPoints, imgPoints, caMatrix, distCoeffs, rvec, tvec);

Expand Down Expand Up @@ -50,7 +51,7 @@ void WebARKitPatternTrackingInfo::invertPose() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ class WebARKitTracker::WebARKitTrackerImpl {
}

for (auto i = 0; i < 4; i++) {
for (auto j = 0; j < 1; j++) {
WEBARKIT_LOGi("Distortion coefficients: %.2f\n", m_distortionCoeff.at<double>(i, j));
}
WEBARKIT_LOGi("Distortion coefficients: %.2f\n", m_distortionCoeff.at<double>(i, 0));
}

webarkit::cameraProjectionMatrix(camData, 0.1, 1000.0, frameWidth, frameHeight, m_cameraProjectionMatrix);
Expand Down Expand Up @@ -158,6 +156,8 @@ class WebARKitTracker::WebARKitTrackerImpl {

cv::Mat getPoseMatrix() { return _patternTrackingInfo.pose3d; };

cv::Mat getGLViewMatrix() { return _patternTrackingInfo.glViewMatrix; };

std::array<double, 16> getCameraProjectionMatrix() { return m_cameraProjectionMatrix; };

bool isValid() { return _valid; };
Expand Down Expand Up @@ -278,8 +278,10 @@ class WebARKitTracker::WebARKitTrackerImpl {
fill_output(m_H);

warpedCorners = getSelectedFeaturesWarped(m_H);
auto camM = cv::Mat(m_camMatrix);
_patternTrackingInfo.computePose(_pattern.points3d, warpedCorners, camM, m_distortionCoeff);

_patternTrackingInfo.computePose(_pattern.points3d, warpedCorners, m_camMatrix, m_distortionCoeff);

_patternTrackingInfo.computeGLviewMatrix();

_isDetected = true;
} else {
Expand Down Expand Up @@ -477,6 +479,8 @@ std::vector<double> WebARKitTracker::getOutputData() { return _trackerImpl->getO

cv::Mat WebARKitTracker::getPoseMatrix() { return _trackerImpl->getPoseMatrix(); }

cv::Mat WebARKitTracker::getGLViewMatrix() { return _trackerImpl->getGLViewMatrix(); }

std::array<double, 16> WebARKitTracker::getCameraProjectionMatrix() {
return _trackerImpl->getCameraProjectionMatrix();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class WebARKitTracker {

cv::Mat getPoseMatrix();

cv::Mat getGLViewMatrix();

std::array<double, 16> getCameraProjectionMatrix();

bool isValid();
Expand Down
2 changes: 2 additions & 0 deletions WebARKit/include/WebARKitManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class WebARKitManager {

cv::Mat getPoseMatrix();

cv::Mat getGLViewMatrix();

std::array<double, 16> getTransformationMatrix();

std::array<double, 16> getCameraProjectionMatrix();
Expand Down
4 changes: 2 additions & 2 deletions WebARKit/include/WebARKitPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class WebARKitPatternTrackingInfo {
/**
* Compute pattern pose using PnP algorithm
*/
void computePose(std::vector<cv::Point3f>& treeDPoints, std::vector<cv::Point2f>& imgPoints, cv::Mat& caMatrix,
cv::Mat& distCoeffs);
void computePose(std::vector<cv::Point3f>& treeDPoints, std::vector<cv::Point2f>& imgPoints, const cv::Matx33f& caMatrix,
const cv::Mat& distCoeffs);

void computeGLviewMatrix();

Expand Down

0 comments on commit a68af51

Please sign in to comment.