私は、いくつかの計算にそれを使用するために、collections.dequeを使用してPythonで循環バッファを実装しています。これは私のオリジナルコードです:dequeを使用するよりもPythonの高速循環バッファ?
clip=moviepy.editor.VideoFileClip('file.mp4')
clip_size= clip.size[::-1]
Depth=30
dc=5
TempKern = # some array of size Depth
RingBuffer=deque(np.zeros(clip_size, dtype=float),maxlen=NewDepth)
modified_clip = clip.fl_image(new_filtered_output)
modified_clip.write_videofile('output.mp4'))
def new_filtered_output(image):
global RingBuffer
inter_frame=somefunction(image)# inter_frame and image shape is same as clip_size
RingBuffer.append(inter_frame)
# Apply kernel
Output = dc + np.sum([np.asarray(RingBuffer)[j]*TempKern[j] for j in range(Depth)],axis=0)
return Output
これは最も速い方法ですか?私は指輪がオプションであると聞きました。しかし、私はそれが上記のコードのように振る舞うようにする方法を知らないのですか?
このバッファのための現実的なサイズは何ですか?内容は常にこのような2次元配列の固定サイズですか? – hpaulj
使用する予定のバッファは(30、1080、720)です。したがって、バッファのmaxlenはここでは012です。 – GKS
合計部分は 'np.einsum( 'ijk、i'、np.array(buf)、TempKern)'や 'tensordot'等価でスチーム化することができます。 – hpaulj