LingxinMeng 6 달 전
부모
커밋
86370b8ed6

+ 57 - 3
src/python2/kinglong/parse_jinlong_image.py

@@ -30,7 +30,7 @@ def parsebag(f, output_dir, target_topic):
                         img = bridge.imgmsg_to_cv2(msg, 'bgr8')
                         # img = bridge.compressed_imgmsg_to_cv2(msg, 'bgr8')
                         timestr = msg.header.stamp.to_nsec()
-                        image_name = str(timestr) + ".jpg"
+                        image_name = str(timestr)[:10]+'.'+str(timestr)[10:] + ".jpg"  #改成和点云一样的时间戳,其中前10位表示秒的整数位,后9位是小数位
                         if not os.path.exists(output_path + '_' + 'image'):
                             os.makedirs(output_path + '_' + 'image')
                         output_path_img = os.path.join(output_path + '_' + 'image', image_name)
@@ -80,8 +80,9 @@ def parse(input_bag_file, output_mp4_dir):
     topic = '/camera_image'  # /camera/color/image_raw
 
     num_count = parsebag(input_dir, output_dir, topic)
-    print("解析完成")
-
+    #print("解析完成")
+    '''
+    下面这段代码是用ffmpeg通过动态计算视频帧率将图片拼接成视频的代码
     dirt = os.path.join(output_dir, input_dir.split('/')[-1].split('.')[0] + '_' + 'image')
     # print(dirt)
 
@@ -95,6 +96,59 @@ def parse(input_bag_file, output_mp4_dir):
                   dirt + '/camera.mp4']
     p = Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     p.communicate()
+    '''
+    
+    '''
+    下面这段代码是利用图像插值算法,通过指定一个频率将图像拼接成视频的代码
+    '''
+    dirt = os.path.join(output_dir, input_dir.split('/')[-1].split('.')[0] + '_' + 'image')
+    #指定视频帧率
+    hz=10.0
+    
+    # 定义图片文件夹路径
+    folder_path = dirt
+
+    # 获取文件夹中的所有图片文件
+    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(dirt,'camera.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()
+    
+    
+    
     list1 = os.listdir(dirt)
     for i in list1:
         if i.split('.')[-1] == 'jpg':

+ 53 - 0
src/python2/kinglong/pcdtovideo_jilong_forwardlook.py

@@ -273,6 +273,8 @@ def parse(input_bag_file, output_mp4_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'] + [
@@ -280,6 +282,57 @@ def parse(input_bag_file, output_mp4_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_forwardlook.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)

+ 54 - 1
src/python2/kinglong/pcdtovideo_jilong_overlook.py

@@ -185,6 +185,8 @@ def parse(input_bag_file, output_mp4_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'] + [
@@ -193,9 +195,60 @@ def parse(input_bag_file, output_mp4_dir):
         # command = ['ffmpeg', '-f', 'image2', '-t', bagtime, '-pattern_type', 'glob', '-i'] + ['"jpg/*.jpg"'] + [
         #     '-tag:v', 'avc1', '-y'] + ['pcd_overlook.mp4']
         result_string = " ".join(command)
-        print '执行视频生成命令:%s' % result_string
+        print('执行视频生成命令:%s' % result_string)
         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_overlook.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)

+ 1 - 1
src/python2/pjibot/resource/convert_rosbag_to_pcd.py

@@ -38,7 +38,7 @@ def process_file(file):
     try:
         os.makedirs(ascii_folder)
     except Exception:
-        print '创建目录失败 %s' % ascii_folder
+        print ('创建目录失败 %s' % ascii_folder)
         pass
     tempFilePath = os.path.join(ascii_folder, filename)
 

+ 55 - 1
src/python2/pjibot/resource/pcdtovideo_pji_deepcamera.py

@@ -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]

+ 52 - 0
src/python2/pjibot_delivery/resource/pcdtovideo_monitor_overlook.py

@@ -115,6 +115,8 @@ def parse(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'] + [
@@ -122,6 +124,56 @@ def parse(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_overlook.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()
     
     e_time=datetime.datetime.now()
     print("using "+str(e_time-s_time)+ "s")

+ 52 - 0
src/python2/pjibot_patrol/resource/pcdtovideo_monitor_overlook.py

@@ -115,6 +115,8 @@ def parse(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'] + [
@@ -122,6 +124,56 @@ def parse(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_overlook.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()
     
     e_time=datetime.datetime.now()
     print("using "+str(e_time-s_time)+ "s")

+ 55 - 1
src/python2/pjisuv/resource/camera_mp4.py

@@ -29,7 +29,7 @@ def parsebag(f, output_dir, target_topic):
             img_resized = cv2.resize(img, (1920, 1080))
             # img = bridge.compressed_imgmsg_to_cv2(msg, 'bgr8')
             timestr = msg.header.stamp.to_nsec()
-            image_name = str(timestr) + ".jpg"
+            image_name = str(timestr)[:10]+'.'+str(timestr)[10:] + ".jpg"  #改成和点云一样的时间戳,其中前10位表示秒的整数位,后9位是小数位
             if not os.path.exists(output_path + '_' + 'image'):
                 os.makedirs(output_path + '_' + 'image')
             output_path_img = os.path.join(output_path + '_' + 'image', image_name)
@@ -50,6 +50,8 @@ def parse(input_bag_file, output_mp4_dir):
 
     dirt = os.path.join(output_dir, input_dir.split('/')[-1].split('.')[0] + '_' + 'image')
     if flag:
+        '''
+        下面这段代码是用ffmpeg通过动态计算视频帧率将图片拼接成视频的代码
         bagtime = duration
 
         hz = str(float(num_count) / bagtime)
@@ -63,4 +65,56 @@ def parse(input_bag_file, output_mp4_dir):
         p = Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         p.communicate()
         print('done')
+        '''
+        
+        '''
+        下面这段代码是利用图像插值算法,通过指定一个频率将图像拼接成视频的代码
+        '''
+        dirt = os.path.join(output_dir, input_dir.split('/')[-1].split('.')[0] + '_' + 'image')
+        #指定视频帧率
+        hz=10.0
+        
+        # 定义图片文件夹路径
+        folder_path = dirt
+
+        # 获取文件夹中的所有图片文件
+        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(dirt,'camera.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()
+        
+        
     return dirt, num_count

+ 54 - 0
src/python2/pjisuv/resource/pcd_forwardlook_mp4.py

@@ -149,6 +149,8 @@ def parse(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'] + [
@@ -156,6 +158,58 @@ def parse(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_forwardlook.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()
+        
+        
+        
     e_time = datetime.datetime.now()
     print("using " + str(e_time - s_time) + "s")
     shutil.rmtree(file1)

+ 53 - 0
src/python2/pjisuv/resource/pcd_overlook_mp4.py

@@ -109,6 +109,8 @@ def parse(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'] + [
@@ -116,6 +118,57 @@ def parse(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_overlook.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()
+        
+        
     e_time = datetime.datetime.now()
     print("using " + str(e_time - s_time) + "s")
     shutil.rmtree(file1)