python - OpenCV内存不足错误

标签 python opencv

我正在使用多个用户生成的视频进行视频合成项目。下面是我的代码

df=pd.concat(user,axis=1)
#print df

dfs= df.loc[:, (slice(None), ['Panning','sec'])]


video_index=0
cap=cv2.VideoCapture(videoList[0])

fra=[]
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter("Output.avi", fourcc, fps, (width, height), True)
while(cap.isOpened()):
    ret,frame=cap.read()
    fra.append(frame)

    for index,row in dfs.iterrows():
          if (row[:, 'Panning'] == 'Panning').any():
               idx = row[:, 'Panning'][row[:, 'Panning'] == 'Panning'].index.tolist()
               sec = int(row.loc[(idx, 'sec')].values.tolist()[0])
               if cap.get(0)==1000*sec:
                  cap = cv2.VideoCapture(videoList[indices.index(random.choice(idx))])
                  cap.set(0, sec * 1000)
                  ret, frame = cap.read()
                  fra.append(frame)
          else:

              ret,frame=cap.read()
              fra.append(frame)
              if frame is None:
                  video_index += 1
                  if video_index == len(videoList):
                      break
                  cap = cv2.VideoCapture(videoList[indices.index(long_dur())])

                  cap.set(0,1000*sec)
                  ret, frame = cap.read()
                  fra.append(frame)

当我尝试运行时,出现以下错误:
OpenCV Error: Unspecified error (The numpy array of typenum=2, ndims=3 can not be created) in NumpyAllocator::allocate, file ..\..\..\modules\python\src2\cv2.cpp, line 184
OpenCV Error: Insufficient memory (Failed to allocate 6220800 bytes) in cv::OutOfMemoryError, file ..\..\..\modules\core\src\alloc.cpp, line 52
Traceback (most recent call last):
File "C:/Users/chaitanya/PycharmProjects/Thesis/ROI.py", line 86, in <module>
    ret,frame=cap.read()
cv2.error: ..\..\..\modules\core\src\alloc.cpp:52: error: (-4) Failed to allocate 6220800 bytes in function cv::OutOfMemoryError

我无法理解问题。我需要这个错误的帮助

最佳答案

您正在不断将帧添加到fra阵列。迟早您将以这种方式完成RAM,这就是发生的情况。

关于python - OpenCV内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40709826/

相关文章:

python - tkinter 执行在大约 140 次迭代后终止,没有错误消息(内存泄漏?)

python - Windows 上的 Python 模块

OPencv SVM 预测概率

matlab - 如何检测一个棋盘角?

c++ - 水平合并 cv::Mat

c++ - 中断已处于条件变量等待调用状态的 boost 线程

python - 设置字段 `null=True` ,为什么在 ModelForm 中我仍然收到必需的错误?

python - 如何在 matplotlib 条形图中显示不同的语言?

python - 为什么 scapy 在 Mac 上安装失败?

python - Opencv:无法获得对faceRecognizer的预测信心