mirror of
https://github.com/opencv/opencv.git
synced 2024-12-14 00:39:13 +08:00
d49958141e
Fixes #22799 Replaces #21559 which was taken as a base Connected PR in contrib: [#3388@contrib](https://github.com/opencv/opencv_contrib/pull/3388) ### Changes OK, now this is more Odometry-related PR than Volume-related. Anyway, * `Volume` class gets wrapped * The same was done for helper classes like `VolumeSettings`, `OdometryFrame` and `OdometrySettings` * `OdometryFrame` constructor signature changed to more convenient where depth goes on 1st place, RGB image on 2nd. This works better for depth-only `Odometry` algorithms. * `OdometryFrame` is checked for amount of pyramid layers inside `Odometry::compute()` * `Odometry` was fully wrapped + more docs added * Added Python tests for `Odometry`, `OdometryFrame` and `Volume` * Added Python sample for `Volume` * Minor fixes including better var names ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
124 lines
4.2 KiB
Python
124 lines
4.2 KiB
Python
import numpy as np
|
|
import cv2 as cv
|
|
|
|
from tests_common import NewOpenCVTests
|
|
|
|
class volume_test(NewOpenCVTests):
|
|
def test_VolumeDefault(self):
|
|
depthPath = 'cv/rgbd/depth.png'
|
|
depth = self.get_sample(depthPath, cv.IMREAD_ANYDEPTH).astype(np.float32)
|
|
if depth.size <= 0:
|
|
raise Exception('Failed to load depth file: %s' % depthPath)
|
|
|
|
Rt = np.eye(4)
|
|
volume = cv.Volume()
|
|
volume.integrate(depth, Rt)
|
|
|
|
size = (480, 640, 4)
|
|
points = np.zeros(size, np.float32)
|
|
normals = np.zeros(size, np.float32)
|
|
|
|
Kraycast = np.array([[525. , 0. , 319.5],
|
|
[ 0. , 525. , 239.5],
|
|
[ 0. , 0. , 1. ]])
|
|
|
|
volume.raycastEx(Rt, size[0], size[1], Kraycast, points, normals)
|
|
|
|
self.assertEqual(points.shape, size)
|
|
self.assertEqual(points.shape, normals.shape)
|
|
|
|
volume.raycast(Rt, points, normals)
|
|
|
|
self.assertEqual(points.shape, size)
|
|
self.assertEqual(points.shape, normals.shape)
|
|
|
|
def test_VolumeTSDF(self):
|
|
depthPath = 'cv/rgbd/depth.png'
|
|
depth = self.get_sample(depthPath, cv.IMREAD_ANYDEPTH).astype(np.float32)
|
|
if depth.size <= 0:
|
|
raise Exception('Failed to load depth file: %s' % depthPath)
|
|
|
|
Rt = np.eye(4)
|
|
|
|
settings = cv.VolumeSettings(cv.VolumeType_TSDF)
|
|
volume = cv.Volume(cv.VolumeType_TSDF, settings)
|
|
volume.integrate(depth, Rt)
|
|
|
|
size = (480, 640, 4)
|
|
points = np.zeros(size, np.float32)
|
|
normals = np.zeros(size, np.float32)
|
|
|
|
Kraycast = settings.getCameraRaycastIntrinsics()
|
|
volume.raycastEx(Rt, size[0], size[1], Kraycast, points, normals)
|
|
|
|
self.assertEqual(points.shape, size)
|
|
self.assertEqual(points.shape, normals.shape)
|
|
|
|
volume.raycast(Rt, points, normals)
|
|
|
|
self.assertEqual(points.shape, size)
|
|
self.assertEqual(points.shape, normals.shape)
|
|
|
|
def test_VolumeHashTSDF(self):
|
|
depthPath = 'cv/rgbd/depth.png'
|
|
depth = self.get_sample(depthPath, cv.IMREAD_ANYDEPTH).astype(np.float32)
|
|
if depth.size <= 0:
|
|
raise Exception('Failed to load depth file: %s' % depthPath)
|
|
|
|
Rt = np.eye(4)
|
|
settings = cv.VolumeSettings(cv.VolumeType_HashTSDF)
|
|
volume = cv.Volume(cv.VolumeType_HashTSDF, settings)
|
|
volume.integrate(depth, Rt)
|
|
|
|
size = (480, 640, 4)
|
|
points = np.zeros(size, np.float32)
|
|
normals = np.zeros(size, np.float32)
|
|
|
|
Kraycast = settings.getCameraRaycastIntrinsics()
|
|
volume.raycastEx(Rt, size[0], size[1], Kraycast, points, normals)
|
|
|
|
self.assertEqual(points.shape, size)
|
|
self.assertEqual(points.shape, normals.shape)
|
|
|
|
volume.raycast(Rt, points, normals)
|
|
|
|
self.assertEqual(points.shape, size)
|
|
self.assertEqual(points.shape, normals.shape)
|
|
|
|
def test_VolumeColorTSDF(self):
|
|
depthPath = 'cv/rgbd/depth.png'
|
|
rgbPath = 'cv/rgbd/rgb.png'
|
|
depth = self.get_sample(depthPath, cv.IMREAD_ANYDEPTH).astype(np.float32)
|
|
rgb = self.get_sample(rgbPath, cv.IMREAD_ANYCOLOR).astype(np.float32)
|
|
|
|
if depth.size <= 0:
|
|
raise Exception('Failed to load depth file: %s' % depthPath)
|
|
if rgb.size <= 0:
|
|
raise Exception('Failed to load RGB file: %s' % rgbPath)
|
|
|
|
Rt = np.eye(4)
|
|
settings = cv.VolumeSettings(cv.VolumeType_ColorTSDF)
|
|
volume = cv.Volume(cv.VolumeType_ColorTSDF, settings)
|
|
volume.integrateColor(depth, rgb, Rt)
|
|
|
|
size = (480, 640, 4)
|
|
points = np.zeros(size, np.float32)
|
|
normals = np.zeros(size, np.float32)
|
|
colors = np.zeros(size, np.float32)
|
|
|
|
Kraycast = settings.getCameraRaycastIntrinsics()
|
|
volume.raycastExColor(Rt, size[0], size[1], Kraycast, points, normals, colors)
|
|
|
|
self.assertEqual(points.shape, size)
|
|
self.assertEqual(points.shape, normals.shape)
|
|
|
|
volume.raycastColor(Rt, points, normals, colors)
|
|
|
|
self.assertEqual(points.shape, size)
|
|
self.assertEqual(points.shape, normals.shape)
|
|
self.assertEqual(points.shape, colors.shape)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
NewOpenCVTests.bootstrap()
|