for image_file in image_files:
if image_file.endswith('.jpg'):
image_path = os.path.join(image_dir, image_file)
image = cv2.imread(image_path)
video.write(image)
video.release()
```
另一种方法是把图片转换成宽高相同
```
import os
import cv2
def resize_images(directory):
image_files = [file for file in os.listdir(directory) if file.endswith(('.jpg', '.jpeg', '.png'))]
for image_file in image_files:
image_path = os.path.join(directory, image_file)
image = cv2.imread(image_path)