ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROSBAG overriding Extracted Images

asked 2018-05-02 03:30:15 -0500

ARM gravatar image

Hello,

I have a rosbag file which contain images. I am extracting images through the following subscriber.

I extract only one image. I thing it is replacing every new image with the old one. I need to save all images.

Can you point me out where should I make changes.

#! /usr/bin/python

import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import cv2

bridge = CvBridge()

def image_callback(msg):

    print("Received an image!")
    try:

       cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")

    except CvBridgeError, e:
        print(e)
    else:
            cv2.imwrite('~/rec_images/frame.jpeg', cv2_img)

def main():

    rospy.init_node('img_listener')

    image_topic = "/xxxx/image_raw/raw"

    rospy.Subscriber(image_topic, Image, image_callback)

    rospy.spin()

if __name__ == '__main__':
    main()
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-05-02 03:48:21 -0500

ARM gravatar image

This saved my life :=)

cv2.imwrite('~/rec_images/frame_' + str(msg.header.seq) + '.jpeg', cv2_img)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-02 03:30:15 -0500

Seen: 119 times

Last updated: May 02 '18