HaoFeng2019 commited on
Commit
74e9d98
·
1 Parent(s): eecbd6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -57
app.py CHANGED
@@ -73,63 +73,6 @@ def reload_segmodel(model, path=""):
73
  return model
74
 
75
 
76
- # def rec(opt):
77
- # # print(torch.__version__) # 1.5.1
78
- # img_list = os.listdir(opt.distorrted_path) # distorted images list
79
-
80
- # if not os.path.exists(opt.gsave_path): # create save path
81
- # os.mkdir(opt.gsave_path)
82
- # if not os.path.exists(opt.isave_path): # create save path
83
- # os.mkdir(opt.isave_path)
84
-
85
- # GeoTr_Seg_model = GeoTr_Seg()#.cuda()
86
- # # reload segmentation model
87
- # reload_segmodel(GeoTr_Seg_model.msk, opt.Seg_path)
88
- # # reload geometric unwarping model
89
- # reload_model(GeoTr_Seg_model.GeoTr, opt.GeoTr_path)
90
-
91
- # IllTr_model = IllTr()#.cuda()
92
- # # reload illumination rectification model
93
- # reload_model(IllTr_model, opt.IllTr_path)
94
-
95
- # # To eval mode
96
- # GeoTr_Seg_model.eval()
97
- # IllTr_model.eval()
98
-
99
- # for img_path in img_list:
100
- # name = img_path.split('.')[-2] # image name
101
-
102
- # img_path = opt.distorrted_path + img_path # read image and to tensor
103
- # im_ori = np.array(Image.open(img_path))[:, :, :3] / 255.
104
- # h, w, _ = im_ori.shape
105
- # im = cv2.resize(im_ori, (288, 288))
106
- # im = im.transpose(2, 0, 1)
107
- # im = torch.from_numpy(im).float().unsqueeze(0)
108
-
109
- # with torch.no_grad():
110
- # # geometric unwarping
111
- # bm = GeoTr_Seg_model(im)
112
- # bm = bm.cpu()
113
- # bm0 = cv2.resize(bm[0, 0].numpy(), (w, h)) # x flow
114
- # bm1 = cv2.resize(bm[0, 1].numpy(), (w, h)) # y flow
115
- # bm0 = cv2.blur(bm0, (3, 3))
116
- # bm1 = cv2.blur(bm1, (3, 3))
117
- # lbl = torch.from_numpy(np.stack([bm0, bm1], axis=2)).unsqueeze(0) # h * w * 2
118
-
119
- # out = F.grid_sample(torch.from_numpy(im_ori).permute(2,0,1).unsqueeze(0).float(), lbl, align_corners=True)
120
- # img_geo = ((out[0]*255).permute(1, 2, 0).numpy())[:,:,::-1].astype(np.uint8)
121
- # cv2.imwrite(opt.gsave_path + name + '_geo' + '.png', img_geo) # save
122
-
123
- # # illumination rectification
124
- # if opt.ill_rec:
125
- # ill_savep = opt.isave_path + name + '_ill' + '.png'
126
- # rec_ill(IllTr_model, img_geo, saveRecPath=ill_savep)
127
-
128
- # print('Done: ', img_path)
129
-
130
-
131
-
132
-
133
 
134
 
135
  def process_image(input_image):
@@ -169,6 +112,14 @@ def process_image(input_image):
169
  else:
170
  return Image.fromarray(img_geo)
171
 
 
 
 
 
 
 
 
 
172
  # Define Gradio interface
173
  input_image = gr.inputs.Image()
174
  output_image = gr.outputs.Image(type='pil')
 
73
  return model
74
 
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
 
78
  def process_image(input_image):
 
112
  else:
113
  return Image.fromarray(img_geo)
114
 
115
+
116
+ desired_width = 200
117
+ scale_ratio = desired_width / output_image.width
118
+ desired_height = int(output_image.height * scale_ratio)
119
+ output_image_resized = output_image.resize((desired_width, desired_height), Image.ANTIALIAS)
120
+
121
+ return output_image_resized
122
+
123
  # Define Gradio interface
124
  input_image = gr.inputs.Image()
125
  output_image = gr.outputs.Image(type='pil')