好吧,因此,我试图制作一个带视频的小型压缩器,将其转换为帧,压缩每个帧,然后将压缩的帧组合回视频形式,而即时消息出现的错误是压缩帧与视频的组合。我无法解决。.请帮助
import cv2
import numpy as np
import os
import shutil
from os.path import isfile, join
def imgtovideo():
pathIn= 'C:\\Users\\Dell\\Desktop\\dangol\\compressed'
pathOut = 'C:\\Users\\Dell\\Desktop\\dangol\\video.avi'
fps = 29.970
frame_array = []
files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
#for sorting the file names properly
files.sort(key = lambda x: x[5:-4])
files.sort()
frame_array = []
files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
#for sorting the file names properly
files.sort(key = lambda x: x[5:-4])
for i in range(len(files)):
filename=pathIn + files[i]
#reading each files
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width,height)
#inserting the frames into an image array
frame_array.append(img)
out = cv2.VideoWriter(pathOut,cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
for i in range(len(frame_array)):
# writing to a image array
out.write(frame_array[i])
out.release()
os.chdir('../')
shutil.rmtree('C:\\Users\\Dell\\Desktop\\dangol\\compressed')
if __name__ == "__imgtovideo__":
imgtovideo()
Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files\Python37\lib\tkinter\__init__.py", line 1705, in __call__ return self.func(*args) File "C:\Users\Dell\Desktop\dangol\img_video.py", line 23, in imgtovideo height, width, layers = img.shape AttributeError: 'NoneType' object has no attribute 'shape'