diff --git a/src/analyzer/framecache.py b/src/analyzer/framecache.py new file mode 100644 --- /dev/null +++ b/src/analyzer/framecache.py @@ -0,0 +1,12 @@ +from collections import deque + + +class FrameCache: + def __init__(self,capacity=600): # 600 is enough for 10 min of 1 fps + self._capacity=capacity + self._cache=deque() + + def put(self,frame): + if len(self._cache)>=self._capacity: + self._cache.popleft() + self._cache.append(frame) diff --git a/src/core.py b/src/core.py --- a/src/core.py +++ b/src/core.py @@ -6,6 +6,7 @@ import PIL from util import MsgQueue from gui import gui from analyzer import ImageAnalyzer +from analyzer.framecache import FrameCache from go.core import Go, isLegalPosition from statebag import StateBag import config as cfg @@ -18,6 +19,7 @@ class Core: self.grid=None self.go=Go() self.detector=ImageAnalyzer() + self._cache=FrameCache() self.states=StateBag() self._ownMessages=MsgQueue(self._handleEvent) @@ -50,6 +52,7 @@ class Core: def analyze(self): if self.detector.analyze(self._frame): + self._cache.put(self._frame) if isLegalPosition(self.detector.board): state=self.states.pushState(self.detector.board) rec=[]