Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7cffc831 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

CameraService: Add unit tests for DistortionMapper

- Make cameraserver_test test module reachable by build system
- Fix minor compilation error in CameraProviderManagerTest
- Add tests to verify:
  - Initialization of DistortionMapper
  - Transforms with an identity distortion function
  - Round-trip transform ~1e6 points with a large distortion function
  - Raw to corrected transform compared against OpenCV undistortPoints,
    using python to generate the comparison coordinate lists as a C++
    header

Test: atest cameraservice_test
Bug: 79885994
Change-Id: Iae3d6f9de2e6c79dd5cea5ca35ee5100b38441f4
parent 7b8a1fd2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -97,3 +97,8 @@ LOCAL_CFLAGS += -Wall -Wextra -Werror
LOCAL_MODULE:= libcameraservice

include $(BUILD_SHARED_LIBRARY)

# Build tests too

include $(LOCAL_PATH)/tests/Android.mk
+1 −0
Original line number Diff line number Diff line
@@ -195,6 +195,7 @@ status_t DistortionMapper::updateCalibration(const CameraMetadata &result) {
    }

    mValidMapping = true;
    // Need to recalculate grid
    mValidGrids = false;

    return OK;
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES:= $(call all-cpp-files-under, .)

LOCAL_SHARED_LIBRARIES := \
    libbase \
    libcutils \
    libcameraservice \
    libhidlbase \
+1 −0
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ struct TestStatusListener : public CameraProviderManager::StatusListener {
            hardware::camera::common::V1_0::CameraDeviceStatus) override {}
    void onTorchStatusChanged(const String8 &,
            hardware::camera::common::V1_0::TorchModeStatus) override {}
    void onNewProviderRegistered() override {}
};

TEST(CameraProviderManagerTest, InitializeTest) {
+47 −0
Original line number Diff line number Diff line
# Calculates comparison output values for DistortionMapperTest.cpp:CompareToOpenCV
#
# Assumes a python that has numpy and cv2 (OpenCV) available

import numpy as np
import cv2

Fx = 1000
Fy = 1000
Cx = 500
Cy = 500
# s = 0 - not supported by OpenCV

K = np.array([[Fx, 0, Cx],[0, Fy, Cy],[0, 0, 1]])

# Order is k1, k2, t1, t2, k3
dist = np.array([0.1, -0.003, 0.02, 0.01, 0.004])

np.random.seed(1234)

activeArray = np.array([[1000, 750]])

rawCoords = np.floor(np.random.rand(1000,2) * activeArray)

# OpenCV needs either row count or col count = 1 for some reason
rawCoords2 = rawCoords.reshape(-1, 1, 2)

# P is the output camera matrix, K is the input; use the same for both
expCoords = cv2.undistortPoints(rawCoords2, K, dist, P = K)

with open('DistortionMapperTest_OpenCvData.h','w') as f:
  f.write('// Generated by DistortionMapperComp.py\n');
  f.write('// for use by DistortionMapperTest.cpp\n\n');

  f.write('namespace openCvData {\n')
  f.write('std::array<int32_t, %d> rawCoords = {\n' % (rawCoords.shape[0] * rawCoords.shape[1]))
  for i in range(rawCoords.shape[0]):
    f.write('  %d, %d,\n' % (rawCoords[i][0], rawCoords[i][1]))
  f.write('};\n')

  f.write('std::array<int32_t, %d> expCoords = {\n' % (expCoords.shape[0] * expCoords.shape[2]))
  for i in range(expCoords.shape[0]):
    f.write('  %d, %d,\n' % (expCoords[i][0][0], expCoords[i][0][1]))
  f.write('};\n')
  f.write('} // namespace openCvData\n')

print "DistortionMapperTest_OpenCvData.h generated"
Loading