Skip to content

Commit

Permalink
new member methods for WebARKitCamera
Browse files Browse the repository at this point in the history
- getCameraData and getDistortionCoefficients with tests
  • Loading branch information
kalwalt committed Oct 27, 2023
1 parent 2a5c470 commit a1101f0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 8 additions & 0 deletions WebARKit/WebARKitCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ void WebARKitCamera::printSettings() {
printf(" [%.2f %.2f %.2f]\n", cmat[6], cmat[7], cmat[8]);
printf("WebARKit: kc = [%.4f %.4f %.4f %.4f %.4f %.4f]\n", kc[0], kc[1], kc[2], kc[3], kc[4], kc[5]);
};

std::array<double, 9> WebARKitCamera::getCameraData() const {
return cmat;
}

std::array<double, 6> WebARKitCamera::getDistortionCoefficients() const {
return kc;
}
} // namespace webarkit
8 changes: 6 additions & 2 deletions WebARKit/include/WebARKitCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ class WebARKitCamera {
~WebARKitCamera();

bool setupCamera(int width, int height);

void printSettings();

std::array<double, 9> getCameraData() const;

std::array<double, 6> getDistortionCoefficients() const;

private:
int xsize, ysize;
std::array<double, 9> cmat;
std::array<double, 6> kc;

private:
double focal_length;
double diagonal_image_size;
double diagonal_fov_degrees;
Expand Down
20 changes: 20 additions & 0 deletions tests/webarkit_test.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include <WebARKitManager.h>
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitEnums.h>
#include <WebARKitCamera.h>
#include <opencv2/imgcodecs.hpp>

class WebARKitEnumTest : public testing::TestWithParam<std::tuple<webarkit::TRACKER_TYPE, webarkit::ColorSpace>> {};
Expand Down Expand Up @@ -61,6 +62,25 @@ TEST(WebARKitConfigTest, TestBlurSize) {
EXPECT_EQ(expected_blur_size.height, blurSize.height);
}

TEST(WebARKitConfigTest, TestPIConstant) {
double internal_m_pi = 3.14159265358979323846;
EXPECT_EQ(internal_m_pi, m_pi);
}

TEST(WebARKitCameraTest, TestCamera) {
int width = 640;
int height = 480;
webarkit::WebARKitCamera camera;
EXPECT_TRUE(camera.setupCamera(width, height));
std::array<double, 9> camera_mat = camera.getCameraData();
EXPECT_EQ(camera_mat[0], 571.25920269684582);
EXPECT_EQ(camera_mat[2], 320.0);
EXPECT_EQ(camera_mat[4], 571.25920269684582);
EXPECT_EQ(camera_mat[5], 240.0);
EXPECT_EQ(camera_mat[8], 1.0);
camera.printSettings();
}

// Check WebARKitManager initialisation.
TEST(WebARKitTest, InitialiseBaseAkazeTest) {
// Create a WebARKitManager object
Expand Down

0 comments on commit a1101f0

Please sign in to comment.