Error in using pyrosbag?
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')
pyrosbag.BagPlayer.play()
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/ros_bagfile.py
Traceback (most recent call last):
<Bag(['test.bag'])>
File "/home/maq/PycharmProjects/ROS_bagfile/ros_bagfile.py", line 22, in <module>
pyrosbag.BagPlayer.play()
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.
Regards.
Maybe you need to do
bag = pyrosbag.BagPlayer('test.bag')
and thenbag.play()
?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??
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.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.
I don't know much about pycharm, but there are instructions on http://wiki.ros.org/IDEs#PyCharm_.28c... about how to set up pycharm to work with ROS.