VPI exposes a Python API that offers a simplified way to use the library, leading to faster development cycle. Resource management is done automatically under the hood, allowing the developer to focus on the definition of the image processing pipeline.
Requirements
- Ubuntu 20.04 or 22.04
- Python 3.9 or 3.10
- numpy >= 1.11.0
- pillow >= 3.1.2
Writing an Image Blurring Application
Copy the code below to a file named main.py. The comments explain how it works.
35 from argparse
import ArgumentParser
39 parser = ArgumentParser()
40 parser.add_argument(
'input',
41 help=
'Image to be used as input')
42 args = parser.parse_args();
51 input = vpi.asimage(np.asarray(Image.open(args.input)))
53 sys.exit(
"Input file not found")
55 sys.exit(
"Error with input file")
64 with vpi.Backend.CUDA:
70 output = input.convert(vpi.Format.U8) \
71 .box_filter(5, border=vpi.Border.ZERO)
78 with output.rlock_cpu()
as outData:
83 Image.fromarray(outData).save(
'tutorial_blurred_python.png')
Testing the Application
With everything set in place, execute the script as follows:
python3 main.py <image file name>
substituting <image file name> by some image on disk.