associate.py 源代码 及 使用方法
ORB_SLAM2运行RGBD数据集需要使用图片序列信息
使用以下代码进行汇集:
#!/usr/bin/python
# Software License Agreement (BSD License)
#
# Copyright (c) , Juergen Sturm, TUM
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of TUM nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Requirements:
# sudo apt-get install python-argparse """
The Kinect provides the color and depth images in an un-synchronized way. This means that the set of time stamps from the color images do not intersect with those of the depth images. Therefore, we need some way of associating color images to depth images. For this purpose, you can use the ''associate.py'' script. It reads the time stamps from the rgb.txt file and the depth.txt file, and joins them by finding the best matches.
""" import argparse
import sys
import os
import numpy def read_file_list(filename):
"""
Reads a trajectory from a text file. File format:
The file format is "stamp d1 d2 d3 ...", where stamp denotes the time stamp (to be matched)
and "d1 d2 d3.." is arbitary data (e.g., a 3D position and 3D orientation) associated to this timestamp. Input:
filename -- File name Output:
dict -- dictionary of (stamp,data) tuples """
file = open(filename)
data = file.read()
lines = data.replace(","," ").replace("\t"," ").split("\n")
list = [[v.strip() for v in line.split(" ") if v.strip()!=""] for line in lines if len(line)> and line[]!="#"]
list = [(float(l[]),l[:]) for l in list if len(l)>]
return dict(list) def associate(first_list, second_list,offset,max_difference):
"""
Associate two dictionaries of (stamp,data). As the time stamps never match exactly, we aim
to find the closest match for every input tuple. Input:
first_list -- first dictionary of (stamp,data) tuples
second_list -- second dictionary of (stamp,data) tuples
offset -- time offset between both dictionaries (e.g., to model the delay between the sensors)
max_difference -- search radius for candidate generation Output:
matches -- list of matched tuples ((stamp1,data1),(stamp2,data2)) """
first_keys = first_list.keys()
second_keys = second_list.keys()
potential_matches = [(abs(a - (b + offset)), a, b)
for a in first_keys
for b in second_keys
if abs(a - (b + offset)) < max_difference]
potential_matches.sort()
matches = []
for diff, a, b in potential_matches:
if a in first_keys and b in second_keys:
first_keys.remove(a)
second_keys.remove(b)
matches.append((a, b)) matches.sort()
return matches if __name__ == '__main__': # parse command line
parser = argparse.ArgumentParser(description='''
This script takes two data files with timestamps and associates them
''')
parser.add_argument('first_file', help='first text file (format: timestamp data)')
parser.add_argument('second_file', help='second text file (format: timestamp data)')
parser.add_argument('--first_only', help='only output associated lines from first file', action='store_true')
parser.add_argument('--offset', help='time offset added to the timestamps of the second file (default: 0.0)',default=0.0)
parser.add_argument('--max_difference', help='maximally allowed time difference for matching entries (default: 0.02)',default=0.02)
args = parser.parse_args() first_list = read_file_list(args.first_file)
second_list = read_file_list(args.second_file) matches = associate(first_list, second_list,float(args.offset),float(args.max_difference)) if args.first_only:
for a,b in matches:
print("%f %s"%(a," ".join(first_list[a])))
else:
for a,b in matches:
print("%f %s %f %s"%(a," ".join(first_list[a]),b-float(args.offset)," ".join(second_list[b])))
使用方法:
python associate.py ×××/rgb.txt ×××/depth.txt > associate.txt
associate.py 源代码 及 使用方法的更多相关文章
- golang编译源代码和交叉编译方法
目录 golang编译源代码和交叉编译方法 编译源代码 编译go1.4 编译go1.12 交叉编译 golang编译源代码和交叉编译方法 编译源代码 golang编译其实很简单,下载一份最新的源代码后 ...
- Android 4.4 全套源代码及子模块源代码的下载方法
博文<Android源代码下载--用git clone实现单个文件夹下载>介绍了採用git clone方法下载Android单个文件夹源代码的方法,这篇文章已经有四年的历史,这期间Goog ...
- django中将views.py中的python方法传递给html模板文件
常规的模板渲染 from django.db import models # Create your models here. class ArticalType(models.Model): cap ...
- 关于Ext 修复源代码 bug的方法
Ext修复源代码出现的问题 1.使用override属性,重写组件 定义一个新的组件,override属性设为要重写的源组件 例子: Extjs4.2.3遇到的一个bug,Datefield 选择不了 ...
- [py][mx]django get方法返回login页面
get方法返回login.html users/views.py def login(request): if request.method == "POST": pass eli ...
- Eclipse Android源代码新下载方法及关联
一.下载Android源代码 Android源代码从4.0后就可以使用SDK Manager进行下载,打开SDK Manager就可以看到,已4.4为例: 关联Android源代码 但是老是提示下载失 ...
- [py]类的专有方法
陆陆续续总结一些用到的类的特殊方法 看源码总会看到一些奇奇怪怪的写法: 掺杂着设计模式 https://coding.net/u/RuoYun/p/Python-design-pattern/git/ ...
- python3.X 安装web.py 失败的解决方法
python2.x 安装python是非常顺利的 但是 在进行 pip3 install web.py 时提示很多错误 例如缺少模块 语法错误...... 最后试了一下web.py 的dev版本 pi ...
- 【Linux】CentOS7中yumbackend.py进程的结束方法
环境: CentOS Linux release 7.3.1611 (Core) 今天启动这个不怎么用的机器,才启动,就发现后台的yum无法进行安装,持续报这个错误 Loaded plugins: f ...
随机推荐
- Emacs Python 自动补全之 jedi
jedi jedi 的安装配置并不是很友好.github 上也没有明确说明.查了很多资料, 最后才配置成功.可是效果却不是很理想.在补全的时候有明显的卡顿现象. 不知道网上这么多人对其推崇备至是因为什 ...
- matplotlib之折线图
1.案例一 # coding=utf-8 from matplotlib import pyplot as plt import random # 设置字体相关 from matplotlib imp ...
- <table>表格与jqGrid
第一次写博客比较生涩.接下来进入正题:...... 普通表格前端的增删改查. <%@ page language="java" contentType="text/ ...
- 阶段3 2.Spring_06.Spring的新注解_6 Qualifier注解的另一种用法
复制上面的数据源到下面改改名字 现在就是有两个数据源 创建一个eesy02的数据库 找到sql语句再创建Account表 现在就相当于有连个库一个eesy一个是eesy02这连个库. account里 ...
- Linux下搭建Git服务器
1.安装Git 见 Jenkins持续集成环境部署 第四节 2.创建Git用户和用户组 groupadd git useradd git -g git 3.创建证书切换到git用户创建证书 su gi ...
- java:Mybatis框架2(基于mapper接口的开发,多种查询,复合类型查询,resultMap定义,多表联查,sql片段)
1.mybatis02: mybatis-config.xml: <?xml version="1.0" encoding="UTF-8"?> &l ...
- docker 安装 nexus
docker pull sonatype/nexus3 用docker-compose 部署 创建目录 /usr/local/docker/nexus 在目录下 创建docker-compose.ym ...
- ca认证(https)
证书签名过程: 1.网页服务器生成证书请求文件: 2.认证中心确认申请者的身份真实性: 3.认证中心使用根证书的私钥加密证书请求文件,生成证书: 4.把证书传给申请者. 一.实验环境 node1 19 ...
- flask 必知必会
在局域网中让其它电脑访问我的网站 from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): re ...
- Neo4j下载与使用
Neo4j 官网 : https://neo4j.com/ Neo4j 国内: http://neo4j.com.cn/topic/5b003eae9662eee704f31cee http://we ...