MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / CustomCrop

Function CustomCrop

python/mod_cvcuda/operators/OpCustomCrop.cpp:50–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50Tensor CustomCrop(Tensor &input, const NVCVRectI &rcCrop, std::optional<Stream> pstream)
51{
52 auto info = nvcv::TensorLayoutInfoImage::Create(input.layout());
53 if (!info)
54 {
55 throw std::invalid_argument("Non-supported tensor layout");
56 }
57
58 int iwidth = info->idxWidth();
59 int iheight = info->idxHeight();
60
61 NVCV_ASSERT(iwidth >= 0 && "All images have width");
62
63 // If no height, we consider height==1, and this dimension can't be changed
64 // in order to keep the output layout the same as input's
65 if (iheight < 0 && rcCrop.height != 1)
66 {
67 throw std::invalid_argument("Non-supported tensor layout");
68 }
69
70 // Create the output shape based inputs, changing width/height to match rcCrop's size
71 nvcv::Shape shape = input.shape().shape();
72 std::vector<int64_t> out_shape{shape.begin(), shape.end()};
73 out_shape[iwidth] = rcCrop.width;
74 if (iheight >= 0)
75 {
76 out_shape[iheight] = rcCrop.height;
77 }
78
79 Tensor output
80 = Tensor::Create({out_shape.data(), static_cast<int32_t>(out_shape.size()), input.layout()}, input.dtype());
81
82 return CustomCropInto(output, input, rcCrop, pstream);
83}
84
85} // namespace
86

Callers

nothing calls this directly

Calls 10

CustomCropIntoFunction · 0.85
idxWidthMethod · 0.80
idxHeightMethod · 0.80
layoutMethod · 0.45
shapeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected