NVIDIA nvImageCodec — nvImageCodec (original) (raw)
The nvImageCodec is a library of accelerated codecs with unified interface. It is designed as a framework for extension modules which delivers codec plugins. The following image illustrates the simplified architecture of nvImageCodec.
Key features#
Accessible on multiple platforms#
Easy installation#
For windows, linux and sbsa
pip install nvidia-nvimgcodec-cu12[all]
For tegra
pip install nvidia-nvimgcodec-tegra-cu12[all]
You can specify a subset of the dependencies: nvjpeg, nvjpeg2k, nvtiff
depending what codecs would you like to use. For example:
pip install nvidia-nvimgcodec-cu12[nvjpeg2k,nvtiff]
For more options, please see Installation documentation.
Unified C and Python API for decoding and encoding images#
from nvidia import nvimgcodec nv_img = nvimgcodec.Decoder().read("cat-1046544_640.jp2") nvimgcodec.Encoder().write("cat-jp2-o.jpg", nv_img)
Batch processing, with variable shape and heterogeneous formats images#
import os.path as p from nvidia import nvimgcodec image_paths = ["cat-1046544_640.jp2", "tabby_tiger_cat.jpg", "Weimaraner.bmp"] image_list = nvimgcodec.Decoder().read(image_paths) out_file_names = [p.splitext(p.basename(i))[0] + "_out.jpg" for i in image_paths]
nvimgcodec.Encoder().write(out_file_names, image_list, ".jpg")
NVIDIA accelerated and 3 rd party codecs with prioritization and automatic fallback#
Zero-copy interfaces to CV-CUDA, PyTorch, Tensorflow, CuPy and more#
from nvidia import nvimgcodec import cupy as cp; import cupyx.scipy.ndimage from matplotlib import pyplot as plt
nv_img = nvimgcodec.Decoder().read("images/tabby_tiger_cat.jpg") cp_img = cp.asarray(nv_img) # zero-copy print('nvImageCodec device pointer: ', nv_img.cuda_array_interface['data'][0], end='') print('CuPy device pointer:', cp_img.cuda_array_interface['data'][0])
cp_img_rotated = cupyx.scipy.ndimage.rotate(cp_img, 90) nvimgcodec.Encoder().write("rotated_cat.jp2", cp_img_rotated)
nv_rotated_img = nvimgcodec.as_image(cp_img_rotated) plt.imshow(nv_rotated_img.cpu())