Changeset - f4097dbb3757
[Not reviewed]
default
0 1 1
Laman - 6 years ago 2018-12-06 23:17:05

FrameCache
2 files changed with 15 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/analyzer/framecache.py
Show inline comments
 
new file 100644
 
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)
src/core.py
Show inline comments
 
@@ -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=[]
0 comments (0 inline, 0 general)