forked from svishwa/crowdcount-mcnn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
34 lines (30 loc) · 1.4 KB
/
utils.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
import cv2
import numpy as np
import os
def save_results(input_img, gt_data,density_map,output_dir, fname='results.png'):
input_img = input_img[0][0]
gt_data = 255*gt_data/np.max(gt_data)
density_map = 255*density_map/np.max(density_map)
gt_data = gt_data[0][0]
density_map= density_map[0][0]
if density_map.shape[1] != input_img.shape[1]:
density_map = cv2.resize(density_map, (input_img.shape[1],input_img.shape[0]))
gt_data = cv2.resize(gt_data, (input_img.shape[1],input_img.shape[0]))
result_img = np.hstack((input_img,gt_data,density_map))
cv2.imwrite(os.path.join(output_dir,fname),result_img)
def save_density_map(density_map,output_dir, fname='results.png'):
density_map = 255*density_map/np.max(density_map)
density_map= density_map[0][0]
cv2.imwrite(os.path.join(output_dir,fname),density_map)
def display_results(input_img, gt_data,density_map):
input_img = input_img[0][0]
gt_data = 255*gt_data/np.max(gt_data)
density_map = 255*density_map/np.max(density_map)
gt_data = gt_data[0][0]
density_map= density_map[0][0]
if density_map.shape[1] != input_img.shape[1]:
input_img = cv2.resize(input_img, (density_map.shape[1],density_map.shape[0]))
result_img = np.hstack((input_img,gt_data,density_map))
result_img = result_img.astype(np.uint8, copy=False)
cv2.imshow('Result', result_img)
cv2.waitKey(0)