Skip to content

Commit

Permalink
Merge branch 'release_2.17.3' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Aug 7, 2022
2 parents 10e9be0 + cc6b377 commit 20ac5f5
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 38 deletions.
3 changes: 3 additions & 0 deletions examples/calibration/calibration_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
print(f'Factory calibration: {json.dumps(device.readFactoryCalibration().eepromToJson(), indent=2)}')
except Exception as ex:
print(f'No factory calibration: {ex}')

print(f'User calibration raw: {json.dumps(device.readCalibrationRaw())}')
print(f'Factory calibration raw: {json.dumps(device.readFactoryCalibrationRaw())}')
2 changes: 1 addition & 1 deletion examples/calibration/calibration_flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
args = parser.parse_args()

# Connect device
with dai.Device() as device:
with dai.Device(dai.OpenVINO.VERSION_2021_4, dai.UsbSpeed.HIGH) as device:

deviceCalib = device.readCalibration()
deviceCalib.eepromToJsonFile(calibBackUpFile)
Expand Down
33 changes: 28 additions & 5 deletions examples/calibration/calibration_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,41 @@
print(f'RGB FOV {calibData.getFov(dai.CameraBoardSocket.RGB)}')

else:
M_rgb, width, height = calibData.getDefaultIntrinsics(dai.CameraBoardSocket.RGB)
print("RGB Camera Default intrinsics...")
print(M_rgb)
print(width)
print(height)

M_rgb = np.array(calibData.getCameraIntrinsics(dai.CameraBoardSocket.RGB, 3840, 2160))
print("RGB Camera resized intrinsics... 3840 x 2160 ")
print(M_rgb)


M_rgb = np.array(calibData.getCameraIntrinsics(dai.CameraBoardSocket.RGB, 4056, 3040 ))
print("RGB Camera resized intrinsics... 4056 x 3040 ")
print(M_rgb)


M_left, width, height = calibData.getDefaultIntrinsics(dai.CameraBoardSocket.LEFT)
print("LEFT Camera Default intrinsics...")
print(M_left)
print(width)
print(height)

M_left = np.array(calibData.getCameraIntrinsics(dai.CameraBoardSocket.LEFT, 1280, 720))
print("LEFT Camera resized intrinsics...")
print("LEFT Camera resized intrinsics... 1280 x 720")
print(M_left)

D_left = np.array(calibData.getDistortionCoefficients(dai.CameraBoardSocket.LEFT))
print("LEFT Distortion Coefficients...")
[print(name+": "+value) for (name, value) in zip(["k1","k2","p1","p2","k3","k4","k5","k6","s1","s2","s3","s4","τx","τy"],[str(data) for data in D_left])]

M_right = np.array(calibData.getCameraIntrinsics(dai.CameraBoardSocket.RIGHT, 1280, 720))
print("RIGHT Camera resized intrinsics...")
print("RIGHT Camera resized intrinsics... 1280 x 720")
print(M_right)

D_left = np.array(calibData.getDistortionCoefficients(dai.CameraBoardSocket.LEFT))
print("LEFT Distortion Coefficients...")
[print(name+": "+value) for (name, value) in zip(["k1","k2","p1","p2","k3","k4","k5","k6","s1","s2","s3","s4","τx","τy"],[str(data) for data in D_left])]

D_right = np.array(calibData.getDistortionCoefficients(dai.CameraBoardSocket.RIGHT))
print("RIGHT Distortion Coefficients...")
[print(name+": "+value) for (name, value) in zip(["k1","k2","p1","p2","k3","k4","k5","k6","s1","s2","s3","s4","τx","τy"],[str(data) for data in D_right])]
Expand Down
6 changes: 3 additions & 3 deletions src/CalibrationHandlerBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ void CalibrationHandlerBindings::bind(pybind11::module& m, void* pCallstack){

.def("getEepromData", &CalibrationHandler::getEepromData, DOC(dai, CalibrationHandler, getEepromData))

.def("getCameraIntrinsics", py::overload_cast<CameraBoardSocket, int, int, Point2f, Point2f>(&CalibrationHandler::getCameraIntrinsics), py::arg("cameraId"), py::arg("resizeWidth") = -1, py::arg("resizeHeight") = -1, py::arg("topLeftPixelId") = Point2f(), py::arg("bottomRightPixelId") = Point2f(), DOC(dai, CalibrationHandler, getCameraIntrinsics))
.def("getCameraIntrinsics", py::overload_cast<CameraBoardSocket, Size2f, Point2f, Point2f>(&CalibrationHandler::getCameraIntrinsics), py::arg("cameraId"), py::arg("destShape"), py::arg("topLeftPixelId") = Point2f(), py::arg("bottomRightPixelId") = Point2f(), DOC(dai, CalibrationHandler, getCameraIntrinsics, 2))
.def("getCameraIntrinsics", py::overload_cast<CameraBoardSocket, std::tuple<int, int>, Point2f, Point2f>(&CalibrationHandler::getCameraIntrinsics), py::arg("cameraId"), py::arg("destShape"), py::arg("topLeftPixelId") = Point2f(), py::arg("bottomRightPixelId") = Point2f(), DOC(dai, CalibrationHandler, getCameraIntrinsics, 3))
.def("getCameraIntrinsics", py::overload_cast<CameraBoardSocket, int, int, Point2f, Point2f, bool>(&CalibrationHandler::getCameraIntrinsics), py::arg("cameraId"), py::arg("resizeWidth") = -1, py::arg("resizeHeight") = -1, py::arg("topLeftPixelId") = Point2f(), py::arg("bottomRightPixelId") = Point2f(), py::arg("keepAspectRatio") = true, DOC(dai, CalibrationHandler, getCameraIntrinsics))
.def("getCameraIntrinsics", py::overload_cast<CameraBoardSocket, Size2f, Point2f, Point2f, bool>(&CalibrationHandler::getCameraIntrinsics), py::arg("cameraId"), py::arg("destShape"), py::arg("topLeftPixelId") = Point2f(), py::arg("bottomRightPixelId") = Point2f(), py::arg("keepAspectRatio") = true, DOC(dai, CalibrationHandler, getCameraIntrinsics, 2))
.def("getCameraIntrinsics", py::overload_cast<CameraBoardSocket, std::tuple<int, int>, Point2f, Point2f, bool>(&CalibrationHandler::getCameraIntrinsics), py::arg("cameraId"), py::arg("destShape"), py::arg("topLeftPixelId") = Point2f(), py::arg("bottomRightPixelId") = Point2f(), py::arg("keepAspectRatio") = true, DOC(dai, CalibrationHandler, getCameraIntrinsics, 3))

.def("getDefaultIntrinsics", &CalibrationHandler::getDefaultIntrinsics, py::arg("cameraId"), DOC(dai, CalibrationHandler, getDefaultIntrinsics))
.def("getDistortionCoefficients", &CalibrationHandler::getDistortionCoefficients, py::arg("cameraId"), DOC(dai, CalibrationHandler, getDistortionCoefficients))
Expand Down
47 changes: 47 additions & 0 deletions src/DatatypeBindings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "DatatypeBindings.hpp"

#include "pipeline/CommonBindings.hpp"
#include "depthai-shared/datatype/DatatypeEnum.hpp"

void bind_adatatype(pybind11::module& m, void* pCallstack);
void bind_apriltagconfig(pybind11::module& m, void* pCallstack);
Expand All @@ -23,6 +24,9 @@ void bind_trackedfeatures(pybind11::module& m, void* pCallstack);
void bind_tracklets(pybind11::module& m, void* pCallstack);

void DatatypeBindings::addToCallstack(std::deque<StackFunction>& callstack) {
// Bind common datatypebindings
callstack.push_front(DatatypeBindings::bind);

// Bind all datatypes (order matters)
callstack.push_front(bind_adatatype);
callstack.push_front(bind_buffer);
Expand All @@ -44,3 +48,46 @@ void DatatypeBindings::addToCallstack(std::deque<StackFunction>& callstack) {
callstack.push_front(bind_trackedfeatures);
callstack.push_front(bind_tracklets);
}

void DatatypeBindings::bind(pybind11::module& m, void* pCallstack){
using namespace dai;

py::enum_<DatatypeEnum> datatypeEnum(m, "DatatypeEnum", DOC(dai, DatatypeEnum));

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Call the rest of the type defines, then perform the actual bindings
Callstack* callstack = (Callstack*) pCallstack;
auto cb = callstack->top();
callstack->pop();
cb(m, pCallstack);
// Actual bindings
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

m.def("isDatatypeSubclassOf", &isDatatypeSubclassOf);

datatypeEnum
.value("Buffer", DatatypeEnum::Buffer)
.value("ImgFrame", DatatypeEnum::ImgFrame)
.value("NNData", DatatypeEnum::NNData)
.value("ImageManipConfig", DatatypeEnum::ImageManipConfig)
.value("CameraControl", DatatypeEnum::CameraControl)
.value("ImgDetections", DatatypeEnum::ImgDetections)
.value("SpatialImgDetections", DatatypeEnum::SpatialImgDetections)
.value("SystemInformation", DatatypeEnum::SystemInformation)
.value("SpatialLocationCalculatorConfig", DatatypeEnum::SpatialLocationCalculatorConfig)
.value("SpatialLocationCalculatorData", DatatypeEnum::SpatialLocationCalculatorData)
.value("EdgeDetectorConfig", DatatypeEnum::EdgeDetectorConfig)
.value("AprilTagConfig", DatatypeEnum::AprilTagConfig)
.value("AprilTags", DatatypeEnum::AprilTags)
.value("Tracklets", DatatypeEnum::Tracklets)
.value("IMUData", DatatypeEnum::IMUData)
.value("StereoDepthConfig", DatatypeEnum::StereoDepthConfig)
.value("FeatureTrackerConfig", DatatypeEnum::FeatureTrackerConfig)
.value("TrackedFeatures", DatatypeEnum::TrackedFeatures)
;

}
2 changes: 2 additions & 0 deletions src/DatatypeBindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

struct DatatypeBindings {
static void addToCallstack(std::deque<StackFunction>& callstack);
private:
static void bind(pybind11::module& m, void* pCallstack);
};
6 changes: 6 additions & 0 deletions src/pipeline/datatype/AprilTagsBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ void bind_apriltags(pybind11::module& m, void* pCallstack){
aprilTags
.def(py::init<>())
.def_property("aprilTags", [](AprilTags& det) { return &det.aprilTags; }, [](AprilTags& det, std::vector<AprilTag> val) { det.aprilTags = val; })
.def("getTimestamp", &AprilTags::getTimestamp, DOC(dai, AprilTags, getTimestamp))
.def("getTimestampDevice", &AprilTags::getTimestampDevice, DOC(dai, AprilTags, getTimestampDevice))
.def("getSequenceNum", &AprilTags::getSequenceNum, DOC(dai, AprilTags, getSequenceNum))
.def("setTimestamp", &AprilTags::setTimestamp, DOC(dai, AprilTags, setTimestamp))
.def("setTimestampDevice", &AprilTags::setTimestampDevice, DOC(dai, AprilTags, setTimestampDevice))
.def("setSequenceNum", &AprilTags::setSequenceNum, DOC(dai, AprilTags, setSequenceNum))
;

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ void bind_spatiallocationcalculatordata(pybind11::module& m, void* pCallstack){
.def(py::init<>())
.def("getSpatialLocations", &SpatialLocationCalculatorData::getSpatialLocations, DOC(dai, SpatialLocationCalculatorData, getSpatialLocations))
.def_property("spatialLocations", [](SpatialLocationCalculatorData& loc) { return &loc.spatialLocations; }, [](SpatialLocationCalculatorData& loc, std::vector<SpatialLocations> val) { loc.spatialLocations = val; }, DOC(dai, SpatialLocationCalculatorData, spatialLocations))

.def("getTimestamp", &SpatialLocationCalculatorData::getTimestamp, DOC(dai, SpatialLocationCalculatorData, getTimestamp))
.def("getTimestampDevice", &SpatialLocationCalculatorData::getTimestampDevice, DOC(dai, SpatialLocationCalculatorData, getTimestampDevice))
.def("getSequenceNum", &SpatialLocationCalculatorData::getSequenceNum, DOC(dai, SpatialLocationCalculatorData, getSequenceNum))
.def("setTimestamp", &SpatialLocationCalculatorData::setTimestamp, DOC(dai, SpatialLocationCalculatorData, setTimestamp))
.def("setTimestampDevice", &SpatialLocationCalculatorData::setTimestampDevice, DOC(dai, SpatialLocationCalculatorData, setTimestampDevice))
.def("setSequenceNum", &SpatialLocationCalculatorData::setSequenceNum, DOC(dai, SpatialLocationCalculatorData, setSequenceNum))
;


Expand Down
6 changes: 6 additions & 0 deletions src/pipeline/datatype/TrackedFeaturesBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ void bind_trackedfeatures(pybind11::module& m, void* pCallstack){
trackedFeatures
.def(py::init<>())
.def_property("trackedFeatures", [](TrackedFeatures& feat) { return &feat.trackedFeatures; }, [](TrackedFeatures& feat, std::vector<TrackedFeature> val) { feat.trackedFeatures = val; }, DOC(dai, TrackedFeatures, trackedFeatures))
.def("getTimestamp", &TrackedFeatures::getTimestamp, DOC(dai, TrackedFeatures, getTimestamp))
.def("getTimestampDevice", &TrackedFeatures::getTimestampDevice, DOC(dai, TrackedFeatures, getTimestampDevice))
.def("getSequenceNum", &TrackedFeatures::getSequenceNum, DOC(dai, TrackedFeatures, getSequenceNum))
.def("setTimestamp", &TrackedFeatures::setTimestamp, DOC(dai, TrackedFeatures, setTimestamp))
.def("setTimestampDevice", &TrackedFeatures::setTimestampDevice, DOC(dai, TrackedFeatures, setTimestampDevice))
.def("setSequenceNum", &TrackedFeatures::setSequenceNum, DOC(dai, TrackedFeatures, setSequenceNum))
;

}
6 changes: 6 additions & 0 deletions src/pipeline/datatype/TrackletsBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ void bind_tracklets(pybind11::module& m, void* pCallstack){
tracklets
.def(py::init<>())
.def_property("tracklets", [](Tracklets& track) { return &track.tracklets; }, [](Tracklets& track, std::vector<Tracklet> val) { track.tracklets = val; }, DOC(dai, Tracklets, tracklets))
.def("getTimestamp", &Tracklets::getTimestamp, DOC(dai, Tracklets, getTimestamp))
.def("getTimestampDevice", &Tracklets::getTimestampDevice, DOC(dai, Tracklets, getTimestampDevice))
.def("getSequenceNum", &Tracklets::getSequenceNum, DOC(dai, Tracklets, getSequenceNum))
.def("setTimestamp", &Tracklets::setTimestamp, DOC(dai, Tracklets, setTimestamp))
.def("setTimestampDevice", &Tracklets::setTimestampDevice, DOC(dai, Tracklets, setTimestampDevice))
.def("setSequenceNum", &Tracklets::setSequenceNum, DOC(dai, Tracklets, setSequenceNum))
;

}
45 changes: 21 additions & 24 deletions src/pipeline/node/NodeBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void NodeBindings::bind(pybind11::module& m, void* pCallstack){
py::class_<Node::Output> pyOutput(pyNode, "Output", DOC(dai, Node, Output));
py::enum_<Node::Output::Type> nodeOutputType(pyOutput, "Type");
py::class_<Properties, std::shared_ptr<Properties>> pyProperties(m, "Properties", DOC(dai, Properties));
py::class_<Node::DatatypeHierarchy> nodeDatatypeHierarchy(pyNode, "DatatypeHierarchy", DOC(dai, Node, DatatypeHierarchy));


// Node::Id bindings
Expand Down Expand Up @@ -189,20 +190,26 @@ void NodeBindings::bind(pybind11::module& m, void* pCallstack){

// Base 'Node' class binding

nodeDatatypeHierarchy
.def(py::init<DatatypeEnum, bool>())
.def_readwrite("datatype", &Node::DatatypeHierarchy::datatype)
.def_readwrite("descendants", &Node::DatatypeHierarchy::descendants)
;

// Node::Input bindings
nodeInputType
.value("SReceiver", Node::Input::Type::SReceiver)
.value("MReceiver", Node::Input::Type::MReceiver)
;
pyInput
.def_property("group", [](Node::Input& obj) { return obj.group; }, [](Node::Input& obj, std::string group) { obj.group = group; })
.def_property("name", [](Node::Input& obj) { return obj.name; }, [](Node::Input& obj, std::string name) { obj.name = name; })
.def_property("type", [](Node::Input& obj) { return obj.type; }, [](Node::Input& obj, Node::Input::Type type) { obj.type = type; })
.def_readwrite("group", &Node::Input::group, DOC(dai, Node, Input, group))
.def_readwrite("name", &Node::Input::name, DOC(dai, Node, Input, name))
.def_readwrite("type", &Node::Input::type, DOC(dai, Node, Input, type))
.def("setBlocking", &Node::Input::setBlocking, py::arg("blocking"), DOC(dai, Node, Input, setBlocking))
.def("getBlocking", &Node::Input::getBlocking, DOC(dai, Node, Input, getBlocking))
.def("setQueueSize", &Node::Input::setQueueSize, py::arg("size"), DOC(dai, Node, Input, setQueueSize))
.def("getQueueSize", &Node::Input::getQueueSize, DOC(dai, Node, Input, getQueueSize))
.def_property("waitForMessage", [](Node::Input& obj) { return obj.type; }, [](Node::Input& obj, bool waitForMessage) { obj.waitForMessage = waitForMessage; })
.def_readwrite("waitForMessage", &Node::Input::waitForMessage, DOC(dai, Node, Input, waitForMessage))
.def("setWaitForMessage", &Node::Input::setWaitForMessage, py::arg("waitForMessage"), DOC(dai, Node, Input, setWaitForMessage))
.def("getWaitForMessage", &Node::Input::getWaitForMessage, DOC(dai, Node, Input, getWaitForMessage))
.def("setReusePreviousMessage", &Node::Input::setReusePreviousMessage, py::arg("reusePreviousMessage"), DOC(dai, Node, Input, setReusePreviousMessage))
Expand All @@ -215,23 +222,23 @@ void NodeBindings::bind(pybind11::module& m, void* pCallstack){
.value("SSender", Node::Output::Type::SSender)
;
pyOutput
.def_property("group", [](Node::Output& obj) -> std::string& { return obj.group; }, [](Node::Output& obj, std::string group) { obj.group = group; })
.def_property("name", [](Node::Output& obj) -> std::string& { return obj.name; }, [](Node::Output& obj, std::string name) { obj.name = name; })
.def_property("type", [](Node::Output& obj) -> Node::Output::Type& { return obj.type; }, [](Node::Output& obj, Node::Output::Type type) { obj.type = type; })
.def_readwrite("group", &Node::Output::group, DOC(dai, Node, Output, group))
.def_readwrite("name", &Node::Output::name, DOC(dai, Node, Output, name))
.def_readwrite("type", &Node::Output::type, DOC(dai, Node, Output, type))
.def_readwrite("possibleDatatypes", &Node::Output::possibleDatatypes, DOC(dai, Node, Output, possibleDatatypes))
.def("canConnect", &Node::Output::canConnect, py::arg("input"), DOC(dai, Node, Output, canConnect))
.def("link", &Node::Output::link, py::arg("input"), DOC(dai, Node, Output, link))
.def("unlink", &Node::Output::unlink, py::arg("input"), DOC(dai, Node, Output, unlink))
.def("getConnections", &Node::Output::getConnections, DOC(dai, Node, Output, getConnections))
;


nodeConnection
.def_property("outputId", [](Node::Connection& conn) -> Node::Id& { return conn.outputId; }, [](Node::Connection& conn, Node::Id id) {conn.outputId = id; }, DOC(dai, Node, Connection, outputId))
.def_property("outputName", [](Node::Connection& conn) -> std::string& { return conn.outputName; }, [](Node::Connection& conn, std::string name) {conn.outputName = name; }, DOC(dai, Node, Connection, outputName))
.def_property("outputGroup", [](Node::Connection& conn) -> std::string& { return conn.outputGroup; }, [](Node::Connection& conn, std::string group) {conn.outputGroup = group; }, DOC(dai, Node, Connection, outputGroup))
.def_property("inputId", [](Node::Connection& conn) -> Node::Id& { return conn.inputId; }, [](Node::Connection& conn, Node::Id id) {conn.inputId = id; }, DOC(dai, Node, Connection, inputId))
.def_property("inputName", [](Node::Connection& conn) -> std::string& { return conn.inputName; }, [](Node::Connection& conn, std::string name) {conn.inputName = name; }, DOC(dai, Node, Connection, inputName))
.def_property("inputGroup", [](Node::Connection& conn) -> std::string& { return conn.inputGroup; }, [](Node::Connection& conn, std::string group) {conn.inputGroup = group; }, DOC(dai, Node, Connection, inputGroup))
.def_readwrite("outputId", &Node::Connection::outputId, DOC(dai, Node, Connection, outputId))
.def_readwrite("outputName", &Node::Connection::outputName, DOC(dai, Node, Connection, outputName))
.def_readwrite("outputGroup", &Node::Connection::outputGroup, DOC(dai, Node, Connection, outputGroup))
.def_readwrite("inputId", &Node::Connection::inputId, DOC(dai, Node, Connection, inputId))
.def_readwrite("inputName", &Node::Connection::inputName, DOC(dai, Node, Connection, inputName))
.def_readwrite("inputGroup", &Node::Connection::inputGroup, DOC(dai, Node, Connection, inputGroup))
;

pyNode
Expand All @@ -250,15 +257,5 @@ void NodeBindings::bind(pybind11::module& m, void* pCallstack){
.def_property("properties", [](Node& n) -> const Properties& { return n.properties; }, [](Node& n, const Properties& p) { n.properties = p; }, DOC(dai, Node, properties), py::return_value_policy::reference_internal)
;

// MSVC errors out with:
// Error C2326 'void NodeBindings::bind(pybind11::module &)': function cannot access 'dai::Node::Connection::outputId'
// ...
// py::class_<Node::Connection>(pyNode, "Connection")
// .def_readwrite("outputId", &dai::Node::Connection::outputId)
// .def_readwrite("outputName", &dai::Node::Connection::outputName)
// .def_readwrite("inputId", &dai::Node::Connection::inputId)
// .def_readwrite("inputName", &dai::Node::Connection::inputName)
// ;

}

Loading

0 comments on commit 20ac5f5

Please sign in to comment.