python - 将图像转换为视频会抛出内存不足错误,即使使用的内存在 8GB 左右,但我有 64GB
问题描述
尝试将图像转换为视频但收到此错误,
文件“C:/test.py”,第 35 行,在 convert_frames_to_video(pathIn, pathOut, fps) 文件“C:/test.py”,第 17 行,在 convert_frames_to_video img = cv2.imread(filename) cv2.error: OpenCV (4.0.0) C:\projects\opencv- python\opencv\modules\core\src\alloc.cpp:55: error: (-4:Insufficient memory) 无法在函数 'cv::OutOfMemoryError' 中分配 72000000 字节
任务管理器中已用内存为 8GB 总内存为 64GB...我正在使用 PyCharm IDE 运行此代码,
import cv2
import numpy as np
import os
from os.path import isfile, join
def convert_frames_to_video(pathIn, pathOut, fps):
frame_array = []
files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
for i in range(len(files)):
filename = pathIn + "\\" + files[i]
# reading each files
img = cv2.imread(filename)
print(filename)
height, width, layers = img.shape
size = (width, height)
print(filename)
# 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()
pathIn = 'C:\\Images'
pathOut = 'video.avi'
fps = 25.0
convert_frames_to_video(pathIn, pathOut, fps)
解决方案
推荐阅读
- scala - 在 Scala 中递归创建具有多个谓词的 Spark 过滤器
- r - 从多个数据框(.tab)中删除特定列,然后将它们合并到 R
- php - 仅输出到 the_content() 的第一个实例
- jquery - 用下一个 onLoad 的 id 替换 this 的内容
- uwp - 针对 1803 时的 UWP Pivot 控件自适应布局错误(春季创建者更新)
- .net - 当前上下文中不存在名称“ConfigureNinject”
- firebase - 如何在 react-native-firebase 上集成 react-native-fcm
- reactjs - 当 TextInput 获得焦点时,按两次以使按钮工作
- javascript - gmail脚本搜索和自动删除邮件
- button - 如何修改交互式网格上的“保存”操作