0

我正在做一个项目,我必须缝合(加入)两个视频并写在一个文件夹中。这是我的功能:

def stich_videos(path1, path2, save_path):
    
    fourcc_ = cv2.VideoWriter_fourcc(*'XVID')
    out_ = cv2.VideoWriter(save_path, fourcc, 30, (1536, 288))

    cap1_ = cv2.VideoCapture(path1) 
    cap2_ = cv2.VideoCapture(path2) 

    while True:

        ret1, frame1_ = cap1_.read()
        ret2, frame2_ = cap2_.read()

        frame1_ = imutils.resize(frame1_, width=512, height=288)

        print(frame1_.shape) # (288, 512, 3)
        print(frame2_.shape) # (288, 1024, 3)

        stacked = np.concatenate((frame1_, frame2_), axis=1)
        out_.write(stacked)
        print('[INFO] Final (1x3) stiching...')

    return save_path

frame1_ 的原始尺寸 = (540, 960, 3) frame2_ 的原始尺寸 = (288, 1024, 3)

在运行并写出_之后这个函数的最后一步,我的代码停止并在 line = frame1_ = imutils.resize(frame1_, width=512, height=288) 中抛出错误,

# grab the image size
     68     dim = None
---> 69     (h, w) = image.shape[:2]
     70 
     71     # if both the width and height are None, then return the

AttributeError: 'NoneType' object has no attribute 'shape'

我不知道为什么会这样,它写得很好,但在最后一帧它抛出了这个错误,甚至堆叠的视频也被保存了!

4

0 回答 0