NVIDIA® Vision Programming Interface (VPI) is a software library that implements computer vision (CV) and image processing (IP) algorithms on several computing hardware platforms available in NVIDIA embedded and discrete devices.
VPI provides seamless access to computer hardware.
Within VPI, the same algorithm is implemented in different backends, such as CPU, GPU, PVA1, VIC2 and OFA
READ More
importsysimportvpiimportnumpyasnpfromPILimportImagetry:input=vpi.asimage(np.asarray(Image.open("/home/user/projects/nvidia_tutorial/assets/kodim08.png")))exceptIOError:sys.exit("Input file not found")except:sys.exit("Error with input file")# 4. Convert it to grayscale .# -----------------------------------------------------------------------------# Enabling the CUDA backend in a python context like done below makes# VPI algorithms use CUDA for execution by default. This can be overriden# if needed by specifying the parameter `backend=` when calling the algorithm.withvpi.Backend.CUDA:# `image.convert` will return a new VPI image with the desired format, in# this case U8 (grayscale, 8-bit unsigned pixels).# Algorithms returning a new VPI image allows for chaining operations like# done below, as the result of the conversion is then filtered.# The end result is finally stored in a new `output` VPI image.output=input.convert(vpi.Format.U8)# -----------------------------------------------------------------------------# The read-lock context enabled below makes sure all processing is finished and# results are stored in `output`.withoutput.rlock_cpu()asoutData:# `outData` is a numpy array view (not a copy) of `output`# contents, accessible by host (cpu). # The numpy array is then converted into a Pillo image and saved / show# to the diskImage.fromarray(outData).show()
importmatplotlib.pyplotaspltimportvpi# img_vpi is a vpi.Image (any backend). Ensure it's 8-bit gray.img_u8=img_vpi.convert(vpi.Format.U8)# or skip if already U8withimg_u8.rlock_cpu()asnp_img:# NumPy view (no copy)plt.imshow(np_img,cmap='gray',vmin=0,vmax=255)plt.axis('off')plt.show()