def __init__(self, world, filename=None, simulator=None, once=False, headless=False): logging.info('Initialising vision') if simulator: self.capture = SimCapture(simulator) else: self.capture = Capture(self.rawSize, filename, once) self.headless = headless self.threshold = threshold.AltRaw() self.pre = Preprocessor(self.rawSize, self.threshold, simulator) self.featureEx = FeatureExtraction(self.pre.cropSize) self.interpreter = Interpreter() self.world = world self.gui = GUI(world, self.pre.cropSize, self.threshold) self.histogram = Histogram(self.pre.cropSize) self.times = [] self.N = 0 #debug.thresholdValues(self.threshold.Tblue, self.gui) logging.debug('Vision initialised')
def initComponents(self, crop=None): undistort = False self.pre = Preprocessor(self.rawSize, self.threshold, undistort, crop=crop) self.featureEx = FeatureExtraction(self.pre.cropSize) self.gui = GUI(self.world, self.pre.cropSize, self.threshold, self) self.world.setResolution(self.pre.cropSize)
class Vision(): rawSize = (640, 480) def __init__(self, world, filenames=None, simulator=None, once=False, headless=False): logging.info('Initialising vision') self.headless = headless self.capture = Capture(self.rawSize, filenames, once) self.threshold = threshold.AltRaw() self.threshold = threshold.PrimaryRaw() self.world = world self.simulator = simulator self.initComponents() self.times=[] self.N=0 logging.debug('Vision initialised') def initComponents(self, crop=None): undistort = False self.pre = Preprocessor(self.rawSize, self.threshold, undistort, crop=crop) self.featureEx = FeatureExtraction(self.pre.cropSize) self.gui = GUI(self.world, self.pre.cropSize, self.threshold, self) self.world.setResolution(self.pre.cropSize) def formatTime(self, t): return time.strftime('%H:%M:%S', time.localtime(t)) \ + ( '%.3f' % (t - math.floor(t)) )[1:] #discard leading 0 def processFrame(self): startTime = time.time() logging.debug("Frame %d at %s", self.N, self.formatTime(startTime) ) self.N += 1 logging.debug("Capturing a frame") frame = self.capture.getFrame() logging.debug("Entering preprocessing") standard = self.pre.get_standard_form(frame) logging.debug("Entering feature extraction") ents = self.featureEx.features(standard, self.threshold) logging.debug("Detected entities:", ents) logging.debug("Entering World") self.world.update(startTime, ents) logging.debug("Updating GUI") if not self.headless: try: self.gui.updateWindow('raw', frame) self.gui.updateWindow('standard', standard) self.gui.draw(ents, startTime) except Exception, e: logging.error("GUI failed: %s", e) raise endTime = time.time() self.times.append( (endTime - startTime) )
def getData(path, requiredFeatures, useExisting): if requiredFeatures is None: requiredFeatures = fa.getAllFeatures() if useExisting: try: return getDataExisting(path, requiredFeatures) except: return getDataNotExisting(path, requiredFeatures) else: return getDataNotExisting(path, requiredFeatures)
def __init__(self, world, filename=None, simulator=None): logging.info('Initialising vision') if simulator: self.capture = SimCapture(simulator) else: self.capture = MPlayerCapture(self.rawSize, filename) #self.capture = Capture(self.rawSize, filename) self.threshold = threshold.PrimaryRaw() self.pre = Preprocessor(self.rawSize, self.threshold, simulator) self.featureEx = FeatureExtraction(self.pre.cropSize) self.interpreter = Interpreter() self.world = world self.gui = GUI(world, self.pre.cropSize, self.threshold) self.histogram = Histogram(self.pre.cropSize) self.times=[] self.N=0 debug.thresholdValues(self.threshold.Tfg, self.gui) logging.debug('Vision initialised')
class Vision(): rawSize = (640, 480) def __init__(self, world, filenames=None, simulator=None, once=False, headless=False): logging.info('Initialising vision') self.headless = headless self.capture = Capture(self.rawSize, filenames, once) self.threshold = threshold.AltRaw() self.threshold = threshold.PrimaryRaw() self.world = world self.simulator = simulator self.initComponents() self.times = [] self.N = 0 logging.debug('Vision initialised') def initComponents(self, crop=None): undistort = False self.pre = Preprocessor(self.rawSize, self.threshold, undistort, crop=crop) self.featureEx = FeatureExtraction(self.pre.cropSize) self.gui = GUI(self.world, self.pre.cropSize, self.threshold, self) self.world.setResolution(self.pre.cropSize) def formatTime(self, t): return time.strftime('%H:%M:%S', time.localtime(t)) \ + ( '%.3f' % (t - math.floor(t)) )[1:] #discard leading 0 def processFrame(self): startTime = time.time() logging.debug("Frame %d at %s", self.N, self.formatTime(startTime)) self.N += 1 logging.debug("Capturing a frame") frame = self.capture.getFrame() logging.debug("Entering preprocessing") standard = self.pre.get_standard_form(frame) logging.debug("Entering feature extraction") ents = self.featureEx.features(standard, self.threshold) logging.debug("Detected entities:", ents) logging.debug("Entering World") self.world.update(startTime, ents) logging.debug("Updating GUI") if not self.headless: try: self.gui.updateWindow('raw', frame) self.gui.updateWindow('standard', standard) self.gui.draw(ents, startTime) except Exception, e: logging.error("GUI failed: %s", e) raise endTime = time.time() self.times.append((endTime - startTime))
def obtainFeatures(ankleData, hipData, features): try: return fa.extract(ankleData, hipData, features) except: return None
class Vision(): #rawSize = (768,576) rawSize = (640, 480) # Whether to 'crash' when something non-critical like the GUI fails debug = True def __init__(self, world, filename=None, simulator=None, once=False, headless=False): logging.info('Initialising vision') if simulator: self.capture = SimCapture(simulator) else: self.capture = Capture(self.rawSize, filename, once) self.headless = headless self.threshold = threshold.AltRaw() self.pre = Preprocessor(self.rawSize, self.threshold, simulator) self.featureEx = FeatureExtraction(self.pre.cropSize) self.interpreter = Interpreter() self.world = world self.gui = GUI(world, self.pre.cropSize, self.threshold) self.histogram = Histogram(self.pre.cropSize) self.times = [] self.N = 0 #debug.thresholdValues(self.threshold.Tblue, self.gui) logging.debug('Vision initialised') def formatTime(self, t): return time.strftime('%H:%M:%S', time.localtime(t)) \ + ( '%.3f' % (t - math.floor(t)) )[1:] #discard leading 0 def processFrame(self): startTime = time.time() logging.debug("Frame %d at %s", self.N, self.formatTime(startTime)) self.N += 1 logging.debug("Capturing a frame") frame = self.capture.getFrame() logging.debug("Entering preprocessing") standard = self.pre.get_standard_form(frame) bgsub_vals, bgsub_mask = self.pre.bgsub(standard) logging.debug("Entering feature extraction") hist_props_bgsub = self.histogram.calcHistogram(standard) hist_props_abs = self.histogram.calcHistogram(bgsub_vals) self.threshold.updateBGSubThresholds(hist_props_bgsub) #self.threshold.updateAbsThresholds(hist_props_abs) ents = self.featureEx.features(bgsub_vals, self.threshold) logging.debug("Detected entities:", ents) logging.debug("Entering interpreter") self.interpreter.interpret(ents) logging.debug("Entering World") self.world.update(startTime, ents) logging.debug("Updating GUI") if not self.headless: try: bgsub = self.pre.remove_background(standard) self.gui.updateWindow('raw', frame) self.gui.updateWindow('mask', bgsub_mask) self.gui.updateWindow('foreground', bgsub_vals) self.gui.updateWindow('bgsub', bgsub) self.gui.updateWindow('standard', standard) canny = cv.CreateImage(self.pre.cropSize, 8, 1) # adaptive = cv.CreateImage(self.pre.cropSize, 32,3) # tmp = cv.CreateImage(self.pre.cropSize, 8,3) # cv.Convert(standard, adaptive) cv.CvtColor(bgsub, canny, cv.CV_BGR2GRAY) cv.Threshold(canny, canny, 150, 255, cv.CV_THRESH_OTSU) # cv.Threshold(canny, canny, 100, 255, cv.CV_ADAPTIVE_THRESH_GAUSSIAN_C) # cv.Sobel(adaptive, adaptive, 1,1,1) # cv.Convert(adaptive, tmp) # cv.ConvertScale(tmp, tmp, 10) # cv.CvtColor(tmp, canny, cv.CV_BGR2GRAY) # cv.Threshold(canny,canny, 50, 255, cv.CV_THRESH_BINARY) #cv.Canny(canny,canny, 100, 180,3) cv.CvtColor(canny, bgsub, cv.CV_GRAY2BGR) new = self.featureEx.detectCircles(bgsub) self.gui.updateWindow('adaptive', canny) self.gui.updateWindow('new', new) self.gui.draw(ents, startTime) except Exception, e: logging.error("GUI failed: %s", e) if self.debug: raise endTime = time.time() self.times.append((endTime - startTime))
def requires(self): return FeatureExtraction()
class Vision(): #rawSize = (768,576) rawSize = (640, 480) # Whether to 'crash' when something non-critical like the GUI fails debug = True def __init__(self, world, filename=None, simulator=None, once=False, headless=False): logging.info('Initialising vision') if simulator: self.capture = SimCapture(simulator) else: self.capture = Capture(self.rawSize, filename, once) self.headless = headless self.threshold = threshold.AltRaw() self.pre = Preprocessor(self.rawSize, self.threshold, simulator) self.featureEx = FeatureExtraction(self.pre.cropSize) self.interpreter = Interpreter() self.world = world self.gui = GUI(world, self.pre.cropSize, self.threshold) self.histogram = Histogram(self.pre.cropSize) self.times=[] self.N=0 #debug.thresholdValues(self.threshold.Tblue, self.gui) logging.debug('Vision initialised') def formatTime(self, t): return time.strftime('%H:%M:%S', time.localtime(t)) \ + ( '%.3f' % (t - math.floor(t)) )[1:] #discard leading 0 def processFrame(self): startTime = time.time() logging.debug("Frame %d at %s", self.N, self.formatTime(startTime) ) self.N += 1 logging.debug("Capturing a frame") frame = self.capture.getFrame() logging.debug("Entering preprocessing") standard = self.pre.get_standard_form(frame) bgsub_vals, bgsub_mask = self.pre.bgsub(standard) logging.debug("Entering feature extraction") hist_props_bgsub = self.histogram.calcHistogram(standard) hist_props_abs = self.histogram.calcHistogram(bgsub_vals) self.threshold.updateBGSubThresholds(hist_props_bgsub) #self.threshold.updateAbsThresholds(hist_props_abs) ents = self.featureEx.features(bgsub_vals, self.threshold) logging.debug("Detected entities:", ents) logging.debug("Entering interpreter") self.interpreter.interpret(ents) logging.debug("Entering World") self.world.update(startTime, ents) logging.debug("Updating GUI") if not self.headless: try: bgsub = self.pre.remove_background(standard) self.gui.updateWindow('raw', frame) self.gui.updateWindow('mask', bgsub_mask) self.gui.updateWindow('foreground', bgsub_vals) self.gui.updateWindow('bgsub', bgsub) self.gui.updateWindow('standard', standard) canny = cv.CreateImage(self.pre.cropSize, 8,1) # adaptive = cv.CreateImage(self.pre.cropSize, 32,3) # tmp = cv.CreateImage(self.pre.cropSize, 8,3) # cv.Convert(standard, adaptive) cv.CvtColor(bgsub, canny, cv.CV_BGR2GRAY) cv.Threshold(canny, canny, 150, 255, cv.CV_THRESH_OTSU) # cv.Threshold(canny, canny, 100, 255, cv.CV_ADAPTIVE_THRESH_GAUSSIAN_C) # cv.Sobel(adaptive, adaptive, 1,1,1) # cv.Convert(adaptive, tmp) # cv.ConvertScale(tmp, tmp, 10) # cv.CvtColor(tmp, canny, cv.CV_BGR2GRAY) # cv.Threshold(canny,canny, 50, 255, cv.CV_THRESH_BINARY) #cv.Canny(canny,canny, 100, 180,3) cv.CvtColor(canny, bgsub, cv.CV_GRAY2BGR) new = self.featureEx.detectCircles(bgsub) self.gui.updateWindow('adaptive', canny) self.gui.updateWindow('new', new) self.gui.draw(ents, startTime) except Exception, e: logging.error("GUI failed: %s", e) if self.debug: raise endTime = time.time() self.times.append( (endTime - startTime) )