几天速通nvJPEG2000:GPU并行处理JEPG2000压缩算法
第四步最关键,这个库只能支持bmp等编码好的二进制格式,不能支持raw格式。通过阅读源码发现,本质上也是读取bmp等格式为像素数据,那么也无需将raw格式的dng图片转为bmp,再jpeg2000编码。几天整明白了nvJPEG这个库,并且在arm架构的英伟达jetson开发板,采用gpu并行,实际将DNG图片压缩为jpeg2000的格式:j2k。要做到移植,还需要保证安装的包(opencv等)也是
几天整明白了nvJPEG2000这个库,并且在arm架构的英伟达jetson开发板,采用gpu并行,实际将DNG图片压缩为jpeg2000的格式:j2k。
我的路线是:

第一步,可以看这篇博客,进行了编码的安装和编译。https://blog.csdn.net/qq_43658820/article/details/152127193?spm=1001.2014.3001.5501
第二步略过。第三步找到了官方的例子:
https://github.com/NVIDIA/CUDALibrarySamples/tree/master/nvJPEG2000/nvJPEG2000-Encoder
然而,官方的例子给出的支持架构是x86。而我的jetson开发板是arm架构。所以之后要改。
第四步最关键,这个库只能支持bmp等编码好的二进制格式,不能支持raw格式。通过阅读源码发现,本质上也是读取bmp等格式为像素数据,那么也无需将raw格式的dng图片转为bmp,再jpeg2000编码。因此只需要编写dng的读取方法,能够将像素数据传递给下游函数。
4.1 理解源码和api的使用是比较痛苦的事。
4.2 修改代码,移植到arm架构上。尤其注意:留意数据类型的差异,比如 char类型在 x86 下默认为有符号,而在 ARM 下默认为无符号,这一点差别就会导致最终运算结果失败!cmake中,要移除 x86 特有的编译选项(例如 -m64, -msse4.1),为 x86_64 和 aarch64 设置不同的编译参数。。。。。。
要做到移植,还需要保证安装的包(opencv等)也是arm架构,并且版本要合适。仔细阅读官方的要求。确保cuda、gcc等版本合适。
https://docs.nvidia.com/cuda/nvjpeg2000/

第五步,源码是按照批次循环处理的。还需要在read_next_batch上加入读取dng的逻辑。这个也好说。

第六步。编译通过。就是运行测试了。官方给出了很好的命令行参数:
Usage: ./nvjpeg2k_encode -i images_dir [-b batch_size] [-t total_images] [-I] [-cblk cblk_w,cblk_h]
[-w warmup_iterations] [-o output_dir] [-ht]
[-q_factor value] [-quantization value] [-psnr value]
[-img_fmt img_w,img_h,num_comp,precision,chromaformat] (-img_fmt is mandatory for raw yuv files)
eg: for an 8 bit image of size 1920x1080 with 420 subsampling: -img-dims 1920,1080,3,8,chroma420
Parameters:
images_dir : Path to single image or directory of images
batch_size : Encode images from input by batches of specified size
total_images : Encode these many images, if there are fewer images
in the input than total images, encoder will loop over the input
-ht : Enable High Throughput encoding
-I : Enable irreversible wavelet transform. Must be set to use any quality option
-q_factor : Set `value` as Q-Factor (jpeg-like) quality:
floating point from 1.0 (worst) to 100.0 (best)
-quantization : Set `value` as quantization step (by how much pixel data will be divided):
floating point, bigger the value, the lower the result quality.
-psnr : Set `value` as target PSNR value: positive floating point.
Cannot be used with -ht option
cblk_w,cblk_h : Code block width and code block height
valid values are 32,32 and 64,64
warmup_iterations: Run these many batches first without measuring performance
output_dir : Write compressed jpeg 2000 files to this directory
这其中,-q_factor、-quantization、-batch_size能够影响并行处理的速度和结果质量。调参主要调整这几个。
需要源码私聊我。
火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。
更多推荐
所有评论(0)