ROS獲取KinectV2相機的彩色圖和深度圖并制作bundlefusion需要的數據集

背景: 最近在研究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")

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/252411.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/252411.shtml
英文地址,請注明出處:http://en.pswp.cn/news/252411.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Linux下配置tomcat+apr+native應對高并發

摘要&#xff1a;在慢速網絡上Tomcat線程數開到300以上的水平&#xff0c;不配APR&#xff0c;基本上300個線程狠快就會用滿&#xff0c;以后的請求就只好等待。但是配上APR之后&#xff0c;Tomcat將以JNI的形式調用Apache HTTP服務器的核心動態鏈接庫來處理文件讀取或網絡傳輸…

Firefox 66 將阻止自動播放音頻和視頻

百度智能云 云生態狂歡季 熱門云產品1折起>>> 當我們點擊一個鏈接&#xff0c;或者打開新的瀏覽器選項卡時&#xff0c;瀏覽器就開始自動播放視頻和聲音&#xff0c;這是一件十分煩人的事。Chrome 瀏覽器早已對這些行為下手了&#xff0c;現在 Firefox 也明確表示要…

Windows 10 關閉Hyper-V

以管理員身份運行命令提示符 關閉 bcdedit /set hypervisorlaunchtype off 啟用 bcdedit / set hypervisorlaunchtype auto 禁用DG 轉載于:https://www.cnblogs.com/Robbery/p/8397767.html

ROS下獲取kinectv2相機的仿照TUM數據集格式的彩色圖和深度圖

準備工作&#xff1a; &#xff11;&#xff0e; ubuntu16.04上安裝iai-kinect2, 2. 運行roslaunch kinect2_bridge kinect2_bridge.launch, 3. 運行 rosrun save_rgbd_from_kinect2 save_rgbd_from_kinect2,開始保存圖像&#xff0e; 這個保存kinectV2相機的代碼如下&…

Java Web 九大內置對象(一)

在Jsp 中一共定義了九個內置對象&#xff0c;分別為&#xff1a; *request HttpServletRequest; *response HttpServletResponse; *session HttpSession; page This(本jsp頁面)&#xff1b; *application ServletCon…

Missing URI template variable 'XXXX' for method parameter of type String

原因&#xff1a;就是spring的controller上的RequestMapping的實參和方法里面的形參名字不一致 方法&#xff1a;改成一樣就可。 ps.還能用綁定的方法&#xff0c;不建議&#xff0c;因為太麻煩了 RequestMapping(value "/findUser/{id}",method RequestMethod.GET…

css:text-overflow屬性

參考文檔:www.w3school.com.cn/cssref/pr_t… text-overflow:ellipsis;( 顯示省略符號來代表被修剪的文本。)

Failed to load nodelet ‘/kinect2_bridge` of type `kinect2_bridge/kinect2_bridge_nodelet` to manager

之前在我的電腦上配置了libfreenect2和iai_kinect2&#xff0c;現在需要在工控機上重新安裝這兩個庫&#xff0c;講kinectV2相機安置在嬰兒車上&#xff0c;然后使用我的ros下獲取kinectV2相機的彩色圖和灰度圖的腳本&#xff0c;獲取深度圖和彩色圖。 我成功的安裝了libfreen…

object轉字符串

1、obj.tostring() obj為空時&#xff0c;拋異常。 2、convert.tostring(obj) obj為空時&#xff0c;返回null&#xff1b; 3、(string)obj obj為空時&#xff0c;返回null&#xff1b;obj不是string類型時&#xff0c;拋異常。 4、obj as string obj為空時&#xff0c;返回nul…

微信開發中,H5的video標簽使用

<video></video>是HTML5新加入的標簽&#xff0c;最近流行的h5開發多以video技術集成一個H5頁面&#xff0c;效果也是很6的。現在總結一下用到的技術&#xff0c;主要的使用環境是微信&#xff0c;部分屬性一些手機的默認瀏覽器不支持&#xff0c;這些還需要讀者親…

bundlefusion論文閱讀筆記

4. 全局位姿對齊(glob pose alignment) 輸入系統的是使用消費級的傳感器獲取的RGBD數據流&#xff0c;并且保證這些數據中的彩色圖像和深度圖像是時間和空間上都對齊的。圖像分辨率是640x480,頻率是30hz。我們的目的就是要找到frames之間的3D對應&#xff0c;然后根據這些對應…

IOC和DI的區別詳解

IOC 是英文inversion of control的縮寫&#xff0c;意思是控制反轉DI 是英文Dependency Injection的縮寫&#xff0c;意思是依賴注入 下面用一個簡單的例子來描述一下IOC和DI的關系 先看下總結&#xff1a; 依賴注入(DI)和控制反轉(IOC)是從不同的角度的描述的同一件事情&#…

TOMCAT啟動到一半停止如何解決

當你的項目過大的時候&#xff0c;往往會導致你的TOMCAT啟動時間過長&#xff0c;啟動失敗&#xff0c;遇到該情況可以試一下下面兩招&#xff1a; TOmcat啟動到一半的時候停止了&#xff0c;以下原因&#xff1a; 1、 tomcat啟動時間超過了設置時間&#xff1a; 解決辦法&…

視覺slam十四講ch6曲線擬合 代碼注釋(筆記版)

1 #include <opencv2/core/core.hpp>2 #include <ceres/ceres.h>3 #include <chrono>4 5 using namespace std;6 7 // 代價函數的計算模型8 struct CURVE_FITTING_COST9 {10 CURVE_FITTING_COST ( double x, double y ) : _x ( x ), _y ( y ) {}11 /…

Dojo 如何測試 widget

測試 dojo/framework/src/testing/README.mdcommit 84e254725f41d60f624ab5ad38fe82e15b6348a2 用于測試和斷言 Dojo 部件期望的虛擬 DOM 和行為的簡單 API。 測試 Features harness APICustom Comparatorsselectors harness.expect harness.expectPartial harness.triggerharn…

python中將四元數轉換為旋轉矩陣

在制作bundlefusion時,想測試TUM數據集,并且將groundtruth寫入到數據集中,TUM中給定的groundtruth中的旋轉是使用四元數表示的,而bundlefusion中需要SE3的形式,所以我需要首先將四元數轉換為旋轉矩陣,然后再將其與平移向量合并在一起,因為我之前關于生成bundlefusion數據集寫了…

js -- 時間轉年月日

/*** 時間轉年月日* param sdate 開始的時間* param edate 結束的時間* returns {*}*/function day2ymrStr2(sdate, edate) {var day2ymrStr "";var date1 new Date(edate);var date2 new Date(sdate);var y 0, m 0, d 0;var y1 date1.getFullYear();var m1 …

iOS sha1加密算法

最近在項目中使用到了網絡請求簽名認證的方法&#xff0c;于是在網上找關于OC sha1加密的方法&#xff0c;很快找到了一個大眾使用的封裝好的方法&#xff0c;以下代碼便是 首先需要添加頭文件 #import<CommonCrypto/CommonDigest.h> 然后直接使用下面的方法就可以了 //s…

Linux開發5款實用工具推薦

今天安利給大家5款實用的Linux開發工具&#xff0c;希望對大家工作效率的提升有所幫助。容器放眼于現實&#xff0c;現在已經是容器的時代了。容器既及其容易部署&#xff0c;又可以方便地構建開發環境。如果你針對的是特定的平臺的開發&#xff0c;將開發流程所需要的各種工具…

TUM數據集制作BundleFusion數據集

BundleFusion的數據集中,在生成.sens文件之前,包括彩色圖,深度圖和一個位姿文件,并且這個pose文件中的位姿態是有變化的,所以我懷疑,推測,在這個pose文件中可以寫入groundtruth的位姿,然后在重建的時候就按照傳入的位姿進行計算.為了測試一下效果,我從TUM數據集開始入手,這個數…