Here are the two code blocks:
class WindowManager(object):
def __init__(self, windowName, keypressCallback = None):
self.keypressCallback = keypressCallback
self._windowName = windowName
self._isWindowCreated = False
@property
def isWindowCreated(self):
return self._isWindowCreated
def createWindow(self):
cv2.namedWindow(self._windowName)
self._isWindowCreated = True
def show(self, frame):
cv2.imsmhow(self._windowName, frame)
def destroyWindow(self):
cv2.destroyWindow(self._windowName)
self._isWindowCreated = False
def processEvents(self):
keycode = cv2.waitKey(1)
if self.keypressCallback is not None and keycode != -1:
self.keypressCallback(keycode)
class Cameo(object):
def __init__(self):
self._windowManager = WindowManager('Cameo', self.onKeypress)
self._captureManager = CaptureManager(cv2.VideoCapture(0), self._windowManager, True)
#Defining the run method:
def run(self):
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
if frame is not None:
self._captureManager.exitFrame()
self._windowManager.processEvents()
#Define the onKeypress method:
def onKeypress(self, keycode):
if keycode == 32:
self._captureManager.writeImage('screenshot.png')
elif keycode == 9:
if not self._captureManager.isWritingVideo:
self._captureManager.startWritingVideo('screencast.avi')
else:
self._captureManager.stopWritingVideo()
elif keycode == 27:
self._windowManager.destroyWindow()
#Adding a main block that instatiates and runs cameo
if __name__=="__main__":
Cameo().run()
I am trying to run my code but I keep getting the attribute error even tho the attribute I am calling is defined as part of the classes properties. An answer would be much appreciated.
it's a simple indentation error.
all your WindowManager
attributes are defined inside your __init__()
function
(so they are invisible to the rest of your program)