AttributeError: 'module' object has no attribute 'Bag'
Program:
import time, sys, os
from ros import rosbag
import roslib, rospy
roslib.load_manifest('sensor_msgs')
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import cv2
TOPIC = 'camera/image_raw'
videopath='/Home/'
bagname='output1.bag'
def CreateVideoBag(videopath, bagname):
'''Creates a bag file with a video file'''
bag = rosbag.Bag(bagname, 'w')
cap = cv2.VideoCapture(videopath)
cb = CvBridge()
prop_fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
if prop_fps != prop_fps or prop_fps <= 1e-2:
print ("Warning: can't get FPS. Assuming 24.")
prop_fps = 24
ret = True
frame_id = 0
while(ret):
ret, frame = cap.read()
if not ret:
break
stamp = rospy.rostime.Time.from_sec(float(frame_id) / prop_fps)
frame_id += 1
image = cb.cv2_to_imgmsg(frame, encoding='bgr8')
image.header.stamp = stamp
image.header.frame_id = "camera"
bag.write(TOPIC, image, stamp)
cap.release()
bag.close()
if __name__ == "__main__":
if len( sys.argv ) == 1:
CreateVideoBag(videopath,bagname)
else:
print( "Usage: video2bag videofilename bagfilename")
bag.close()
Error output
$ python video2bag.py
Error:
Traceback (most recent call last):
File "video2bag.py", line 39, in <module>
CreateVideoBag(videopath,bagname)
File "video2bag.py", line 15, in CreateVideoBag
bag = rosbag.Bag(bagname, 'w')
AttributeError: 'module' object has no attribute 'Bag'
Please help me with above error
Edit:
$ dpkg -l | grep rosbag
ii ros-kinetic-rosbag 1.12.14-0xenial-20180824-103606-0800 amd64 This is a set of tools for recording from and playing back to ROS topics.
ii ros-kinetic-rosbag-migration-rule 1.0.0-0xenial-20180809-134558-0800 amd64 This empty package allows to export rosbag migration rule files without depending on rosbag.
ii ros-kinetic-rosbag-storage 1.12.14-0xenial-20180824-085858-0800 amd64 This is a set of tools for recording from and playing back ROS message without relying on the ROS client library.
Asked by SUBHASH on 2019-03-11 01:12:55 UTC
Comments
@SUBHASH I tried to recreate your problem, but using the code you provided, I don't get the error you paste. (I get another one, but in line 18, so this should be working).
You are using ROS kinetic, considering your tags, right?
Asked by mgruhler on 2019-03-11 02:05:25 UTC
@mgruhler: did this really work for you? I've never seen this:
Asked by gvdhoorn on 2019-03-11 02:59:44 UTC
@SUBHASH: can you show us the output of
dpkg -l | grep rosbag
?Asked by gvdhoorn on 2019-03-11 03:00:15 UTC
$ dpkg -l | grep rosbag
ii ros-kinetic-rosbag 1.12.14-0xenial-20180824-103606-0800 amd64 This is a set of tools for recording from and playing back to ROS topics. ii ros-kinetic-rosbag-migration-rule 1.0.0-0xenial-20180809-134558-0800 amd64 This empty package allows to export rosbag migration rule files without depending on rosbag. ii ros-kinetic-rosbag-storage 1.12.14-0xenial-20180824-085858-0800 amd64 This is a set of tools for recording from and playing back ROS message without relying on the ROS client library. test@DH1CT5Z1:~$
Asked by SUBHASH on 2019-03-11 03:41:56 UTC
I also tried using import rosbag but still same error. Also I don't know how to run python programs on ROS
Asked by SUBHASH on 2019-03-11 03:43:02 UTC
please help me with python coding in ros
Asked by SUBHASH on 2019-03-11 03:43:56 UTC
@gvdhoorn yes, I was as suprised as you are that this works. With the quick tests I did, I wasn't able to spot a difference between this and
import rosbag
...I'm actually on the same versions @SUBHASH is. So I'm even more surprised that this isn't working for him.
@SUBHASH you have source'd your workspace properly, right? Are you using
rosbag
from debians or a from-source version?Asked by mgruhler on 2019-03-11 06:40:59 UTC
yes properly as per mentioned on the official site
Asked by SUBHASH on 2019-03-11 08:04:59 UTC
I want to execute some python programs. How to execute on linux with ros? Please help me.
Asked by SUBHASH on 2019-03-11 09:23:54 UTC