【2022年第一期 CANN训练营学习笔记】进阶班应用开发课 大作业1-开发DVPP应用,输入,输出都是JPEG图片,且分辨率不同
1、大作業(yè)1題目如下:開發(fā)DVPP應(yīng)用,輸入,輸出都是JPEG圖片,且分辨率不同。
根據(jù)作業(yè)提示,轉(zhuǎn)換的思路如下:
原始JPEG圖片->JPEG解碼->YUV Resize->JPEGE->保存JPEG圖片
這些應(yīng)該使用dvpp技術(shù),在device端進(jìn)行轉(zhuǎn)換。其流程應(yīng)滿足dvpp的流程設(shè)計(jì)和編碼方式。
下面看看如何實(shí)戰(zhàn)。
實(shí)現(xiàn)JPEG圖片解碼-縮放-編碼的過程應(yīng)該使用dvpp技術(shù),在device端進(jìn)行轉(zhuǎn)換,其流程滿足dvpp的流程設(shè)計(jì)和編碼方式
2、sample參考
根據(jù)學(xué)習(xí)的內(nèi)容,原來的sample倉里面,包含三個(gè)JPEGD、VPC Resize、JPEGE單獨(dú)的樣例:
2.1 JPEGD 解碼
輸入JPEG圖片,解碼為YUV420格式,保存為yuv格式的文件,sample運(yùn)行截圖:
2.2 VPC Resize
輸入YUV圖片,根據(jù)Resize的尺寸,保存resize之后的YUV圖片,sample運(yùn)行截圖:
2.3 JPEGE 編碼
輸入yuv圖片,調(diào)用編碼接口,保存JPEG圖片,sample運(yùn)行截圖:
3、JPEGD + VPC Resize + JPEGE串聯(lián)
根據(jù)學(xué)習(xí)的內(nèi)容,按照以下思路將完整的功能串聯(lián)在一起輸出代碼,實(shí)現(xiàn)內(nèi)存的復(fù)用,JPEGD解碼后的YUV輸出內(nèi)存給到VPC Resize,Resize之后的內(nèi)存給到JPEGE,編碼之后根據(jù)內(nèi)存輸出地址和Buffersize,寫文件圖片即可。
下面廢話不多說,直接上關(guān)鍵實(shí)現(xiàn)代碼,完整代碼請(qǐng)看作業(yè)貼回復(fù)附件。
3.1.JPEG圖片解碼
主要接口:
acldvppJpegDecodeAsync異步接口進(jìn)行解碼
代碼實(shí)現(xiàn):
3.2. VPC Resize
acldvppCreateResizeConfig縮放配置接口
acldvppVpcResizeAsync異步接口,將輸入圖片縮放到輸出圖片大小,輸出大小這里設(shè)置為640*480,可以自行修改。
代碼實(shí)現(xiàn):
3.3. JPEGE編碼
主要接口:
acldvppCreateJpegeConfig創(chuàng)建圖片編碼配置數(shù)據(jù)
acldvppJpegEncodeAsync異步編碼
代碼實(shí)現(xiàn):
3.4. 保存JPEG圖片
根據(jù)編碼輸出內(nèi)存地址和Buffersize,寫入到JPEG圖片:
int dir_tail_index = image_path.find("/data");std::string outfile_dir = image_path.substr(0, dir_tail_index) + "/" + "out/output/";std::string outfile_path = outfile_dir + image_path.substr(dir_tail_index+5+1, image_path.rfind(".jpg")-dir_tail_index-5-1) + "_jpege_" + std::to_string(modelInputWidth) + "_" + std::to_string(modelInputHeight) + ".jpg"; INFO_LOG("outfile_path=%s", outfile_path.c_str());ret = save_dvpp_outputdata(outfile_path.c_str(), encode_out_buffer_dev_, encode_outbuffer_size_);if (ret != SUCCESS) {ERROR_LOG("save dvpp output data failed");// allow not return}3.5. 運(yùn)行效果
編譯:
cd jpegd_resize_jpede/ cd scripts/ bash sample_build.sh編譯Log:
bash sample_build.sh ../../../../../common [INFO] Sample preparation please input TargetKernel? [arm/x86]:x86 [INFO] input is normal, start preparation. -- The C compiler identification is GNU 7.5.0 -- The CXX compiler identification is GNU 7.5.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/g++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/gitee/samples/cplusplus/level2_simple_inference/0_data_process/jpegd_resize_jpede/build/intermediates/host Scanning dependencies of target main [ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o [100%] Linking CXX executable /home/gitee/samples/cplusplus/level2_simple_inference/0_data_process/jpegd_resize_jpede/out/main運(yùn)行:
bash sample_run.sh運(yùn)行Log:
[INFO] The sample starts to run [INFO] acl init success [INFO] open device 0 success [INFO] create stream success [INFO] start to process picture:../data/dog1_1024_683.jpg [INFO] get jpeg image info successed, width=1024, height=683, format=2, jpegDecodeSize=0 [INFO] dvpp init resource success [INFO] VPC Resized_Width=640, Resized_Hight=480, Output_Buffer_Size=460800 [INFO] Call acldvppCreateJpegeConfig success [INFO] Call acldvppJpegEncodeAsync success [INFO] outfile_path=../out/output/dog1_1024_683_jpege_640_480.jpg [INFO] end to destroy stream [INFO] end to destroy context [INFO] end to reset device is 0 [INFO] end to finalize acl [INFO] execute sample success [INFO] The program runs successfully, please view the result file in the /home/gitee/samples/cplusplus/level2_simple_inference/0_data_process/jpegd_resize_jpede/scripts/../out/output directory!輸出Resize之后的圖片:
完美符合預(yù)期!!!
總結(jié)
以上是生活随笔為你收集整理的【2022年第一期 CANN训练营学习笔记】进阶班应用开发课 大作业1-开发DVPP应用,输入,输出都是JPEG图片,且分辨率不同的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 代理模式(一):代理模式概述,代理模式结
- 下一篇: 【Python中的】列表生成式和字典生成