将图像转换为视频时抛出内存不足错误,即使使用了大约8GB,但我有64GB

时间:2019-03-23 05:37:04

标签: python opencv out-of-memory

尝试将图像转换为视频,但出现此错误,

  

文件“ C:/test.py”,第35行,在       convert_frames_to_video(pathIn,pathOut,fps)文件“ C:/test.py”,第17行,在convert_frames_to_video中       img = cv2.imread(文件名)   cv2.error:OpenCV(4.0.0)C:\ projects \ opencv-   python \ opencv \ modules \ core \ src \ alloc.cpp:55:   错误:(-4:内存不足)无法在以下位置分配72000000字节   函数'cv :: OutOfMemoryError'

任务管理器中使用的内存为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)

0 个答案:

没有答案