MCPcopy Create free account
hub / github.com/davisking/dlib / convert_to_numpy

Method convert_to_numpy

dlib/python/numpy_image.h:211–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209
210 private:
211 static py::array_t<typename pixel_traits<pixel_type>::basic_pixel_type, py::array::c_style> convert_to_numpy(matrix<pixel_type>&& img)
212 {
213 using basic_pixel_type = typename pixel_traits<pixel_type>::basic_pixel_type;
214 const size_t dtype_size = sizeof(basic_pixel_type);
215 const auto rows = static_cast<const size_t>(num_rows(img));
216 const auto cols = static_cast<const size_t>(num_columns(img));
217 const size_t channels = pixel_traits<pixel_type>::num;
218 const size_t image_size = dtype_size * rows * cols * channels;
219
220 std::unique_ptr<pixel_type[]> arr_ptr = img.steal_memory();
221 basic_pixel_type* arr = (basic_pixel_type *) arr_ptr.release();
222
223 if (channels == 1)
224 {
225 return pybind11::template array_t<basic_pixel_type, py::array::c_style>(
226 {rows, cols}, // shape
227 {dtype_size*cols, dtype_size}, // strides
228 arr, // pointer
229 pybind11::capsule{ arr, [](void *arr_p) { delete[] reinterpret_cast<basic_pixel_type*>(arr_p); } }
230 );
231 }
232 else
233 {
234 return pybind11::template array_t<basic_pixel_type, py::array::c_style>(
235 {rows, cols, channels}, // shape
236 {dtype_size * cols * channels, dtype_size * channels, dtype_size}, // strides
237 arr, // pointer
238 pybind11::capsule{ arr, [](void *arr_p) { delete[] reinterpret_cast<basic_pixel_type*>(arr_p); } }
239 );
240 }
241 }
242
243 };
244

Callers

nothing calls this directly

Calls 4

num_rowsFunction · 0.70
num_columnsFunction · 0.70
steal_memoryMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected