| 297 | } |
| 298 | |
| 299 | nvcv::TensorShape GetOutputTensorShape(const nvcv::TensorShape &inputShape, nvcv::ImageFormat outputFormat, |
| 300 | NVCVColorConversionCode code) |
| 301 | { |
| 302 | if (inputShape.rank() < 3 || inputShape.rank() > 4) |
| 303 | { |
| 304 | throw std::runtime_error("Invalid input tensor shape, only NHWC or HWC are supported"); |
| 305 | } |
| 306 | |
| 307 | int64_t outputShape[4] = {}; |
| 308 | bool heightIndex = inputShape.rank() == 4 ? 1 : 0; |
| 309 | for (int i = 0; i < inputShape.rank(); i++) |
| 310 | { |
| 311 | outputShape[i] = inputShape[i]; |
| 312 | } |
| 313 | int channelIndex = inputShape.rank() == 4 ? 3 : 2; |
| 314 | |
| 315 | outputShape[heightIndex] = GetOutputHeight(outputShape[heightIndex], code); |
| 316 | outputShape[channelIndex] = outputFormat.numChannels(); |
| 317 | |
| 318 | if (inputShape.rank() == 4) |
| 319 | { |
| 320 | return nvcv::TensorShape({outputShape[0], outputShape[1], outputShape[2], outputShape[3]}, "NHWC"); |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | assert(inputShape.rank() == 3); |
| 325 | |
| 326 | return nvcv::TensorShape({outputShape[0], outputShape[1], outputShape[2]}, "HWC"); |
| 327 | } |
| 328 | } |
no test coverage detected