GithubHelp home page GithubHelp logo

Comments (4)

traum100 avatar traum100 commented on June 12, 2024 1

Screenshot from 2020-05-29 16-25-56

I did it.
Algorithm works very well
Thank you!!

from scale_optimization.

jiawei-mo avatar jiawei-mo commented on June 12, 2024

Hi, thanks for your attention to this algorithm.
The current implementation is based on ROS, the data is organized as a rosbag file. Check launch/sample.launch how to launch the algorithm.

Below is the script I used to use to convert stereo images to a rosbag. You need to modify it to fit your data format. I hope it helps:

import sys
import os
import cv2
import rospy
import rosbag
import progressbar
import argparse
import glob
from std_msgs.msg import Header
from cv_bridge import CvBridge
        
def save_camera_data(image_path, bag, bridge, camera_frame_id, topic):
    print(image_path)
    image_filenames = sorted(os.listdir(image_path))

    bar = progressbar.ProgressBar()
    for filename in bar(image_filenames):
        image_filename = os.path.join(image_path, filename)
        cv_image = cv2.imread(image_filename, 0)
        cv_image = cv2.cvtColor(cv_image, cv2.COLOR_BayerRG2RGB)
        cv_image = cv2.cvtColor(cv_image, cv2.COLOR_RGB2GRAY)
        encoding = "mono8" 
        image_message = bridge.cv2_to_imgmsg(cv_image, encoding=encoding)
        image_message.header.frame_id = camera_frame_id
        image_message.header.stamp = rospy.Time.from_sec(float(os.path.splitext(filename)[0])*1e-9)
        topic_ext = "/image_raw"
        bag.write(topic + topic_ext, image_message, t = image_message.header.stamp)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description = "Convert images to ROS bag file!")
    
    parser.add_argument("--left_dir", help = "directory of the left images")
    parser.add_argument("--right_dir", help = "directory of the right images")
    parser.add_argument("--bag", help = "directory of the output bag file")
    args = parser.parse_args()

    if not os.path.exists(args.left_dir):
        print('Path {} does not exists. Exiting.'.format(args.left_dir))
        sys.exit(1)

    if not os.path.exists(args.right_dir):
        print('Path {} does not exists. Exiting.'.format(args.right_dir))
        sys.exit(1)

    bag = rosbag.Bag(args.bag, 'w', compression=rosbag.Compression.NONE)
    bridge = CvBridge()
    try:
        save_camera_data(args.left_dir, bag, bridge, 'camera_left', '/left')
        save_camera_data(args.right_dir, bag, bridge, 'camera_right', '/right')

    finally:
        print("## OVERVIEW ##")
        print(bag)
        bag.close()

from scale_optimization.

traum100 avatar traum100 commented on June 12, 2024

Please make sure what I understand.

  1. Convert the image files into a rosbag using the script.
  2. launch program
  3. rosbag play

I'll try it. thank you.

from scale_optimization.

jiawei-mo avatar jiawei-mo commented on June 12, 2024

Correct. But you need to modify the script a bit since some lines are hardcoded (e.g., rospy.Time.from_sec(float(os.path.splitext(filename)[0])*1e-9)).

from scale_optimization.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.