Skip to content

Commit 8f6091f

Browse files
DuinoDuPICO-XR-Dev
andauthored
fix issue#6 (#7)
* fix issue#6 * skip release in github actions * fix as_se3 bug --------- Co-authored-by: bingwen.ai <[email protected]>
1 parent 9d68380 commit 8f6091f

File tree

4 files changed

+77
-32
lines changed

4 files changed

+77
-32
lines changed

.github/workflows/build_wheels.yml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,29 @@ jobs:
4949
bash scripts/build_ffmpeg.sh
5050
python -m build --wheel
5151
52-
release:
53-
needs: build_wheels
54-
runs-on: ubuntu-latest
55-
steps:
56-
- name: Create release
57-
id: create_release
58-
uses: actions/create-release@v1
59-
env:
60-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
61-
with:
62-
tag_name: ${{ github.ref }}
63-
release_name: Release ${{ github.ref }}
64-
body: |
65-
Changes in this Release
66-
- First release
67-
draft: true
68-
prerelease: false
69-
- name: Upload release asset
70-
uses: actions/upload-release-asset@v1
71-
env:
72-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73-
with:
74-
upload_url: ${{ steps.create_release.outputs.upload_url }}
75-
asset_path: ./dist/spatialmp4-*.whl
76-
asset_name: spatialmp4-*.whl
77-
asset_content_type: application/zip
52+
# release:
53+
# needs: build_wheels
54+
# runs-on: ubuntu-latest
55+
# steps:
56+
# - name: Create release
57+
# id: create_release
58+
# uses: actions/create-release@v1
59+
# env:
60+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
61+
# with:
62+
# tag_name: ${{ github.ref }}
63+
# release_name: Release ${{ github.ref }}
64+
# body: |
65+
# Changes in this Release
66+
# - First release
67+
# draft: true
68+
# prerelease: false
69+
# - name: Upload release asset
70+
# uses: actions/upload-release-asset@v1
71+
# env:
72+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
# with:
74+
# upload_url: ${{ steps.create_release.outputs.upload_url }}
75+
# asset_path: ./dist/spatialmp4-*.whl
76+
# asset_name: spatialmp4-*.whl
77+
# asset_content_type: application/zip

bindings/spatialmp4.cpp

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <pybind11/numpy.h>
2020
#include <pybind11/eigen.h>
2121
#include <opencv2/core/core.hpp>
22+
#include <Eigen/Core>
2223
#include "spatialmp4/reader.h"
2324
#include "spatialmp4/data_types.h"
2425
#include "spatialmp4/utils.h"
@@ -27,6 +28,32 @@
2728

2829
namespace py = pybind11;
2930

31+
namespace {
32+
33+
template <int Rows, int Cols>
34+
Eigen::Matrix<double, Rows, Cols> MatxToEigen(const cv::Matx<double, Rows, Cols> &matx) {
35+
Eigen::Matrix<double, Rows, Cols> result;
36+
for (int r = 0; r < Rows; ++r) {
37+
for (int c = 0; c < Cols; ++c) {
38+
result(r, c) = matx(r, c);
39+
}
40+
}
41+
return result;
42+
}
43+
44+
template <int Rows, int Cols>
45+
cv::Matx<double, Rows, Cols> EigenToMatx(const Eigen::Matrix<double, Rows, Cols> &matrix) {
46+
cv::Matx<double, Rows, Cols> result;
47+
for (int r = 0; r < Rows; ++r) {
48+
for (int c = 0; c < Cols; ++c) {
49+
result(r, c) = matrix(r, c);
50+
}
51+
}
52+
return result;
53+
}
54+
55+
} // namespace
56+
3057
// Helper function to convert cv::Mat to numpy array
3158
py::array_t<uint8_t> mat_to_numpy(const cv::Mat &mat) {
3259
if (mat.empty()) {
@@ -81,7 +108,9 @@ PYBIND11_MODULE(spatialmp4, m) {
81108
.def_readwrite("qx", &SpatialML::pose_frame::qx)
82109
.def_readwrite("qy", &SpatialML::pose_frame::qy)
83110
.def_readwrite("qz", &SpatialML::pose_frame::qz)
84-
.def("as_se3", &SpatialML::pose_frame::as_se3)
111+
.def("as_se3", [](const SpatialML::pose_frame &pose) {
112+
return pose.as_se3().matrix();
113+
})
85114
.def("__repr__", [](const SpatialML::pose_frame &p) {
86115
std::ostringstream ss;
87116
ss << p;
@@ -132,7 +161,9 @@ PYBIND11_MODULE(spatialmp4, m) {
132161
.def_readwrite("fy", &SpatialML::camera_intrinsics::fy)
133162
.def_readwrite("cx", &SpatialML::camera_intrinsics::cx)
134163
.def_readwrite("cy", &SpatialML::camera_intrinsics::cy)
135-
.def("as_cvmat", &SpatialML::camera_intrinsics::as_cvmat)
164+
.def("as_cvmat", [](const SpatialML::camera_intrinsics &intrinsics) {
165+
return MatxToEigen(intrinsics.as_cvmat());
166+
})
136167
.def("__repr__", [](const SpatialML::camera_intrinsics &i) {
137168
std::ostringstream ss;
138169
ss << i;
@@ -142,9 +173,18 @@ PYBIND11_MODULE(spatialmp4, m) {
142173
// Bind camera_extrinsics struct
143174
py::class_<SpatialML::camera_extrinsics>(m, "CameraExtrinsics")
144175
.def(py::init<>())
145-
.def_readwrite("extrinsics", &SpatialML::camera_extrinsics::extrinsics)
146-
.def("as_cvmat", &SpatialML::camera_extrinsics::as_cvmat)
147-
.def("as_se3", &SpatialML::camera_extrinsics::as_se3)
176+
.def_property(
177+
"extrinsics",
178+
[](const SpatialML::camera_extrinsics &extrinsics) { return MatxToEigen(extrinsics.extrinsics); },
179+
[](SpatialML::camera_extrinsics &extrinsics, const Eigen::Matrix4d &matrix) {
180+
extrinsics.extrinsics = EigenToMatx(matrix);
181+
})
182+
.def("as_cvmat", [](const SpatialML::camera_extrinsics &extrinsics) {
183+
return MatxToEigen(extrinsics.as_cvmat());
184+
})
185+
.def("as_se3", [](const SpatialML::camera_extrinsics &extrinsics) {
186+
return extrinsics.as_se3().matrix();
187+
})
148188
.def("__repr__", [](const SpatialML::camera_extrinsics &e) {
149189
std::ostringstream ss;
150190
ss << e;

python/tests/test_reader.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_reader():
3434

3535
# Get pose data
3636
pose = rgb_frame.pose
37+
pose_se3 = pose.as_se3()
3738
print(f"Frame timestamp: {rgb_frame.timestamp}")
3839
print(f"Pose: x={pose.x}, y={pose.y}, z={pose.z}, qw={pose.qw}, qx={pose.qx}, qy={pose.qy}, qz={pose.qz}")
3940

@@ -48,3 +49,7 @@ def test_reader():
4849
# Access depth data (returns numpy array)
4950
depth = depth_frame.depth # Shape: (height, width)
5051
print(f"Depth: {depth.shape}")
52+
53+
54+
def test_bugfix_extrinsics():
55+
print(spatialmp4.Reader('video/test.mp4').get_rgb_extrinsics_left().extrinsics)

src/spatialmp4/reader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ void Reader::ParseDepthFrame(const AVPacket& pkt, depth_frame& frame_depth, bool
791791
Eigen::Vector3d t = T_W_Stof.translation();
792792
Eigen::Quaterniond q = T_W_Stof.unit_quaternion();
793793
frame_depth.pose.x = t.x();
794-
frame_depth.pose.y = t.z();
794+
frame_depth.pose.y = t.y();
795795
frame_depth.pose.z = t.z();
796796
frame_depth.pose.qx = q.x();
797797
frame_depth.pose.qy = q.y();

0 commit comments

Comments
 (0)