Error in using pyrosbag?

asked 2019-03-26 22:39:10 -0500

Ghost gravatar image

Hello everyone I am trying make a bag file of rgb images and depth images that are saved in .mat file (h5py fomat), in Ubuntu 16.04 and ROS kinetic with pycharm IDE.

import pyrosbag
import h5py
import numpy as np
path_to_depth = '/home/maq/PycharmProjects/ROS_bagfile/test.mat'

f = h5py.File(path_to_depth)

img = f['rgb_undist'][1]
img_ = np.empty([480, 640, 3])
img_[:, :, 0] = img[0, :, :].T
img_[:, :, 1] = img[1, :, :].T

img_[:, :, 2] = img[2, :, :].T
img__ = img_.astype('float32')

bag = pyrosbag.Bag('test.bag')

But ther is error on the play command, I have taken help from here.

Error is

/usr/bin/python2.7 /home/maq/PycharmProjects/ROS_bagfile/
Traceback (most recent call last):
  File "/home/maq/PycharmProjects/ROS_bagfile/", line 22, in <module>
TypeError: unbound method play() must be called with BagPlayer instance as first argument (got nothing instead)

Process finished with exit code 1

Can anyone help me with this or guide me with some other effective method that could be done in pycharm.


edit retag flag offensive close merge delete



Maybe you need to do bag = pyrosbag.BagPlayer('test.bag') and then ?

ahendrix gravatar image ahendrix  ( 2019-03-26 23:13:31 -0500 )edit

Thanks for a quick reply, I tried this but I guess it needs to be saved. Can you guide me how to save it first and then load it may be??

Ghost gravatar image Ghost  ( 2019-03-26 23:27:04 -0500 )edit

Ah, it looked like you were trying to play back a bag file. It looks like pyrosbag can only play existing bag files; it doesn't look like it can create them. You may want to use the official rosbag API to write bag files.

ahendrix gravatar image ahendrix  ( 2019-03-26 23:43:44 -0500 )edit

That is what exactly I was trying to do, but somehow I could not import rosbag into my pycharm, so I looked for an alternative which is pyrosbag, available in Pycharm. But encountered the above error. If you could guide me how to import rosbag into Pycharm that will be of great help.

Ghost gravatar image Ghost  ( 2019-03-26 23:50:52 -0500 )edit

I don't know much about pycharm, but there are instructions on about how to set up pycharm to work with ROS.

ahendrix gravatar image ahendrix  ( 2019-03-26 23:54:08 -0500 )edit