def read_all_patches_from_log(fileName, type=0): # initialize the parser my_parser = Parser() # register the protobuf message name for the 'ImageTop' my_parser.register("ImageTop", "Image") my_parser.register("BallCandidatesTop", "BallCandidates") my_parser.register("CameraMatrixTop", "CameraMatrix") # get all the images from the logfile # images = map(getPatches, LogReader(fileName, my_parser)) camera_index = [] patches = [] for frame in LogReader(fileName, my_parser): ball_candidates = frame["BallCandidates"] for p in ball_candidates.patches: if p.type == type: data = numpy.fromstring(p.data, dtype=numpy.uint8) patches.append(data) camera_index.append([0]) ball_candidates_top = frame["BallCandidatesTop"] for p in ball_candidates_top.patches: if p.type == type: data = numpy.fromstring(p.data, dtype=numpy.uint8) patches.append(data) camera_index.append([1]) return patches, camera_index
def parse(self, name, data): self.current_options = {} if name == 'BehaviorStateComplete': message = Parser.parse(self, name, data) # process options self.options = message.options # process symbols for s in message.inputSymbolList.decimal: self.symbols.values[s.name] = s.value self.symbols.decimalIdToName[s.id] = s.name for s in message.inputSymbolList.boolean: self.symbols.values[s.name] = s.value self.symbols.booleanIdToName[s.id] = s.name for s in message.inputSymbolList.enumerated: self.symbols.values[s.name] = s.value self.symbols.enumIdToName[s.id] = s.name return self.symbols.values, self.current_options elif name == 'BehaviorStateSparse': message = Parser.parse(self, name, data) symbols_values = self.symbols.values.copy() # process active options for o in message.activeRootActions: self.parseOption(o) # process symbols for s in message.inputSymbolList.decimal: name = self.symbols.decimalIdToName[s.id] symbols_values[name] = s.value for s in message.inputSymbolList.boolean: name = self.symbols.booleanIdToName[s.id] symbols_values[name] = s.value for s in message.inputSymbolList.enumerated: name = self.symbols.enumIdToName[s.id] symbols_values[name] = s.value return symbols_values, self.current_options else: return Parser.parse(self, name, data)
edgelsPlot = [ plt.scatter([], [], point_size), plt.scatter([], [], point_size) ] ax = fig.add_subplot(1, 2, 2, aspect='equal') ax.set_xlim([-10000, 10000]) ax.set_ylim([-10000, 10000]) projectedEdgelsPlot = [ plt.scatter([], [], point_size, color='black'), plt.scatter([], [], point_size, color='orange') ] linePlot = LinePlot(ax, (-10000, 10000), (-10000, 10000)) # init parser logParser = Parser() logParser.register("ScanLineEdgelPerceptTop", "ScanLineEdgelPercept") logParser.register("CameraMatrixTop", "CameraMatrix") log = iter(LogReader(args.logfile, logParser, getEdgels)) # start animation ani = animation.FuncAnimation(fig, animate, frames=100, fargs=(log, edgelsPlotTop, linePlot, edgelsPlot, projectedEdgelsPlot), interval=66) plt.show()
#!/usr/bin/python from naoth.LogReader import LogReader from naoth.LogReader import Parser def get_camera_matrix(frame): cm_bottom = frame["CameraMatrix"] cm_top = frame["CameraMatrixTop"] return [frame.number, cm_bottom, cm_top] def get_edgels(frame): edgel_percepts = frame["ScanLineEdgelPercept"] return [frame.number, edgel_percepts] if __name__ == "__main__": myParser = Parser() myParser.register("CameraMatrixTop", "CameraMatrix") for msg in LogReader("./game.log", myParser, get_edgels): print(msg)
#!/usr/bin/python from naoth.LogReader import LogReader from naoth.LogReader import Parser def get_audio(frame): return frame["AudioData"] if __name__ == "__main__": myParser = Parser() newFile = open("audio.raw", "wb") timestamp = 0 for s in LogReader("./test_new_recorder.log", myParser, get_audio): if s.timestamp > timestamp: timestamp = s.timestamp #print (type(s.samples)) print (timestamp) newFile.write(s.samples) newFile.close()
def __init__(self): Parser.__init__(self) self.symbols = XABSLSymbols() self.options = [] self.current_options = {}