图像处理工具3——进行图像文件的拷贝(不只是图像文件)

1 进行文件的拷贝,不只是图像文件

# 这个文件的作用是复制负样本的文件

import os
import gdal
import numpy as np
import time


def Positive(nature_to_path,label_path,label_to_path,img_path,img_to_path,):
    """
    进行负样本文件的拷贝
    :param nature_to_path:负样本已经存在的的文件夹
    :param label_path:全部的标签
    :param label_to_path:要复制到的负样本标签文件夹
    :param img_path:全部的影像
    :param img_to_path:要复制到的负样本影像文件夹
    :return:
    """
    filenames = os.listdir(nature_to_path)
    print(len(filenames))
    for filename in filenames:
        # 1 拷贝标签
        file_path = os.path.join(label_path, filename)
        label_to = os.path.join(label_to_path, filename)  # 路径2拼接
        with open(file_path, "rb") as f:
            res_one = f.read()
            with open(label_to, "wb") as a:
                a.write(res_one)

        # 2 拷贝rawdata
        remote_path = os.path.join(img_path, filename)
        remote_to = os.path.join(img_to_path, filename)
        with open(remote_path, "rb") as f:
            res_one = f.read()
            with open(remote_to, "wb") as a:
                a.write(res_one)

if __name__ == '__main__':
    start = time.time()
    Positive(
        nature_to_path=r"I:\5GF2\5dataset\3NegativeData\3Negativenaturedata",
        label_path=r"I:\5GF2\5dataset\1alldata\1labels",
        label_to_path=r"I:\5GF2\5dataset\3NegativeData\1Negativelabels",
        img_path=r"I:\5GF2\5dataset\1alldata\2rawdata",
        img_to_path=r"I:\5GF2\5dataset\3NegativeData\2Negativerawdata"
    )

    end = time.time()
    print("time_cost:",end-start)

2 拷贝含指定名字的图像

import os
path_png = r"I"
path_jpg = r"I:"
path_to_png = r"H:\01Hs"
path_to_jpg = r"H:\01HTut"
names = ["sc254305","sc254308","sc254309","lt497911","lt497908","lt521769"]
filenames = os.listdir(path_png)
for filename in filenames:
    if filename[0:8] in names:
        # 1 拷贝标签
        file_path = os.path.join(path_png, filename)
        label_to = os.path.join(path_to_png, filename)  # 路径2拼接
        with open(file_path, "rb") as f:
            res_one = f.read()
            with open(label_to, "wb") as a:
                a.write(res_one)

print("label ok")

filenamesjpg = os.listdir(path_jpg)
for filename in filenamesjpg:
    if filename[0:8] in names:
        # 2 拷贝名字
        file_path = os.path.join(path_jpg, filename)
        label_to = os.path.join(path_to_jpg, filename)  # 路径2拼接
        with open(file_path, "rb") as f:
            res_one = f.read()
            with open(label_to, "wb") as a:
                a.write(res_one)
print("images ok")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晓码bigdata

如果文章给您带来帮助,感谢打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值