打开路径选择点云TXT文件并合并,返回点云数据

该代码示例展示了一个使用Python的numpy库和文件对话框来合并多个TXT文档的函数。它首先打开一个文件选择对话框,然后加载选定的TXT文件,跳过第一行数据,将所有文件的数据垂直堆叠在一起,最后返回合并后的点云数据numpy数组。
摘要由CSDN通过智能技术生成
# 点云TXT文档合并 nploadtxt方式
def combine_txt_npload():
    """
    点云TXT文档合并 nploadtxt方式
    :return: data, 合并点云数据,数据类型 numpy.ndarray
    """
    #
    import numpy as np
    import os
    import tkinter as tk
    from tkinter import filedialog
    import numpy as np

    # Open a file dialog to choose the text files
    root = tk.Tk()
    root.withdraw()
    file_paths = filedialog.askopenfilenames(filetypes=[("Text files", "*.txt")])

    # Load the text files and combine them together    
    data = None

    for file_path in file_paths:
        file_name = os.path.basename(file_path)[:-4]
        # Load the data from the file, skipping the first row
        file_data = np.loadtxt(file_path, skiprows=1)
        num_rows = file_data.shape[0]

        # Combine the data with the existing data, if any
        if data is None:
            data = file_data
        else:
            data = np.vstack((data, file_data))
    # The combined data is now stored in the `data` variable
    return data
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值