Skip to content

Commit 752647b

Browse files
committed
segmentation properties
1 parent ecef0fa commit 752647b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/cpp/py_bindings/py_segmentation.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,39 @@ void init_segmentation(nb::module_& m) {
6565
static_cast<size_t>(r.resultImage.cols),
6666
static_cast<size_t>(r.resultImage.channels())});
6767
},
68+
nb::rv_policy::reference_internal)
69+
.def_prop_ro(
70+
"feature_vector",
71+
[](ResultBase& r) {
72+
ImageResultWithSoftPrediction ir = r.asRef<ImageResultWithSoftPrediction>();
73+
if (!ir.feature_vector) {
74+
return nb::ndarray<float, nb::numpy, nb::c_contig>();
75+
}
76+
77+
return nb::ndarray<float, nb::numpy, nb::c_contig>(ir.feature_vector.data(),
78+
ir.feature_vector.get_shape().size(),
79+
ir.feature_vector.get_shape().data());
80+
},
81+
nb::rv_policy::reference_internal)
82+
.def_prop_ro(
83+
"soft_prediction",
84+
[](ResultBase& r) {
85+
ImageResultWithSoftPrediction ir = r.asRef<ImageResultWithSoftPrediction>();
86+
return nb::ndarray<float, nb::numpy, nb::c_contig>(
87+
ir.soft_prediction.data,
88+
{static_cast<size_t>(ir.soft_prediction.rows),
89+
static_cast<size_t>(ir.soft_prediction.cols),
90+
static_cast<size_t>(ir.soft_prediction.channels())});
91+
},
92+
nb::rv_policy::reference_internal)
93+
.def_prop_ro(
94+
"saliency_map",
95+
[](ResultBase& r) {
96+
ImageResultWithSoftPrediction ir = r.asRef<ImageResultWithSoftPrediction>();
97+
return nb::ndarray<float, nb::numpy, nb::c_contig>(ir.saliency_map.data,
98+
{static_cast<size_t>(ir.saliency_map.rows),
99+
static_cast<size_t>(ir.saliency_map.cols),
100+
static_cast<size_t>(ir.saliency_map.channels())});
101+
},
68102
nb::rv_policy::reference_internal);
69103
}

0 commit comments

Comments
 (0)