Skip to content

Commit

Permalink
getCameraProjectioMatrix with gtest
Browse files Browse the repository at this point in the history
  • Loading branch information
kalwalt committed Nov 6, 2023
1 parent 0d74031 commit dce5a2a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions WebARKit/WebARKitManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ std::array<double, 16> WebARKitManager::getTransformationMatrix() {
return transformationMatrix;
}

std::array<double, 16> WebARKitManager::getCameraProjectionMatrix() {
return m_tracker->getCameraProjectionMatrix();
}

bool WebARKitManager::isValid() {
return m_tracker->isValid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ class WebARKitTracker::WebARKitTrackerImpl {
}
}

for (auto i = 0; i < 6; i++) {
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::cameraProjectionMatrix(camData, 0.1, 1000.0, frameWidth, frameHeight, m_cameraProjectionMatrix);
}

void initTracker(uchar* refData, size_t refCols, size_t refRows) {
Expand Down Expand Up @@ -115,6 +117,8 @@ class WebARKitTracker::WebARKitTrackerImpl {

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

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

bool isValid() { return _valid; };

protected:
Expand Down Expand Up @@ -329,7 +333,6 @@ class WebARKitTracker::WebARKitTrackerImpl {
std::vector<cv::Point2f> getSelectedFeaturesWarped(cv::Mat& H) {
std::vector<cv::Point2f> warpedPoints;
perspectiveTransform(_pattern.points2d, warpedPoints, H);
WEBARKIT_LOGi("warpedPoint(0,0): %.2f, %.2f\n", warpedPoints[0].x, warpedPoints[0].y);
return warpedPoints;
}

Expand Down Expand Up @@ -360,6 +363,8 @@ class WebARKitTracker::WebARKitTrackerImpl {
cv::Matx33d m_camMatrix;
cv::Mat m_distortionCoeff;

std::array<double, 16> m_cameraProjectionMatrix;

private:
std::vector<double> output; // 9 from homography matrix, 8 from warped corners*/

Expand Down Expand Up @@ -427,6 +432,10 @@ std::vector<double> WebARKitTracker::getOutputData() { return _trackerImpl->getO

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

std::array<double, 16> WebARKitTracker::getCameraProjectionMatrix() {
return _trackerImpl->getCameraProjectionMatrix();
}

bool WebARKitTracker::isValid() { return _trackerImpl->isValid(); }

} // namespace webarkit
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "WebARKitEnums.h"
#include <WebARKitLog.h>
#include <WebARKitCamera.h>
#include <WebARKitGL.h>
#include <WebARKitPattern.h>
#include <opencv2/xfeatures2d.hpp>

Expand All @@ -29,6 +30,8 @@ class WebARKitTracker {

cv::Mat getPoseMatrix();

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

bool isValid();

private:
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 {

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

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

bool isValid();
};

Expand Down
15 changes: 15 additions & 0 deletions tests/webarkit_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ TEST(WebARKitTest, CheckWebARKitVersion) {
EXPECT_STREQ(manager.getWebARKitVersion().c_str(), "1.0.0");
}

// Check cameraProjectionMatrix from manager
TEST(WebARKitTest, CheckCameraProjectionMatrix) {
// Create a WebARKitManager object
webarkit::WebARKitManager manager;
// Init the manager with the Akaze tracker
manager.initialiseBase(webarkit::TRACKER_TYPE::AKAZE_TRACKER, 640, 480);
// Check if the cameraProjectionMatrix is correct
std::array<double, 16> camProjectionMatrix = manager.getCameraProjectionMatrix();
EXPECT_EQ(camProjectionMatrix[0], -1.7851850084276433);
EXPECT_EQ(camProjectionMatrix[5], 2.3802466779035241);
EXPECT_EQ(camProjectionMatrix[10], -1.0002000200020003);
EXPECT_EQ(camProjectionMatrix[11], -1.0);
EXPECT_EQ(camProjectionMatrix[14], -0.20002000200020004);
}

TEST(WebARKitTest, InitTrackerTest) {
// Create a WebARKitManager object
webarkit::WebARKitManager manager;
Expand Down

0 comments on commit dce5a2a

Please sign in to comment.