Skip to content

Commit eb6383c

Browse files
aljazkonec1Matevz Morato
andauthored
Feat: Add abstract TransformableBuffer class (#1778)
* Add transformable buffer and use it in ImgDetections * make TransformableBuffer abstratract only and add placeholder in SpatialImgDetections. * Stop out of line virtual definition of Transformalble Buffer. * Add keypoint TODO * Add ImgDetections bindings and test case for transformTo * Adjust test * Implement transformTo in SpatialImgDetections * Add transformTo to Tracklets * Implement transformTo in AprilTags * PointCloudData now inherits from TransformableBuffer * SegmentationMask inherits from TransformableBuffer * Update docstrings * Add clone overload for each message * Enumerate TransformableBuffer and adjust bindings and includes * override TransformableBuffer::getDatatype * bump RVC4 FW * Expose ImgTransformations to AprilTags and properly roundtrip TransformableBuffer datatypes. * Fix import * Fix includes * Bump RVC2 fw * Fix clangformat * Fix MSVC compilation error * clangformat * Fix MSVC * Protobuf field renumbering breaks wire compatibility. * Implement PR suggestions. * Bump FW * Improve error messages for "image like" TransformableBuffer classes * Fix typo in comment * Pivot to Multi inheritance of Buffer and Transformable + add pybind overloads for transformTo * revert ImageAlign addition * Serialize transformable buffer and improve tests * Update bindings and docstrings * Update SegmentationMask docstrings and bindings * SegmentationMask missing bindings * Some Pr suggestions * Clangformat & RVC2 build issues * Bump FW * clangformat * Update transformableBuffer docstrings and add throw statement * Implement suggestions * Bump Fw * MSVC build issues * Bump fw --------- Co-authored-by: Matevz Morato <matevz.morato@gmail.com>
1 parent fd2a406 commit eb6383c

48 files changed

Lines changed: 984 additions & 77 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ set(TARGET_CORE_SOURCES
344344
src/pipeline/node/NeuralAssistedStereo.cpp
345345
src/pipeline/node/Rectification.cpp
346346
src/pipeline/datatype/Buffer.cpp
347+
src/pipeline/datatype/Transformable.cpp
347348
src/pipeline/datatype/ImgFrame.cpp
348349
src/pipeline/datatype/ImgTransformations.cpp
349350
src/pipeline/datatype/Extrinsics.cpp

bindings/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ set(SOURCE_LIST
119119
src/pipeline/datatype/AprilTagConfigBindings.cpp
120120
src/pipeline/datatype/AprilTagsBindings.cpp
121121
src/pipeline/datatype/BufferBindings.cpp
122+
src/pipeline/datatype/TransformableBindings.cpp
122123
src/pipeline/datatype/CameraControlBindings.cpp
123124
src/pipeline/datatype/EdgeDetectorConfigBindings.cpp
124125
src/pipeline/datatype/FeatureTrackerConfigBindings.cpp

bindings/python/src/DatatypeBindings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ void bind_adatatype(pybind11::module& m, void* pCallstack);
77
void bind_apriltagconfig(pybind11::module& m, void* pCallstack);
88
void bind_apriltags(pybind11::module& m, void* pCallstack);
99
void bind_buffer(pybind11::module& m, void* pCallstack);
10+
void bind_transformable(pybind11::module& m, void* pCallstack);
1011
void bind_cameracontrol(pybind11::module& m, void* pCallstack);
1112
void bind_edgedetectorconfig(pybind11::module& m, void* pCallstack);
1213
void bind_featuretrackerconfig(pybind11::module& m, void* pCallstack);
@@ -57,6 +58,7 @@ void DatatypeBindings::addToCallstack(std::deque<StackFunction>& callstack) {
5758
// Bind all datatypes (order matters)
5859
callstack.push_front(bind_adatatype);
5960
callstack.push_front(bind_buffer);
61+
callstack.push_front(bind_transformable);
6062
callstack.push_front(bind_apriltagconfig);
6163
callstack.push_front(bind_apriltags);
6264
callstack.push_front(bind_cameracontrol);
@@ -125,6 +127,7 @@ void DatatypeBindings::bind(pybind11::module& m, void* pCallstack) {
125127

126128
datatypeEnum.value("ADatatype", DatatypeEnum::ADatatype)
127129
.value("Buffer", DatatypeEnum::Buffer)
130+
.value("Transformable", DatatypeEnum::Transformable)
128131
.value("ImgFrame", DatatypeEnum::ImgFrame)
129132
.value("EncodedFrame", DatatypeEnum::EncodedFrame)
130133
.value("NNData", DatatypeEnum::NNData)

bindings/python/src/DatatypeBindings.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#pragma once
22

33
// pybind
4+
#include <type_traits>
5+
46
#include "depthai/pipeline/datatype/ImgAnnotations.hpp"
57
#include "depthai/pipeline/datatype/ImgFrame.hpp"
8+
#include "depthai/pipeline/datatype/Transformable.hpp"
69
#include "pybind11_common.hpp"
710

811
struct DatatypeBindings {
@@ -13,7 +16,7 @@ struct DatatypeBindings {
1316
};
1417

1518
namespace dai {
16-
template <typename T>
19+
template <typename T, typename Enable = void>
1720
// This is used so pybind detects the classes as overridable in python,
1821
// which trigers the holders to keep the python part of the object alive
1922
class Py : public T {
@@ -26,4 +29,14 @@ class Py : public T {
2629
);
2730
}
2831
};
29-
} // namespace dai
32+
33+
template <typename T>
34+
class Py<T, std::enable_if_t<std::is_base_of_v<dai::TransformableBuffer, T>>> : public T {
35+
public:
36+
using T::T;
37+
38+
std::shared_ptr<dai::TransformableBuffer> transformTo(const dai::ImgTransformation& target) const override {
39+
PYBIND11_OVERLOAD(std::shared_ptr<dai::TransformableBuffer>, T, transformTo, target);
40+
}
41+
};
42+
} // namespace dai

bindings/python/src/pipeline/CommonBindings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ void CommonBindings::bind(pybind11::module& m, void* pCallstack) {
222222
spatialKeypointsList.def(py::init<>())
223223
.def(py::init<std::vector<SpatialKeypoint>, std::vector<Edge>>(), py::arg("keypoints"), py::arg("edges"), DOC(dai, KeypointsListT, KeypointsListT))
224224
.def(py::init<std::vector<SpatialKeypoint>>(), py::arg("keypoints"), DOC(dai, KeypointsListT, KeypointsListT))
225+
.def_readwrite("unit", &SpatialKeypointsList::unit, DOC(dai, SpatialKeypointsList, unit))
225226
.def(
226227
"setKeypoints",
227228
[](SpatialKeypointsList& self, const std::vector<SpatialKeypoint>& kps) { self.Base::setKeypoints(kps); },
@@ -248,6 +249,7 @@ void CommonBindings::bind(pybind11::module& m, void* pCallstack) {
248249
.def("setSpatialCoordinates",
249250
&SpatialKeypointsList::setSpatialCoordinates,
250251
py::arg("spatialCoordinates"),
252+
py::arg("spatialUnit") = LengthUnit::MILLIMETER,
251253
DOC(dai, SpatialKeypointsList, setSpatialCoordinates))
252254
.def("getSpatialCoordinates", &SpatialKeypointsList::getSpatialCoordinates, DOC(dai, SpatialKeypointsList, getSpatialCoordinates));
253255

bindings/python/src/pipeline/datatype/AprilTagsBindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void bind_apriltags(pybind11::module& m, void* pCallstack) {
1717
using namespace dai;
1818

1919
py::class_<AprilTag> aprilTag(m, "AprilTag", DOC(dai, AprilTag));
20-
py::class_<AprilTags, Py<AprilTags>, Buffer, std::shared_ptr<AprilTags>> aprilTags(m, "AprilTags", DOC(dai, AprilTags));
20+
py::class_<AprilTags, Py<AprilTags>, Buffer, Transformable, std::shared_ptr<AprilTags>> aprilTags(m, "AprilTags", DOC(dai, AprilTags));
2121

2222
///////////////////////////////////////////////////////////////////////
2323
///////////////////////////////////////////////////////////////////////
@@ -50,6 +50,7 @@ void bind_apriltags(pybind11::module& m, void* pCallstack) {
5050
.def("getTimestamp", &AprilTags::Buffer::getTimestamp, DOC(dai, Buffer, getTimestamp))
5151
.def("getTimestampDevice", &AprilTags::Buffer::getTimestampDevice, DOC(dai, Buffer, getTimestampDevice))
5252
.def("getSequenceNum", &AprilTags::Buffer::getSequenceNum, DOC(dai, Buffer, getSequenceNum))
53+
.def("transformTo", &AprilTags::transformTo, py::arg("target"), DOC(dai, AprilTags, transformTo))
5354
// .def("setTimestamp", &AprilTags::setTimestamp, DOC(dai, Buffer, setTimestamp))
5455
// .def("setTimestampDevice", &AprilTags::setTimestampDevice, DOC(dai, Buffer, setTimestampDevice))
5556
// .def("setSequenceNum", &AprilTags::setSequenceNum, DOC(dai, Buffer, setSequenceNum))

bindings/python/src/pipeline/datatype/ImgDetectionsBindings.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ void bind_imgdetections(pybind11::module& m, void* pCallstack) {
2020
using namespace dai;
2121

2222
// py::class_<RawImgDetections, RawBuffer, std::shared_ptr<RawImgDetections>> rawImgDetections(m, "RawImgDetections", DOC(dai, RawImgDetections));
23-
py::class_<ImgDetections, Py<ImgDetections>, Buffer, std::shared_ptr<ImgDetections>> imgDetections(m, "ImgDetections", DOC(dai, ImgDetections));
23+
py::class_<ImgDetections, Py<ImgDetections>, Buffer, Transformable, std::shared_ptr<ImgDetections>> imgDetections(
24+
m, "ImgDetections", DOC(dai, ImgDetections));
2425
py::class_<ImgDetection> imgDetection(m, "ImgDetection", DOC(dai, ImgDetection));
2526

2627
///////////////////////////////////////////////////////////////////////
@@ -84,7 +85,8 @@ void bind_imgdetections(pybind11::module& m, void* pCallstack) {
8485
.def("getCenterY", &dai::ImgDetection::getCenterY)
8586
.def("getWidth", &dai::ImgDetection::getWidth)
8687
.def("getHeight", &dai::ImgDetection::getHeight)
87-
.def("getAngle", &dai::ImgDetection::getAngle);
88+
.def("getAngle", &dai::ImgDetection::getAngle)
89+
.def("transform", &dai::ImgDetection::transform, py::arg("source"), py::arg("target"), DOC(dai, ImgDetection, transform));
8890

8991
// rawImgDetections
9092
// .def(py::init<>())
@@ -152,6 +154,7 @@ void bind_imgdetections(pybind11::module& m, void* pCallstack) {
152154
py::return_value_policy::reference_internal)
153155
.def("getMaskData", &ImgDetections::getMaskData, DOC(dai, ImgDetectionsT, getMaskData))
154156
.def("getSegmentationMask", &ImgDetections::getSegmentationMask, DOC(dai, ImgDetectionsT, getSegmentationMask))
157+
.def("transformTo", &ImgDetections::transformTo, py::arg("target"), DOC(dai, ImgDetections, transformTo))
155158
#ifdef DEPTHAI_HAVE_OPENCV_SUPPORT
156159
.def("setCvSegmentationMask", &ImgDetections::setCvSegmentationMask, py::arg("mask"), DOC(dai, ImgDetectionsT, setCvSegmentationMask))
157160
.def(

bindings/python/src/pipeline/datatype/PointCloudDataBindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ void bind_pointclouddata(pybind11::module& m, void* pCallstack) {
1717
using namespace dai;
1818

1919
// py::class_<RawPointCloudData, RawBuffer, std::shared_ptr<RawPointCloudData>> rawPointCloudData(m, "RawPointCloudData", DOC(dai, RawPointCloudData));
20-
py::class_<PointCloudData, Py<PointCloudData>, Buffer, std::shared_ptr<PointCloudData>> pointCloudData(m, "PointCloudData", DOC(dai, PointCloudData));
20+
py::class_<PointCloudData, Py<PointCloudData>, Buffer, Transformable, std::shared_ptr<PointCloudData>> pointCloudData(
21+
m, "PointCloudData", DOC(dai, PointCloudData));
2122

2223
///////////////////////////////////////////////////////////////////////
2324
///////////////////////////////////////////////////////////////////////

bindings/python/src/pipeline/datatype/SegmentationMaskBindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ py::array_t<std::uint8_t> toNumpyMask(const dai::SegmentationMask& mask, const s
3939
void bind_segmentationmask(pybind11::module& m, void* pCallstack) {
4040
using namespace dai;
4141

42-
py::class_<SegmentationMask, Py<SegmentationMask>, Buffer, std::shared_ptr<SegmentationMask>> segmentationMask(
42+
py::class_<SegmentationMask, Py<SegmentationMask>, Buffer, Transformable, std::shared_ptr<SegmentationMask>> segmentationMask(
4343
m, "SegmentationMask", DOC(dai, SegmentationMask));
4444

4545
///////////////////////////////////////////////////////////////////////
@@ -112,6 +112,7 @@ void bind_segmentationmask(pybind11::module& m, void* pCallstack) {
112112
py::arg("label"),
113113
DOC(dai, SegmentationMask, getMaskByLabel))
114114
.def("hasValidMask", &SegmentationMask::hasValidMask, DOC(dai, SegmentationMask, hasValidMask))
115+
.def("transformTo", &SegmentationMask::transformTo, py::arg("target"), DOC(dai, SegmentationMask, transformTo))
115116
#ifdef DEPTHAI_HAVE_OPENCV_SUPPORT
116117
.def("setCvMask", &SegmentationMask::setCvMask, py::arg("mask"), DOC(dai, SegmentationMask, setCvMask))
117118
.def(

bindings/python/src/pipeline/datatype/SpatialImgDetectionsBindings.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void bind_spatialimgdetections(pybind11::module& m, void* pCallstack) {
2020
// py::class_<RawSpatialImgDetections, RawBuffer, std::shared_ptr<RawSpatialImgDetections>> rawSpatialImgDetections(m, "RawSpatialImgDetections", DOC(dai,
2121
// RawSpatialImgDetections));
2222
py::class_<SpatialImgDetection> spatialImgDetection(m, "SpatialImgDetection", DOC(dai, SpatialImgDetection));
23-
py::class_<SpatialImgDetections, Py<SpatialImgDetections>, Buffer, std::shared_ptr<SpatialImgDetections>> spatialImgDetections(
23+
py::class_<SpatialImgDetections, Py<SpatialImgDetections>, Buffer, Transformable, std::shared_ptr<SpatialImgDetections>> spatialImgDetections(
2424
m, "SpatialImgDetections", DOC(dai, SpatialImgDetections));
2525

2626
///////////////////////////////////////////////////////////////////////
@@ -121,6 +121,7 @@ void bind_spatialimgdetections(pybind11::module& m, void* pCallstack) {
121121
// Message
122122
spatialImgDetections.def(py::init<>(), DOC(dai, ImgDetectionsT, ImgDetectionsT))
123123
.def("__repr__", &SpatialImgDetections::str)
124+
.def_readwrite("unit", &SpatialImgDetections::unit, DOC(dai, SpatialImgDetections, unit))
124125
.def_property(
125126
"detections",
126127
[](SpatialImgDetections& det) { return &det.detections; },
@@ -142,6 +143,7 @@ void bind_spatialimgdetections(pybind11::module& m, void* pCallstack) {
142143
py::return_value_policy::reference_internal)
143144
.def("getMaskData", &SpatialImgDetections::getMaskData, DOC(dai, ImgDetectionsT, getMaskData))
144145
.def("getSegmentationMask", &SpatialImgDetections::getSegmentationMask, DOC(dai, ImgDetectionsT, getSegmentationMask))
146+
.def("transformTo", &SpatialImgDetections::transformTo, py::arg("target"), DOC(dai, SpatialImgDetections, transformTo))
145147
#ifdef DEPTHAI_HAVE_OPENCV_SUPPORT
146148
.def("setCvSegmentationMask", &SpatialImgDetections::setCvSegmentationMask, py::arg("mask"), DOC(dai, ImgDetectionsT, setCvSegmentationMask))
147149
.def(

0 commit comments

Comments
 (0)