Reformat an image with CVCUDA.
()
| 29 | |
| 30 | |
| 31 | def main() -> None: |
| 32 | """Reformat an image with CVCUDA.""" |
| 33 | # docs_tag: begin_main |
| 34 | args: argparse.Namespace = parse_image_args() |
| 35 | # docs_tag: begin_read_image |
| 36 | input_image: cvcuda.Tensor = read_image(args.input) |
| 37 | height, width, channels = input_image.shape |
| 38 | # docs_tag: end_read_image |
| 39 | |
| 40 | # docs_tag: begin_reformat |
| 41 | # 1. Perform a reformat operation on the image to CHW |
| 42 | chw_image: cvcuda.Tensor = cvcuda.reformat(input_image, "CHW") |
| 43 | assert chw_image.shape == (channels, height, width) |
| 44 | |
| 45 | # 2. Perform a reformat operation on the CHW image back to HWC |
| 46 | hwc_image: cvcuda.Tensor = cvcuda.reformat(chw_image, "HWC") |
| 47 | assert hwc_image.shape == (height, width, channels) |
| 48 | |
| 49 | # 3. Add a batch dimension to the image and reformat to NCHW |
| 50 | nhwc_image: cvcuda.Tensor = cvcuda.stack([input_image]) |
| 51 | nchw_image: cvcuda.Tensor = cvcuda.reformat(nhwc_image, "NCHW") |
| 52 | assert nchw_image.shape == (1, channels, height, width) |
| 53 | # docs_tag: end_reformat |
| 54 | # docs_tag: end_main |
| 55 | |
| 56 | |
| 57 | if __name__ == "__main__": |
no test coverage detected