栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python分类文件(大疆精灵4多光谱版PM4影象分类)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python分类文件(大疆精灵4多光谱版PM4影象分类)

任务描述

大疆精灵4多光谱版有六个通道,每次拍摄都会生成六张图片。图片的顺序为 0. 可见光 1. 蓝光 2. 绿光 3. 红光 4. 红边 5. 近红外。

在用其他软件进行拼接时需要对六个通道的照片分别进行拼接,而不同通道的图片仅是最后一位数字不同,因此要将相同通道的图片放到一起,易于利用软件拼接。

代码实现

基于Python的os库和shutil库进行文件转移操作,代码如下

python
import shutil
import os

path = r'E:博士期间记录照片站内高光谱20210811'
files = os.listdir(path)
rgb_file = path+'\rgb'
red_file = path+'\red'
green_file = path+'\green'
blue_file = path+'\blue'
red_edge_file = path+'\red_edge'
Near_infrared_file = path+'\Near_infrared'
for f in files:
    filename, suffix = os.path.splitext(f)  # filename是文件名 suffix是文件后缀
    if not os.path.exists(rgb_file):
        os.makedirs(rgb_file)
    if not os.path.exists(red_file):
        os.makedirs(red_file)
    if not os.path.exists(green_file):
        os.makedirs(green_file)
    if not os.path.exists(blue_file):
        os.makedirs(blue_file)
    if not os.path.exists(red_edge_file):
        os.makedirs(red_edge_file)
    if not os.path.exists(Near_infrared_file):
        os.makedirs(Near_infrared_file)
    if filename[-1] == '0':
        shutil.move(os.path.join(path, f), rgb_file)
    elif filename[-1] == '1':
        shutil.move(os.path.join(path, f), blue_file)
    elif filename[-1] == '2':
        shutil.move(os.path.join(path, f), green_file)
    elif filename[-1] == '3':
        shutil.move(os.path.join(path, f), red_file)
    elif filename[-1] == '4':
        shutil.move(os.path.join(path, f), red_edge_file)
    elif filename[-1] == '5':
        shutil.move(os.path.join(path, f), Near_infrared_file)
结果如下


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/423651.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号