我有很多块文件,例如:
由于这些文件是图像分区和标签。如何将这些文件合并为一个文件?以及如何将它们转换为png或jpeg文件?
from gaps_dataset import gaps
import zipfile
import os
import numpy as np
import cv2
# change these parameters:
destination_directory = 'D:/local/datasets/gaps/v1'
login = 'login'
# download images and patch references
#gaps.download_images(login=login, datadir=destination_directory)
# unzip images
#zip_filename = os.path.join(destination_directory, 'images/images.zip')
#zip_ref = zipfile.ZipFile(zip_filename, 'r')
#zip_ref.extractall(os.path.join(destination_directory, 'images'))
#zip_ref.close()
# load patch references for training subset
ref_filename = os.path.join(destination_directory, 'train/patch_references_train.npy')
patch_ref = np.load(ref_filename).astype(int)
# get patches from images
n_patches = patch_ref.shape[0] # number of patches
image_template = os.path.join(destination_directory, 'images/images/train_{:04d}.jpg')
for patch_index, patch_info in enumerate(patch_ref):
# get information for this patch
image_index, row, col, mirror_state, binary_label, class_label = patch_info
# load image containing this patch
image_filename = image_template.format(image_index)
image = cv2.imread(image_filename)
# extract patch from image
patch = image[row:row+64, col:col+64]
# mirroring
if mirror_state == 0: # flip rows
patch = patch[::-1, :]
elif mirror_state == 1: # flip cols
patch = patch[:, ::-1]
# binary_label:
# 0 = intact road,
# 1 = distress
# class_label:
# 0 = intact road,
# 1 = applied patch,
# 2 = pothole,
# 3 = inlaid patch,
# 4 = open joint,
# 5 = crack
# replace train with valid or test respectively to extract patches of the other subsets
我希望输出是图像文件,但出现错误消息:
not enough values to unpack (expected 6, got 1)
答案 0 :(得分:0)
您正在以下行中打开patch_info的包装:
image_index, row, col, mirror_state, binary_label, class_label = patch_info
但是补丁信息不知道有6个值,而是只有一个值。请调试您的代码,并检查patch_info的值。