Moved ToImage() and added a use case in man_contr
This commit is contained in:
parent
a55c71ad4f
commit
9f5f4b9a2e
|
@ -9,6 +9,7 @@
|
|||
#include "carla/Debug.h"
|
||||
#include "carla/sensor/data/Array.h"
|
||||
#include "carla/sensor/data/DVSEvent.h"
|
||||
#include "carla/sensor/data/Color.h"
|
||||
#include "carla/sensor/s11n/DVSEventArraySerializer.h"
|
||||
|
||||
namespace carla {
|
||||
|
@ -16,7 +17,7 @@ namespace sensor {
|
|||
namespace data {
|
||||
|
||||
/// An array of DVS Events in an image structure HxW
|
||||
class DVSEventArray : public Array<DVSEvent> {
|
||||
class DVSEventArray : public Array<DVSEvent> {
|
||||
using Super = Array<DVSEvent>;
|
||||
protected:
|
||||
|
||||
|
@ -51,6 +52,22 @@ namespace data {
|
|||
auto GetFOVAngle() const {
|
||||
return GetHeader().fov_angle;
|
||||
}
|
||||
|
||||
std::vector<Color> ToImage() const {
|
||||
std::vector<Color> img(GetHeight() * GetWidth());
|
||||
for (const auto &event : *this) {
|
||||
size_t index = (GetWidth() * event.y) + event.x;
|
||||
if (event.pol == true) {
|
||||
// Blue is positive
|
||||
img[index].b = 255u;
|
||||
} else {
|
||||
// Red is negative
|
||||
img[index].r = 255u;
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace data
|
||||
|
|
|
@ -319,12 +319,6 @@ void export_sensor_data() {
|
|||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<std::vector<csd::Color> >("ColorVector")
|
||||
.add_property("raw_data", &GetRawDataAsBuffer< std::vector<csd::Color> >)
|
||||
.def("__len__", &std::vector<csd::Color>::size)
|
||||
.def(vector_indexing_suite< std::vector<csd::Color> >())
|
||||
;
|
||||
|
||||
class_<std::vector<std::int64_t>>("IntVector")
|
||||
.add_property("raw_data", &GetRawDataAsBuffer< std::vector<std::int64_t> >)
|
||||
.def("__len__", &std::vector<std::int64_t>::size)
|
||||
|
@ -364,25 +358,7 @@ void export_sensor_data() {
|
|||
.def("__setitem__", +[](csd::DVSEventArray &self, size_t pos, csd::DVSEvent event) {
|
||||
self.at(pos) = event;
|
||||
})
|
||||
.def("to_image", +[](const csd::DVSEventArray &self) -> std::vector<csd::Color> {
|
||||
std::vector<csd::Color> img (self.GetHeight() * self.GetWidth());
|
||||
for (size_t i=0; i<self.size(); ++i)
|
||||
{
|
||||
const csd::DVSEvent &event = self[i];
|
||||
size_t index = (self.GetWidth() * event.y) + event.x;
|
||||
if (event.pol == true)
|
||||
{
|
||||
/** Blue is positive **/
|
||||
img[index].b = 255u;
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Red is negative **/
|
||||
img[index].r = 255u;
|
||||
}
|
||||
}
|
||||
return img;
|
||||
})
|
||||
.def("to_image", CALL_RETURNING_LIST(csd::DVSEventArray, ToImage))
|
||||
.def("to_array", +[](const csd::DVSEventArray &self) -> std::vector<std::vector<std::int64_t>> {
|
||||
std::vector<std::vector<std::int64_t>> array (self.size());
|
||||
for (size_t i=0; i<self.size(); ++i)
|
||||
|
|
|
@ -980,15 +980,18 @@ class CameraManager(object):
|
|||
lidar_data = lidar_data.astype(np.int32)
|
||||
lidar_data = np.reshape(lidar_data, (-1, 2))
|
||||
lidar_img_size = (self.hud.dim[0], self.hud.dim[1], 3)
|
||||
lidar_img = np.zeros((lidar_img_size), dtype = int)
|
||||
lidar_img = np.zeros((lidar_img_size), dtype=np.uint8)
|
||||
lidar_img[tuple(lidar_data.T)] = (255, 255, 255)
|
||||
self.surface = pygame.surfarray.make_surface(lidar_img)
|
||||
elif self.sensors[self.index][0].startswith('sensor.camera.dvs'):
|
||||
array = np.frombuffer(image.to_image().raw_data, dtype=np.dtype("uint8"))
|
||||
array = np.reshape(array, (image.height, image.width, 4))
|
||||
array = array[:, :, :3]
|
||||
array = array[:, :, ::-1]
|
||||
self.surface = pygame.surfarray.make_surface(array.swapaxes(0, 1))
|
||||
# Example of converting the raw_data from a carla.DVSEventArray
|
||||
# sensor into a NumPy array and using it as an image
|
||||
dvs_events = np.frombuffer(image.raw_data, dtype=np.dtype([
|
||||
('x', np.uint16), ('y', np.uint16), ('t', np.int64), ('pol', np.bool)]))
|
||||
dvs_img = np.zeros((image.height, image.width, 3), dtype=np.uint8)
|
||||
# Blue is positive, red is negative
|
||||
dvs_img[dvs_events[:]['y'], dvs_events[:]['x'], dvs_events[:]['pol'] * 2] = 255
|
||||
self.surface = pygame.surfarray.make_surface(dvs_img.swapaxes(0, 1))
|
||||
else:
|
||||
image.convert(self.sensors[self.index][1])
|
||||
array = np.frombuffer(image.raw_data, dtype=np.dtype("uint8"))
|
||||
|
|
Loading…
Reference in New Issue