|
@@ -17,6 +17,8 @@ import rosbag
|
|
|
|
|
|
def parse1(topic_name,input_dir, output_dir):
|
|
|
|
|
|
+
|
|
|
+
|
|
|
bag_name = input_dir.split('/')[-1].split('.')[0]
|
|
|
output_dir = os.path.join(output_dir, bag_name + '_pcd_depthcamera' + '/pcd')
|
|
|
if not os.path.exists(output_dir):
|
|
@@ -198,6 +200,8 @@ def parse2(topic_name,input_dir, output_dir):
|
|
|
#######################将转化的点云jpg合成视频#######################
|
|
|
jpg_list = os.listdir(file2)
|
|
|
if not jpg_list == []:
|
|
|
+ '''
|
|
|
+ 下面这段代码是用ffmpeg通过动态计算视频帧率将图片拼接成视频的代码
|
|
|
command = ['ffmpeg', '-f', 'image2', '-r', hz, '-pattern_type', 'glob', '-i'] + ['"jpg/*.jpg"'] + ['-tag:v',
|
|
|
'avc1',
|
|
|
'-y'] + [
|
|
@@ -205,7 +209,57 @@ def parse2(topic_name,input_dir, output_dir):
|
|
|
result_string = " ".join(command)
|
|
|
p = Popen(result_string, shell=True, cwd=output_dir[0:-4] + '/', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
p.wait()
|
|
|
+ '''
|
|
|
+
|
|
|
+ '''
|
|
|
+ 下面这段代码是利用图像插值算法,通过指定一个频率将图像拼接成视频的代码
|
|
|
+ '''
|
|
|
+ #指定视频帧率
|
|
|
+ hz=10.0
|
|
|
+
|
|
|
+ # 定义图片文件夹路径
|
|
|
+ folder_path = file2
|
|
|
+
|
|
|
+ # 获取文件夹中的所有图片文件
|
|
|
+ image_files = [f for f in os.listdir(folder_path) if f.endswith('.jpg')]
|
|
|
+
|
|
|
+ # 对文件名进行排序,以便按顺序处理图片
|
|
|
+ image_files.sort()
|
|
|
+
|
|
|
+ # 读取第一张图片
|
|
|
+ first_image = cv2.imread(os.path.join(folder_path, image_files[0]))
|
|
|
+
|
|
|
+ # 获取图片的形状
|
|
|
+ image_shape = first_image.shape
|
|
|
+
|
|
|
+ # 创建视频写入对象
|
|
|
+ video_path=os.path.join(file2,'pcd_depthcamera2.mp4')
|
|
|
+ video_writer = cv2.VideoWriter(video_path, cv2.VideoWriter_fourcc('m', 'p', '4', 'v'), hz, (image_shape[1], image_shape[0]))
|
|
|
+
|
|
|
+ # 遍历图片文件列表
|
|
|
+ for i in range(len(image_files) - 1):
|
|
|
+ # 读取当前图片和下一张图片
|
|
|
+ current_image = cv2.imread(os.path.join(folder_path, image_files[i]))
|
|
|
+ next_image = cv2.imread(os.path.join(folder_path, image_files[i + 1]))
|
|
|
+
|
|
|
+ # 获取当前图片和下一张图片的时间戳
|
|
|
+ current_timestamp = float(image_files[i].split('.jpg')[0])
|
|
|
+ next_timestamp = float(image_files[i + 1].split('.jpg')[0])
|
|
|
+
|
|
|
+ # 计算时间间隔
|
|
|
+ time_interval = next_timestamp - current_timestamp
|
|
|
+ #print(time_interval)
|
|
|
+
|
|
|
+ # 根据实际时间间隔调整循环次数
|
|
|
+ video_writer.write(current_image)
|
|
|
+ if int(time_interval * hz)>1.5:
|
|
|
+ for _ in range(int(time_interval * hz)):
|
|
|
+ video_writer.write(current_image)
|
|
|
+
|
|
|
+ # 释放资源
|
|
|
+ video_writer.release()
|
|
|
+
|
|
|
shutil.rmtree(file1)
|
|
|
shutil.rmtree(file2)
|
|
|
shutil.rmtree(output_dir)
|
|
|
- return output_dir[0:-4]
|
|
|
+ return output_dir[0:-4]
|