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

Function py_sub_image

tools/python/src/image2.cpp:522–553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520// ----------------------------------------------------------------------------------------
521
522py::array py_sub_image (
523 const py::array& img,
524 const rectangle& win
525)
526{
527 DLIB_CASSERT(img.ndim() >= 2);
528
529 auto width_step = img.strides(0);
530
531 const long nr = img.shape(0);
532 const long nc = img.shape(1);
533 rectangle rect(0,0,nc-1,nr-1);
534 rect = rect.intersect(win);
535
536 std::vector<size_t> shape(img.ndim()), strides(img.ndim());
537 for (size_t i = 0; i < shape.size(); ++i)
538 {
539 shape[i] = img.shape(i);
540 strides[i] = img.strides(i);
541 }
542
543 shape[0] = rect.height();
544 shape[1] = rect.width();
545
546 size_t col_stride = 1;
547 for (size_t i = 1; i < strides.size(); ++i)
548 col_stride *= strides[i];
549
550 const void* data = (char*)img.data() + col_stride*rect.left() + rect.top()*strides[0];
551
552 return py::array(img.dtype(), shape, strides, data, img);
553}
554
555py::array py_sub_image2 (
556 const py::tuple& image_and_rect_tuple

Callers 1

py_sub_image2Function · 0.85

Calls 12

stridesMethod · 0.80
arrayClass · 0.50
ndimMethod · 0.45
shapeMethod · 0.45
intersectMethod · 0.45
sizeMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
dataMethod · 0.45
leftMethod · 0.45
topMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected