背景: 最近在研究BundleFusion,跑通官方数据集后,就想着制作自己的数据集来运行bundlefusion.KinectV2相机可直接获取的图像的分辨率分为三个HD 1920x1080, QHD: 960X540,SD: 512x424.我选择是中间的分辨率qhd.

录制了一段时间我去查看,彩色图和深度图,发现两者的帧数不相同,我就很纳闷了,还想着用什么方法对两个进行同步处理,但是我去查看了一下TUM数据集,发现数据集里面的深度图和彩色图的帧数也不相同,我恍然大悟,在orb-slam2运行tum数据集时,需要使用TUM数据集中的associate.py脚本,按照时间戳的远近将深度图和彩色图匹配起来,得到associate.txt文件,这个里面是彩色图时间戳,以时间戳命名的图像的名字,以及对应这个彩色图的深度图的时间戳,和以这个时间戳命名的图像的名字.这样在运行代码的时候就按照这个匹配结果去文件夹下读取相应的图像.

可以在我的git上下载完整代码,然后放到你的catkin_ws/src下然后catkin_make进行编译

https://github.com/Serena2018/save_color_depth_from_kinect2_with_ros

当然你需要提前配置好libfreenect2和iai-kinect2,然后运行roslaunch kinect2_bridge kinect2_bridge.launch

然后使用 rostopic list 查看当前系统上发布出来的话题.

这样运行上面下载的代码就可以订阅发布出来的彩色图像和深度图像的数据.

然后我使用了TUM数据集提供的associate.py工具,在保存下来的图像中找到对应,得到associate.txt文件,然后直接读取这个文件,去文件目录下找相应的图像,并按照bundlefusion需要的图像的命名格式对图像进行重命名,将重命名后的图像保存到新路径下

## in another script we have find the association of color and depth and now
## in this script we will pick the correspondents of color and depth images
## according their timestamps then rename them according the standards of
##  bundlefusion dataset and then store them in separate folders.## step one: read the assoc.txt into this project.import sys
import os
import shutildef 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 nameOutput:dict -- dictionary of (stamp,data) tuples"""file = open(filename)data = file.read()lines = data.replace(",", " ").replace("\t", " ").split("\n")#strip() function can be used to remove space located in the head or the tail places of a string# v.strip('0')remove 0# list = [[v.strip() for v in line.split(" ") if v.strip() != ""] for line in lines if#         len(line) > 0 and line[0] != "#"]# list = [(float(l[0]), l[1:]) for l in list if len(l) > 1]list= []listResult = []for line in lines:tmpList = []if len(line) > 0 and line[0] != "#":for v in line.split(" "):if v.strip() != "":tmpList.append(v.strip())list.append(tmpList)for l in list:if len(l) > 1:listResult.append((float(l[0]), l[1:]))return dict(listResult)def associate(first_list, second_list, offset, max_difference):"""Associate two dictionaries of (stamp,data). As the time stamps never match exactly, we aimto find the closest match for every input tuple.Input:first_list -- first dictionary of (stamp,data) tuplessecond_list -- second dictionary of (stamp,data) tuplesoffset -- time offset between both dictionaries (e.g., to model the delay between the sensors)max_difference -- search radius for candidate generationOutput:matches -- list of matched tuples ((stamp1,data1),(stamp2,data2))"""## obatin all keysfirst_keys = list(first_list)second_keys = list(second_list)potential_matches = [(abs(a - (b + offset)), a, b)for a in first_keysfor b in second_keysif 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 matchesdef read_data_from_file(file_path):associ_file = open(file_path)data = associ_file.read()lines = data.replace(',', ' ').replace('\t', ' ').split('\n')print(f"read {len(lines)} from {file_path}.")# come here we have obtain every line of this associ.txt and in each line we can index arbitrary part of it# we mainly work on the first and the third part and then to find the correspondent color and depth image,# and the rename them and store them.list = [[v.strip() for v in line.split(" ") if v.strip() != " "] for line in lines if len(line) > 0 and line[0] != "#"]return listdef load_images_rename_store(file_data, image_folder, output_folder):print(f"The length of file is {len(file_data)}.")print(f"the path of image_folder is {image_folder}.")print(f"the path of output_folder is {output_folder}.")rgb_path = image_folder + "/rgb/"depth_path = image_folder + "/depth/"print("**********************")rgbs = os.listdir(rgb_path)# print(len(rgbs))# for rgb in sorted(rgbs):#     print(rgb)print("**********************")depths = os.listdir(depth_path)# print(len(depths))# for depth in sorted(depths):#     print(depth)couples = []print("............................")for data in file_data:couple_list = []##I must search the frame name in the folder by the exactly name from the filergb_name = data[1].split("/")[1]depth_name = data[3].split("/")[1]couple_list.append(rgb_name)couple_list.append(depth_name)couples.append(couple_list)print(f"length of couples is {len(couples)}.")# for couple in sorted(couples):#     print(couple)frame_id = 0for couple in sorted(couples):if couple[0] in sorted(rgbs) and couple[1] in sorted(depths):print(f"\nframe_id is {frame_id}.\n")print(rgb_path + "/" + couple[0])print(output_folder + "/rgb/" + "frame-" + str(frame_id).zfill(6) + ".color.png")print("\n")print(depth_path + "/" + couple[1])print(output_folder + "/depth/" + "frame-" + str(frame_id).zfill(6) + ".depth.png")shutil.copyfile(rgb_path + "/" + couple[0], output_folder + "/rgb/" + "frame-" + str(frame_id).zfill(6) + ".color.png")shutil.copyfile(depth_path + "/" + couple[1], output_folder + "/depth/" + "frame-" + str(frame_id).zfill(6) + ".depth.png")frame_id = frame_id + 1## argvs: file_path, images_path, output_path
if __name__ == '__main__':if len(sys.argv) == 8:path_rgb_file = sys.argv[1]path_depth_file = sys.argv[2]associate_file_name = sys.argv[3]offset = sys.argv[4]max_diff = sys.argv[5]image_path = sys.argv[6]output_path = sys.argv[7]first_list = read_file_list(path_rgb_file)second_list = read_file_list(path_depth_file)matches = associate(first_list, second_list, float(offset), float(max_diff))filename = image_path + associate_file_name# when you use with open you don't need to use close.with open(filename, 'w') as fp:for a, b in matches:fp.write("%f %s %f %s" % (a, " ".join(first_list[a]), b - float(offset), " ".join(second_list[b])) + '\n')# fp = open(filename, 'w')# for a, b in matches:#     fp.write(#         "%f %s %f %s" % (a, " ".join(first_list[a]), b - float(offset), " ".join(second_list[b])) + '\n')#     print("%f %s %f %s" % (a, " ".join(first_list[a]), b - float(offset), " ".join(second_list[b])))# fp.close()file_path = image_path + associate_file_namelist = read_data_from_file(file_path)load_images_rename_store(list, image_path, output_path)else:print("usage: path_rgb.txt path_depth.txt offset(0 default) max_diff(0.02 default), images_path, output_path")

ROS获取KinectV2相机的彩色图和深度图并制作bundlefusion需要的数据集相关推荐

  1. ROS下获取kinectv2相机的仿照TUM数据集格式的彩色图和深度图

    准备工作: 1. ubuntu16.04上安装iai-kinect2, 2. 运行roslaunch kinect2_bridge kinect2_bridge.launch, 3. 运行 rosru ...

  2. Open3d利用彩色图和深度图生成点云进行室内三维重建

    上一次得到的点云图在累加多张后配准会出现少量离群的点云,效果很差,于是考虑从 ICL-NUIM dataset这个数据集获得官方的室内图进行三维重建,数据集网址如下: ICL-NUIM RGB-D B ...

  3. 图像处理中涉及的灰度图、彩色图以及深度图概念

    图像处理中涉及最多的概念就是图像的类型,为了很好的理解图像的概念以及处理图片,我们就需要对常见的图像具有一定的概念. 我们首先介绍一下生活中常见的图像格式: 1.bmp格式:这是一种不常见的图像格式, ...

  4. kinect linux 深度处理,kinect彩色图和深度图对齐(一)

    本文主要记录kinect相关的知识和对齐方法,这是第一部分,此记. 深度相机成像方法简介 深度相机就是可以获取场景中物体距离摄像头物理距离的相机.深度相机通常由多种镜头和光学传感器组成,根据测量原理不 ...

  5. 使用iai_kinect2标定kinectV2相机

    实验背景:因为需要制作bundlefusion需要的数据集,所以需要使用kinectV2相机获取rgbd图像,年前的时候在我的笔记本上安装了libfreenect2库和iai_kinect2,标定过一 ...

  6. Ubuntu20.04 ROS读取basler相机图像步骤。MATLAB2021b标定basler单目相机

    运行环境:Ubuntu20.04(64-Bit) ROS版本:Noetic 网卡型号:Realtek RTL 8156外置网卡 相机型号:acA 1920-25gc (GigE接口) 驱动版本:pyl ...

  7. 奥比中光 astra 乐视三合一体感摄像头采集深度图彩色图并保存

    本文参考的文章: 目录 ROS下开发 运行ROS节点 查看相机的话题及画面 订阅画面并保存 Python环境下开发 调用摄像头并保存采集画面 C++环境下开发 C++环境配置 代码编译 ROS下开发 ...

  8. 乐视三合一体感摄像头Astra pro开发记录1(深度图、彩色图及点云简单显示)

    在某鱼上淘的乐视三合一体感摄像头,捡漏价九十几块,买来玩玩. 网上已经有一些关于此款摄像头的开发资料. 官方的开发资料:官网链接 按官方网站以及其他帖子,下载并安装相机的驱动和SDK,不难配置好相机. ...

  9. 使用ros发布UVC相机和串口IMU数据

    1.目的:为了可以标定普通USB相机和固定在相机上的外置IMU的外参,我希望通过ROS获取更高分辨率和更高频率的图像数据,并且可以将图像和imu的topic发布出来,直接使用rosbag record ...

最新文章

  1. 零基础怎么学习web前端开发
  2. raid5和raid6对比
  3. BZOJ 3786: 星系探索 欧拉游览树
  4. 01.神经网络和深度学习 W2.神经网络基础
  5. 记号(notation)的学习
  6. 物联网卡就是流量卡 这说法正确吗
  7. 教大家防止Jar包被反编译
  8. Nodejs文件相关操作
  9. Java实习日记(7)
  10. java调用万网域名接口
  11. 如何使用高德地图API
  12. 项目实战 - tpshop商城项目环境搭建
  13. Android App签名的那些事
  14. 服务端开发框架及技术(转)
  15. 推荐3个游戏小程序,让你整个暑假都充实!
  16. 李宏毅机器学习之Deep Learning简介
  17. MSYS 1.0.11 + MinGW安装方法
  18. 基于 electron 实现简单易用的抓包、mock 工具
  19. 2019年山东省第十届ACM程序设计竞赛 比赛总结
  20. 开源BI报表工具Metabase初体验

热门文章

  1. Chrome开发者工具详解(4)-Profiles面板
  2. LVS--NAT模型配置
  3. Hashtable.ContainsKey跟Hashtable.Contains的区别
  4. 基于PageRank的作弊检测算法
  5. AE 模板 天使之城
  6. 第5课 - 线性表的本质
  7. 浅谈微信smali注入
  8. [No0000111]java9环境变量配置bat
  9. 排序算法02--冒泡排序
  10. MsWord 操作总结