2022-02-08 00:16:17 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
import cv2 as cv
|
|
|
|
|
|
|
|
from tests_common import NewOpenCVTests
|
|
|
|
|
|
|
|
class odometry_test(NewOpenCVTests):
|
2022-12-12 14:40:12 +08:00
|
|
|
def commonOdometryTest(self, needRgb, otype, algoType, useFrame):
|
2022-02-08 00:16:17 +08:00
|
|
|
depth = self.get_sample('cv/rgbd/depth.png', cv.IMREAD_ANYDEPTH).astype(np.float32)
|
2022-10-24 21:34:01 +08:00
|
|
|
if needRgb:
|
|
|
|
rgb = self.get_sample('cv/rgbd/rgb.png', cv.IMREAD_ANYCOLOR)
|
2022-02-08 00:16:17 +08:00
|
|
|
radian = np.radians(1)
|
|
|
|
Rt_warp = np.array(
|
|
|
|
[[np.cos(radian), -np.sin(radian), 0],
|
|
|
|
[np.sin(radian), np.cos(radian), 0],
|
|
|
|
[0, 0, 1]], dtype=np.float32
|
|
|
|
)
|
|
|
|
Rt_curr = np.array(
|
|
|
|
[[np.cos(radian), -np.sin(radian), 0, 0],
|
|
|
|
[np.sin(radian), np.cos(radian), 0, 0],
|
|
|
|
[0, 0, 1, 0],
|
|
|
|
[0, 0, 0, 1]], dtype=np.float32
|
|
|
|
)
|
|
|
|
Rt_res = np.zeros((4, 4))
|
|
|
|
|
2022-10-24 21:34:01 +08:00
|
|
|
if otype is not None:
|
2022-12-12 14:40:12 +08:00
|
|
|
settings = cv.OdometrySettings()
|
|
|
|
odometry = cv.Odometry(otype, settings, algoType)
|
2022-10-24 21:34:01 +08:00
|
|
|
else:
|
|
|
|
odometry = cv.Odometry()
|
2022-12-12 14:40:12 +08:00
|
|
|
|
2022-02-08 00:16:17 +08:00
|
|
|
warped_depth = cv.warpPerspective(depth, Rt_warp, (640, 480))
|
2022-10-24 21:34:01 +08:00
|
|
|
if needRgb:
|
|
|
|
warped_rgb = cv.warpPerspective(rgb, Rt_warp, (640, 480))
|
2022-12-12 14:40:12 +08:00
|
|
|
|
|
|
|
if useFrame:
|
|
|
|
if needRgb:
|
|
|
|
srcFrame = cv.OdometryFrame(depth, rgb)
|
|
|
|
dstFrame = cv.OdometryFrame(warped_depth, warped_rgb)
|
|
|
|
else:
|
|
|
|
srcFrame = cv.OdometryFrame(depth)
|
|
|
|
dstFrame = cv.OdometryFrame(warped_depth)
|
|
|
|
odometry.prepareFrames(srcFrame, dstFrame)
|
|
|
|
isCorrect = odometry.compute(srcFrame, dstFrame, Rt_res)
|
2022-10-24 21:34:01 +08:00
|
|
|
else:
|
2022-12-12 14:40:12 +08:00
|
|
|
if needRgb:
|
|
|
|
isCorrect = odometry.compute(depth, rgb, warped_depth, warped_rgb, Rt_res)
|
|
|
|
else:
|
|
|
|
isCorrect = odometry.compute(depth, warped_depth, Rt_res)
|
2022-02-08 00:16:17 +08:00
|
|
|
|
|
|
|
res = np.absolute(Rt_curr - Rt_res).sum()
|
|
|
|
eps = 0.15
|
|
|
|
self.assertLessEqual(res, eps)
|
|
|
|
self.assertTrue(isCorrect)
|
|
|
|
|
2022-10-24 21:34:01 +08:00
|
|
|
def test_OdometryDefault(self):
|
2022-12-12 14:40:12 +08:00
|
|
|
self.commonOdometryTest(False, None, None, False)
|
|
|
|
|
|
|
|
def test_OdometryDefaultFrame(self):
|
|
|
|
self.commonOdometryTest(False, None, None, True)
|
2022-02-08 00:16:17 +08:00
|
|
|
|
2022-10-24 21:34:01 +08:00
|
|
|
def test_OdometryDepth(self):
|
2022-12-12 14:40:12 +08:00
|
|
|
self.commonOdometryTest(False, cv.OdometryType_DEPTH, cv.OdometryAlgoType_COMMON, False)
|
|
|
|
|
|
|
|
def test_OdometryDepthFast(self):
|
|
|
|
self.commonOdometryTest(False, cv.OdometryType_DEPTH, cv.OdometryAlgoType_FAST, False)
|
|
|
|
|
|
|
|
def test_OdometryDepthFrame(self):
|
|
|
|
self.commonOdometryTest(False, cv.OdometryType_DEPTH, cv.OdometryAlgoType_COMMON, True)
|
|
|
|
|
|
|
|
def test_OdometryDepthFastFrame(self):
|
|
|
|
self.commonOdometryTest(False, cv.OdometryType_DEPTH, cv.OdometryAlgoType_FAST, True)
|
2022-02-08 00:16:17 +08:00
|
|
|
|
|
|
|
def test_OdometryRGB(self):
|
2022-12-12 14:40:12 +08:00
|
|
|
self.commonOdometryTest(True, cv.OdometryType_RGB, cv.OdometryAlgoType_COMMON, False)
|
|
|
|
|
|
|
|
def test_OdometryRGBFrame(self):
|
|
|
|
self.commonOdometryTest(True, cv.OdometryType_RGB, cv.OdometryAlgoType_COMMON, True)
|
2022-02-08 00:16:17 +08:00
|
|
|
|
|
|
|
def test_OdometryRGB_Depth(self):
|
2022-12-12 14:40:12 +08:00
|
|
|
self.commonOdometryTest(True, cv.OdometryType_RGB_DEPTH, cv.OdometryAlgoType_COMMON, False)
|
|
|
|
|
|
|
|
def test_OdometryRGB_DepthFrame(self):
|
|
|
|
self.commonOdometryTest(True, cv.OdometryType_RGB_DEPTH, cv.OdometryAlgoType_COMMON, True)
|
2022-02-08 00:16:17 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
NewOpenCVTests.bootstrap()
|