def __init__(self): super().__init__(name='camera') self.mStopEvent = threading.Event() self.mCamera = cv2.VideoCapture(0) self.mCookie = uuid.uuid1() self.mBlackboard = TBlackBoard() self.mBlackboard.addInterest(self.mCookie) self.mTable = TTable() self.mName = 'picture{}.jpg' self.mDict = {'sourcefile':'picture1.jpg'} pass
This program comes with ABSOLUTELY NO WARRANTY;'. This is free software, and you are welcome to redistribute it under certain conditions;. """) # Parse command line options aOptParser = OptionParser() aOptParser.add_option("-d", "--host", dest="aHttpHost", default="localhost", help="HTTP Hostname") aOptParser.add_option("-p", "--port", dest="aHttpPort", default="8000", help="HTTP Port") aOptParser.add_option("-w", "--webroot", dest="aWebRoot", default="webroot", help="Web-Root") aOptParser.add_option("-x", "--websocket", dest="aWebSocket", default="8100", help="Web-Socket Port") (aOptions, aArgs) = aOptParser.parse_args() xPath = os.path.join(aOptions.aWebRoot, 'public') aBlackBoard = TBlackBoard() aBlackBoard.mDocRoot = xPath aBlackBoard.mRootPath = xPath if os.path.isdir(xPath): os.chdir(xPath) else: print('webroot not found: {}'.format(xPath)) os._exit(0) aHttpd = TWebServer((aOptions.aHttpHost, int(aOptions.aHttpPort)), THttpHandler, aOptions.aWebSocket) # Start the HTTP server print("serving {0} at port {1} ...".format(aOptions.aHttpHost, aOptions.aHttpPort)) aHttpd.serve_forever() print('shutdown')
class TCamera(threading.Thread): # -------------------------------------------------------- # -------------------------------------------------------- def __init__(self): super().__init__(name='camera') self.mStopEvent = threading.Event() self.mCamera = cv2.VideoCapture(0) self.mCookie = uuid.uuid1() self.mBlackboard = TBlackBoard() self.mBlackboard.addInterest(self.mCookie) self.mTable = TTable() self.mName = 'picture{}.jpg' self.mDict = {'sourcefile':'picture1.jpg'} pass # -------------------------------------------------------- # -------------------------------------------------------- def read(self): return self.mCamera.read() # -------------------------------------------------------- # -------------------------------------------------------- def release(self): self.mCamera.release() # -------------------------------------------------------- # -------------------------------------------------------- def run(self): xCounter = 0 while True: xCounter += 1 xPicture = self.mName.format(xCounter) xInterest = self.mBlackboard.getInterest(self.mCookie) if xInterest and xInterest.get('sender') == 'system': if xInterest.get('system') == 'shutdown': break xResult, xFrame = self.mCamera.read() cv2.imwrite(xPicture, xFrame) if self.mStopEvent.wait(2): break self.mDict.update({'sourcefile':xPicture}) self.mBlackboard.addMesage(self.mCookie, 'camera') try: if xCounter >= 4: xDelete = xCounter - 4 os.remove(self.mName.format(xDelete)) except: pass self.mCamera.release() cv2.destroyAllWindows() pass # -------------------------------------------------------- # -------------------------------------------------------- def get_camera(self): return {'return':{'code':200, 'value': self}} # -------------------------------------------------------- # -------------------------------------------------------- def get_dictionary(self): return {'return': {'code':200, 'value': self.mDict}}
def get_dictionary(self): return dict() # ------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------ def globalfnct(): try: print(xList['test']) except Exception as xEx: xTracer.writeException(1, {"return":{"code":600, "value":"error"}}) # raise # ------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------ if __name__ == '__main__': xList = {} xBlackboard = TBlackBoard() xBlackboard.mRootPath = os.path.join('/', 'temp') xTracer = TTracer() for i in range(5): globalfnct() xSessions = xTracer.get_selected_sessions(convert_time=True) xSessions.printTable() xTraces = xTracer.get_selected_traces(1) xTraces.printTable() pass