-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpredataset_RGBT_CC.py
116 lines (100 loc) · 4.18 KB
/
predataset_RGBT_CC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import glob
import math
import os
import torch
import cv2
import h5py
import numpy as np
import scipy.io as io
import scipy.spatial
from scipy.ndimage.filters import gaussian_filter
import random
# 先224*224
'''set your data path'''
root = 'F:/DataSets/'
rgbt_cc_train = os.path.join(root, 'RGBT-CC-use/train')
rgbt_cc_test = os.path.join(root, 'RGBT-CC-use/test')
rgbt_cc_val = os.path.join(root, 'RGBT-CC-use/val')
# 记得与之修改后面的路径
# path_sets = [rgbt_cc_train]
path_sets = [rgbt_cc_test]
# path_sets = [rgbt_cc_val]
'''for part A'''
# if not os.path.exists(rgbt_cc_train.replace('train', 'new_train_224')):
# os.makedirs(rgbt_cc_train.replace('train', 'new_trian_224'))
if not os.path.exists(rgbt_cc_test.replace('test', 'new_test_224')):
os.makedirs(rgbt_cc_test.replace('test', 'new_test_224'))
#
# if not os.path.exists(rgbt_cc_val.replace('val', 'new_val_224')):
# os.makedirs(rgbt_cc_val.replace('val', 'new_val_224'))
img_paths = []
for path in path_sets:
for img_path in glob.glob(os.path.join(path, '*RGB.jpg')):
img_paths.append(img_path)
img_paths.sort()
np.random.seed(0)
random.seed(0)
for img_path in img_paths:
# print(img_path)
Img_data = cv2.imread(img_path)
T_data = cv2.imread(img_path.replace('_RGB', '_T'))
Gt_data = np.load(img_path.replace('_RGB.jpg', '_GT.npy'))
# 448和672
rate = 1
rate_1 = 1
rate_2 = 1
flag = 0
if Img_data.shape[1] >= Img_data.shape[0]: # 后面的大
rate_1 = 672.0 / Img_data.shape[1]
rate_2 = 448.0 / Img_data.shape[0]
Img_data = cv2.resize(Img_data, (0, 0), fx=rate_1, fy=rate_2)
T_data = cv2.resize(T_data, (0, 0), fx=rate_1, fy=rate_2)
Gt_data[:, 0] = Gt_data[:, 0] * rate_1
Gt_data[:, 1] = Gt_data[:, 1] * rate_2
print("1111111")
elif Img_data.shape[0] > Img_data.shape[1]: # 前面的大
rate_1 = 672.0 / Img_data.shape[0]
rate_2 = 448.0 / Img_data.shape[1]
Img_data = cv2.resize(Img_data, (0, 0), fx=rate_2, fy=rate_1)
T_data = cv2.resize(T_data, (0, 0), fx=rate_2, fy=rate_1)
Gt_data[:, 0] = Gt_data[:, 0] * rate_2 # 对应的坐标进行扩大映射
Gt_data[:, 1] = Gt_data[:, 1] * rate_1 # 对应的坐标进行扩大映射
print("22222")
# kpoint = np.zeros((Img_data.shape[0], Img_data.shape[1]))
#
# for i in range(0, len(Gt_data)):
# if int(Gt_data[i][1]) < Img_data.shape[0] and int(Gt_data[i][0]) < Img_data.shape[1]:
# kpoint[int(Gt_data[i][1]), int(Gt_data[i][0])] = 1
# height, width = Img_data.shape[0], Img_data.shape[1]
# m = int(width / 224)
# n = int(height / 224)
# fname = img_path.split('/')[-1]
# root_path = img_path.split('IMG_')[0].replace('images', 'images_crop')
# kpoint = kpoint.copy()
# if root_path.split('/')[-3] == 'train_data':
#
# for i in range(0, m):
# for j in range(0, n):
# crop_img = Img_data[j * 224: 224 * (j + 1), i * 224:(i + 1) * 224, ]
# crop_kpoint = kpoint[j * 224: 224 * (j + 1), i * 224:(i + 1) * 224]
# gt_count = np.sum(crop_kpoint)
#
# save_fname = str(i) + str(j) + str('_') + fname
# save_path = root_path + save_fname
# h5_path = save_path.replace('.jpg', '.h5').replace('images', 'gt_density_map')
# if gt_count == 0:
# print(save_path, h5_path)
# with h5py.File(h5_path, 'w') as hf:
# hf['gt_count'] = gt_count
# cv2.imwrite(save_path, crop_img)
# else: # 训练才需要位置,验证,测试不需要
img_path = img_path.replace('test', 'new_test_224')
print(img_path)
T_path = img_path.replace('_RGB','_T')
gt_save_path = img_path.replace('_RGB.jpg', '_GT.npy')
cv2.imwrite(img_path, Img_data)
cv2.imwrite(T_path, T_data)
np.save(gt_save_path, Gt_data)
# gt_count = np.sum(kpoint)
# with h5py.File(img_path.replace('.jpg', '.h5').replace('images', 'gt_density_map'), 'w') as hf:
# hf['gt_count'] = gt_count