У меня есть изображения JPG, и я пытаюсь сделать следующее:
- изменить размер ввода и сохранить результат в PNG
- преобразовать изображения PNG в YUV (например, yuv444p10le) в контейнере AVI
- конвертируйте AVI обратно в изображение PNG.
Я использую python 3 и версию ffmpeg Linux, установленную на Colab
Я распечатал Разница между resized_png и restore_png. У меня есть значения 255, которые вообще не имеют смысла.
[[[ 0 255 1]
[ 0 0 1]
[ 0 255 1]
...
[ 1 0 0]
[ 1 0 0]
[ 2 0 1]]
[[ 0 255 1]
[ 0 255 1]
[ 1 0 0]
...
[ 1 0 0]
[ 1 0 0]
[ 1 0 0]]
[[ 0 0 1]
[ 0 0 1]
[ 0 0 1]
...
[ 1 255 0]
[ 1 255 1]
[ 1 0 0]]
...
[[255 0 0]
[255 0 1]
[255 0 1]
...
[ 0 0 0]
[ 0 0 1]
[255 0 1]]
[[255 0 1]
[255 0 1]
[255 0 1]
...
[ 0 0 1]
[ 0 0 1]
[ 0 0 0]]
[[255 0 1]
[255 0 1]
[255 0 1]
...
[255 1 0]
[255 0 0]
[255 0 1]]]
input_image = '/content/drive/My Drive/Colab Notebooks/adv_dnn/datasets/im2.jpg'
output_resized = '/content/drive/My Drive/Colab Notebooks/adv_dnn/datasets/im2.png'
folder_path = '/content/drive/My Drive/Colab Notebooks/adv_dnn/datasets/'
#do resize
# code = subprocess.call('cd /usr/bin/ffmpeg', shell=True)
# print(code)
cmd_resize = ['ffmpeg', '-y', '-i', input_image,'-vf', 'scale=224:224', output_resized]
process = subprocess.Popen(cmd_resize, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
print(out)
print(err)
fmt = ['yuv420p', 'yuv420p10le', 'yuv444p', 'yuv444p10le']
for f in fmt:
cmd2YUV = ['ffmpeg', '-y', '-i', output_resized, '-c:v', 'libx264', '-preset', 'placebo',\
'-qp', '0', '-x264-params', "keyint=15:no-deblock=1", '-pix_fmt', f, \
'-sws_flags', 'spline+accurate_rnd+full_chroma_int', \
'-vf', "colorspace=bt709:iall=bt601-6-625:fast=1", '-color_range', '1', '-colorspace', '1',
'-color_primaries', '1', '-color_trc', '1', folder_path+'im2_'+f+'.avi']
process = subprocess.Popen(cmd2YUV, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
print(out)
print(err)
cmd2PNG = ['ffmpeg', '-y', '-i', folder_path+'im2_'+f+'.avi', '-compression_level', '10', '-pred', 'mixed', \
'-pix_fmt', 'rgb24', '-sws_flags', '+accurate_rnd+full_chroma_int', \
folder_path+'im2_'+f+'.png']
process = subprocess.Popen(cmd2PNG, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
print(out)
print(err)
im1=pilim.open('/content/drive/My Drive/Colab Notebooks/adv_dnn/datasets/im2.png')
im2=pilim.open('/content/drive/My Drive/Colab Notebooks/adv_dnn/datasets/im2_yuv444p10le.png')
im1_2d = np.asarray(im1)
im2_2d = np.asarray(im2)
print(im2_2d-im1_2d)