Esempio n. 1
0
    def run(self):
        while 1:
            if self.stopping:
                hg.cvDestroyAllWindows()
                return

            try:

                # Check for a new command request
                try:
                    (self.func,
                     self.args,
                     self.kwargs) = self.cmds.get_nowait()
                except Empty:
                    self.func = None

                # Execute function if requested
                if self.func:
                    try:
                        rc = self.func(*self.args, **self.kwargs)
                    except Exception:
                        rc = None
                        sys.stderr.write('ImageThread exception - ignoring:')
                        traceback.print_exc()
                    if self.synchronized:
                        self.result.put(rc)

                # Service the OpenCV event loop - buffer recent keys for
                # possible use by the foreground thread, but bound it to a
                # a small number in case WaitKey isn't called by the thread.
                #
                # Note: This is very CPU-inefficient if we haven't created
                # a window, so only bother if we've seen one created
                if self._have_windows:
                    rc = hg.cvWaitKey(5)
                    if rc >= 0:
                        if self.keys.qsize() >= 10:
                            self.keys.get()
                        self.keys.put(rc)
                else:
                    # Yield CPU to prevent CPU burn
                    time.sleep(0.01)

            except:
                sys.stderr.write('ImageThread exception - shutting down:')
                traceback.print_exc()
Esempio n. 2
0
    def run(self):
        while 1:
            if self.stopping:
                hg.cvDestroyAllWindows()
                return

            try:

                # Check for a new command request
                try:
                    (self.func, self.args,
                     self.kwargs) = self.cmds.get_nowait()
                except Empty:
                    self.func = None

                # Execute function if requested
                if self.func:
                    try:
                        rc = self.func(*self.args, **self.kwargs)
                    except Exception:
                        rc = None
                        sys.stderr.write('ImageThread exception - ignoring:')
                        traceback.print_exc()
                    if self.synchronized:
                        self.result.put(rc)

                # Service the OpenCV event loop - buffer recent keys for
                # possible use by the foreground thread, but bound it to a
                # a small number in case WaitKey isn't called by the thread.
                #
                # Note: This is very CPU-inefficient if we haven't created
                # a window, so only bother if we've seen one created
                if self._have_windows:
                    rc = hg.cvWaitKey(5)
                    if rc >= 0:
                        if self.keys.qsize() >= 10:
                            self.keys.get()
                        self.keys.put(rc)
                else:
                    # Yield CPU to prevent CPU burn
                    time.sleep(0.01)

            except:
                sys.stderr.write('ImageThread exception - shutting down:')
                traceback.print_exc()
Esempio n. 3
0
 def DestroyAllWindows(self):
     hg.cvDestroyAllWindows()
Esempio n. 4
0
 def DestroyAllWindows(self):
     hg.cvDestroyAllWindows()