python api: move logic in sensor data methods to DVSEventArray

This commit is contained in:
Javier Hidalgo-Carrió 2020-05-05 19:11:38 +02:00 committed by Marc Garcia Puig
parent f5df364089
commit 38432de658
2 changed files with 51 additions and 53 deletions

View File

@ -53,6 +53,7 @@ namespace data {
return GetHeader().fov_angle; return GetHeader().fov_angle;
} }
/// Get an event "frame" image for visualization
std::vector<Color> ToImage() const { std::vector<Color> ToImage() const {
std::vector<Color> img(GetHeight() * GetWidth()); std::vector<Color> img(GetHeight() * GetWidth());
for (const auto &event : *this) { for (const auto &event : *this) {
@ -68,6 +69,51 @@ namespace data {
return img; return img;
} }
/// Get the array of events in pure vector format
std::vector<std::vector<std::int64_t>> ToArray() const {
std::vector<std::vector<std::int64_t>> array;
for (const auto &event : *this) {
array.push_back({static_cast<std::int64_t>(event.x), static_cast<std::int64_t>(event.y), static_cast<std::int64_t>(event.t), static_cast<std::int64_t>(event.pol)});
}
return array;
}
/// Get all events' x coordinate for convenience
std::vector<std::uint16_t> ToArrayX() const {
std::vector<std::uint16_t> array;
for (const auto &event : *this) {
array.push_back(event.x);
}
return array;
}
/// Get all events' y coordinate for convenience
std::vector<std::uint16_t> ToArrayY() const {
std::vector<std::uint16_t> array;
for (const auto &event : *this) {
array.push_back(event.y);
}
return array;
}
/// Get all events' timestamp for convenience
std::vector<std::int64_t> ToArrayT() const {
std::vector<std::int64_t> array;
for (const auto &event : *this) {
array.push_back(event.t);
}
return array;
}
/// Get all events' polarity for convenience
std::vector<short> ToArrayPol() const {
std::vector<short> array;
for (const auto &event : *this) {
array.push_back(2*static_cast<short>(event.pol) - 1);
}
return array;
}
}; };
} // namespace data } // namespace data

View File

@ -359,59 +359,11 @@ void export_sensor_data() {
self.at(pos) = event; self.at(pos) = event;
}) })
.def("to_image", CALL_RETURNING_LIST(csd::DVSEventArray, ToImage)) .def("to_image", CALL_RETURNING_LIST(csd::DVSEventArray, ToImage))
.def("to_array", +[](const csd::DVSEventArray &self) -> std::vector<std::vector<std::int64_t>> { .def("to_array", CALL_RETURNING_LIST(csd::DVSEventArray, ToArray))
std::vector<std::vector<std::int64_t>> array (self.size()); .def("to_array_x", CALL_RETURNING_LIST(csd::DVSEventArray, ToArrayX))
for (size_t i=0; i<self.size(); ++i) .def("to_array_y", CALL_RETURNING_LIST(csd::DVSEventArray, ToArrayY))
{ .def("to_array_t", CALL_RETURNING_LIST(csd::DVSEventArray, ToArrayT))
const csd::DVSEvent &event = self[i]; .def("to_array_pol", CALL_RETURNING_LIST(csd::DVSEventArray, ToArrayPol))
std::vector<std::int64_t> element = {static_cast<std::int64_t>(event.x), static_cast<std::int64_t>(event.y), static_cast<std::int64_t>(event.t), static_cast<std::int64_t>(event.pol)};
array[i] = element;
}
return array;
})
.def("to_array_x", +[](const csd::DVSEventArray &self) -> std::vector<std::int64_t> {
std::vector<std::int64_t> array;
for (size_t i=0; i<self.size(); ++i)
{
const csd::DVSEvent &event = self[i];
array.push_back(event.x);
}
return array;
})
.def("to_array_y", +[](const csd::DVSEventArray &self) -> std::vector<std::int64_t> {
std::vector<std::int64_t> array;
for (size_t i=0; i<self.size(); ++i)
{
const csd::DVSEvent &event = self[i];
array.push_back(event.y);
}
return array;
})
.def("to_array_t", +[](const csd::DVSEventArray &self) -> std::vector<std::int64_t> {
std::vector<std::int64_t> array;
for (size_t i=0; i<self.size(); ++i)
{
const csd::DVSEvent &event = self[i];
array.push_back(event.t);
}
return array;
})
.def("to_array_pol", +[](const csd::DVSEventArray &self) -> std::vector<short> {
std::vector<short> array;
for (size_t i=0; i<self.size(); ++i)
{
const csd::DVSEvent &event = self[i];
if (event.pol == true)
array.push_back(1);
else
array.push_back(-1);
}
return array;
})
.def(self_ns::str(self_ns::self)) .def(self_ns::str(self_ns::self))
; ;
} }