From dce5a2a612b9aa884ca6b4474c22355f88b799f9 Mon Sep 17 00:00:00 2001 From: kalwalt Date: Mon, 6 Nov 2023 18:57:14 +0100 Subject: [PATCH] getCameraProjectioMatrix with gtest --- WebARKit/WebARKitManager.cpp | 4 ++++ .../WebARKitOpticalTracking/WebARKitTracker.cpp | 13 +++++++++++-- .../WebARKitOpticalTracking/WebARKitTracker.h | 3 +++ WebARKit/include/WebARKitManager.h | 2 ++ tests/webarkit_test.cc | 15 +++++++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/WebARKit/WebARKitManager.cpp b/WebARKit/WebARKitManager.cpp index c081ec9..0cab6dd 100644 --- a/WebARKit/WebARKitManager.cpp +++ b/WebARKit/WebARKitManager.cpp @@ -95,6 +95,10 @@ std::array WebARKitManager::getTransformationMatrix() { return transformationMatrix; } +std::array WebARKitManager::getCameraProjectionMatrix() { + return m_tracker->getCameraProjectionMatrix(); +} + bool WebARKitManager::isValid() { return m_tracker->isValid(); } diff --git a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp index 5e8c41a..8055f77 100644 --- a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp +++ b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp @@ -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(i, j)); } } + + webarkit::cameraProjectionMatrix(camData, 0.1, 1000.0, frameWidth, frameHeight, m_cameraProjectionMatrix); } void initTracker(uchar* refData, size_t refCols, size_t refRows) { @@ -115,6 +117,8 @@ class WebARKitTracker::WebARKitTrackerImpl { cv::Mat getPoseMatrix() { return _patternTrackingInfo.pose3d; }; + std::array getCameraProjectionMatrix() { return m_cameraProjectionMatrix; }; + bool isValid() { return _valid; }; protected: @@ -329,7 +333,6 @@ class WebARKitTracker::WebARKitTrackerImpl { std::vector getSelectedFeaturesWarped(cv::Mat& H) { std::vector warpedPoints; perspectiveTransform(_pattern.points2d, warpedPoints, H); - WEBARKIT_LOGi("warpedPoint(0,0): %.2f, %.2f\n", warpedPoints[0].x, warpedPoints[0].y); return warpedPoints; } @@ -360,6 +363,8 @@ class WebARKitTracker::WebARKitTrackerImpl { cv::Matx33d m_camMatrix; cv::Mat m_distortionCoeff; + std::array m_cameraProjectionMatrix; + private: std::vector output; // 9 from homography matrix, 8 from warped corners*/ @@ -427,6 +432,10 @@ std::vector WebARKitTracker::getOutputData() { return _trackerImpl->getO cv::Mat WebARKitTracker::getPoseMatrix() { return _trackerImpl->getPoseMatrix(); } +std::array WebARKitTracker::getCameraProjectionMatrix() { + return _trackerImpl->getCameraProjectionMatrix(); +} + bool WebARKitTracker::isValid() { return _trackerImpl->isValid(); } } // namespace webarkit \ No newline at end of file diff --git a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.h b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.h index 6379937..47dfacb 100644 --- a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.h +++ b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.h @@ -4,6 +4,7 @@ #include "WebARKitEnums.h" #include #include +#include #include #include @@ -29,6 +30,8 @@ class WebARKitTracker { cv::Mat getPoseMatrix(); + std::array getCameraProjectionMatrix(); + bool isValid(); private: diff --git a/WebARKit/include/WebARKitManager.h b/WebARKit/include/WebARKitManager.h index fafa42c..ee7a130 100644 --- a/WebARKit/include/WebARKitManager.h +++ b/WebARKit/include/WebARKitManager.h @@ -104,6 +104,8 @@ class WebARKitManager { std::array getTransformationMatrix(); + std::array getCameraProjectionMatrix(); + bool isValid(); }; diff --git a/tests/webarkit_test.cc b/tests/webarkit_test.cc index a84718d..2e2fc62 100644 --- a/tests/webarkit_test.cc +++ b/tests/webarkit_test.cc @@ -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 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;