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 16.04 or 18.04
- python 2.7 or 3.6
- numpy >= 1.11.0
- pillow >= 3.1.2
Install the Python 2.7 packages using:
apt-get install python python-pil python-numpy
If using Python 3.6, install the following packages:
apt-get install python3 python3-pil python3-numpy
Writing an Image Blurring Application
Copy the code below to a file named main.py. The comments explain how it works.
34 from argparse
import ArgumentParser
38 parser = ArgumentParser()
39 parser.add_argument(
'input',
40 help=
'Image to be used as input')
41 args = parser.parse_args();
49 input = vpi.asimage(np.asarray(Image.open(args.input)))
58 with vpi.Backend.CUDA:
64 output = input.convert(vpi.Format.U8) \
65 .box_filter(5, border=vpi.Border.ZERO)
77 Image.fromarray(output.cpu()).save(
'tutorial_blurred_python.png')
Testing the Application
With everything set in place, if you're using python 2.7, execute the script as follows:
python main.py <image file name>
substituting <image file name> by some image on disk.
To use python 3.6, substitute python
with python3
:
python3 main.py <image file name>