Hey,
I am trying to read the trajectory data in *.pbstream file in python. I am able to to read the identifier number and the size of the data but i'm stuck parsing the uncompressed data to meaning full pose information. My python code so far looks like
#!/usr/bin/env python
import os
import sys
import gzip
import struct
import numpy as np
import zlib
def pbstreamreader(posefile):
print "Reading .pbstream data"
idnumber = '0x7b1d1f7b5bf501db'
filehandle = open(posefile, 'rb')
# make sure the data
size = readthefile(filehandle)
if idnumber!= size:
print "unknown string"
return
#get the total size of the data
size = readthefile(filehandle)
print int(size,0)
compressed_trajectory_data = readdatafromfile(filehandle,int(size,0))
trajectory_data = zlib.decompress(compressed_trajectory_data,16+zlib.MAX_WBITS)
# read the entire data of the file
data = struct.unpack_from('b',trajectory_data)
print data
filehandle.close()
def readthefile(fileobj):
size =0
byte=None
word = []
for i in range(0,8):
byte = fileobj.read(1).encode("hex")
word.append(byte)
word = word[::-1]
word = '0x'+''.join(word)
return word
def readdatafromfile(fileobj, size):
return fileobj.read(size)
def main():
if len(sys.argv)!=2:
print "Incorrect usage. generateassetsfrombag.py <path/to/the/*.pbstream>"
return
pbstreamreader(sys.argv[1])
if __name__=='__main__':
main()
from the proro_stream.h, I believe that the data is being parsed from string to a buffer with
proto->ParseFromString(decompressed_data)
where
`ParseFromString` seems to be a protobuf api. So, do I need to use protobuf Api to read the pose? My goal is to created an vector of all Poses of the robot.
From the
github link they suggest to use gzip and struct to achieve the same. the o/p of the struct.upack doesn't seem to be correct.
I'm not sure if I am on the right track and how to proceed further. I am kinda confused.
Any help is greatly appreciated.
Thanks
Akshay