MCPcopy Create free account
hub / github.com/colmap/colmap / ArrayFromBitmap

Function ArrayFromBitmap

src/pycolmap/sensor/bitmap.cc:20–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18#endif
19
20py::array_t<uint8_t> ArrayFromBitmap(const Bitmap& self) {
21 std::vector<ssize_t> shape = {static_cast<ssize_t>(self.Height()),
22 static_cast<ssize_t>(self.Width())};
23 const auto channels = static_cast<ssize_t>(self.Channels());
24 if (channels != 1) {
25 if (channels != 3) {
26 throw std::runtime_error(
27 "Can only convert grayscale or 3-channel RGB image to "
28 "array");
29 }
30 shape.push_back(channels);
31 }
32 py::array_t<uint8_t> output(shape);
33 py::buffer_info output_into = output.request();
34 uint8_t* output_row_ptr = reinterpret_cast<uint8_t*>(output.request().ptr);
35 std::memcpy(output_row_ptr, self.RowMajorData().data(), self.NumBytes());
36 return output;
37}
38
39Bitmap BitmapFromArray(py::array_t<uint8_t, py::array::c_style> array,
40 bool linear_colorspace) {

Callers

nothing calls this directly

Calls 4

ChannelsMethod · 0.80
HeightMethod · 0.45
WidthMethod · 0.45
NumBytesMethod · 0.45

Tested by

no test coverage detected