This repository has been archived by the owner on Oct 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeocap_utils.py
146 lines (114 loc) · 6.07 KB
/
geocap_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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Import libraries
import json
import cv2
# Load a JSON file
def load_json(tmp_file_path):
# load json file from file system
print("[INFO] loading JSON file from '" + tmp_file_path + "'...")
with open(tmp_file_path) as json_file:
data = json.load(json_file)
print("[OK] Successfully loaded JSON file from '" + tmp_file_path + "'!")
return data
# Perform CLAHE on an image
def clahe(in_img):
clip_limit = 2.0
grid_size = (2, 2)
print("[STATUS] Converting image to grayscale...")
out_img = cv2.cvtColor(in_img, cv2.COLOR_BGR2GRAY)
print("[OK] Successfully converted to a grayscale image.")
print("[STATUS] Performing CLAHE with clip limit " + str(clip_limit) + " and grid size "\
+ str(grid_size) + ".")
out_img = cv2.createCLAHE(clipLimit=clip_limit, tileGridSize=grid_size).apply(out_img)
print("[OK] Successfully performed CLAHE on the image.")
print("[STATUS] Converting image to colour...")
out_img = cv2.cvtColor(out_img, cv2.COLOR_GRAY2BGR)
print("[OK] Successfully converted to a colour image.")
return out_img
# Parse frame name to get time and frame number
def parse_frame_name(input_name):
print("[INFO] Parsing frame name '" + input_name + "'...")
output = input_name[:-6].split('_')
####################################################
# If file name contains "FD*_" at the front, enable:
# output = output[1:]
####################################################
num = output[2]
date, time = output[4:6]
date = date[6:8] + "/" + date[4:6] + "/" + date[0:4]
time = time[0:2] + ":" + time[2:5]
output_name = date + " @ " + time + "UTC"
return (output_name, num)
# Overlay information onto a frame
def overlay_info(inp_img, frame_name, data_size, frame_cnt):
print("[INFO] Overlaying text onto frame...")
frame_time, frame_num = parse_frame_name(frame_name)
font = cv2.FONT_HERSHEY_PLAIN
cv2.putText(inp_img, "GK-2A Imagery", (20, 80), font, 5, (0, 255, 255), 5, cv2.LINE_AA)
cv2.putText(inp_img, "Animation", (20, 170), font, 6, (0, 165, 255), 5, cv2.LINE_AA)
cv2.putText(inp_img, "Capture Time: ", (1720, 60), font, 4, (0, 255, 255), 4, cv2.LINE_AA)
cv2.putText(inp_img, frame_time, (1570, 110), font, 3, (150, 150, 150), 3, cv2.LINE_AA)
cv2.putText(inp_img, "Frame Number: ", (1690, 180), font, 4, (0, 255, 255), 4, cv2.LINE_AA)
cv2.putText(inp_img, frame_num, (2070, 240), font, 4, (150, 150, 150), 4, cv2.LINE_AA)
cv2.putText(inp_img, "Processing: ", (20, 2120), font, 4, (255, 255, 255), 4, cv2.LINE_AA)
cv2.putText(inp_img, "Albert (Technobird22)", (20, 2180), font, 4, (0, 255, 0), 4, cv2.LINE_AA)
cv2.putText(inp_img, "Data size: " + str(round(data_size, 2)) + " GB", (1710, 2078), font, 3, (100, 100, 100), 4, cv2.LINE_AA)
cv2.putText(inp_img, "Frame count: " + str(frame_cnt) + " frames", (1540, 2128), font, 3, (100, 100, 100), 4, cv2.LINE_AA)
cv2.putText(inp_img, "Data from: MouseBatteries", (1510, 2178), font, 3, (100, 100, 100), 4, cv2.LINE_AA)
cv2.putText(inp_img, "Thanks ;)", (2100, 2194), font, 1, (50, 50, 50), 1, cv2.LINE_AA)
return inp_img
# For testing the overlay code
def test_overlay():
path = "everything/"
img_name = "FD8_IMG_FD_001_IR105_20200704_001006.jpg"
img = cv2.imread(path + img_name, 1)
print("-"*30)
print("---START---")
print("Input name:", img_name)
out = parse_frame_name(img_name)[0]
print("Output time:", out)
num = parse_frame_name(img_name)[1]
print("Frame number:", num)
# Apply overlay
print("[INFO] Applying overlay to image...")
img = overlay_info(img, img_name, 1.2345678, 123)
# Write final output image
print("[INFO] Writing final output to image...")
cv2.imwrite(path + "overlay_TEST_" + img_name, img)
print("---DONE---")
print("-"*30)
# ---FOR DEBUGGING:---
# test_overlay()
# Headers at the start of program
HEADER = """\
┌────────────────────────────────────────────────────────┐
│ GeoCapture │
│ Automatic processing of geostationary satellite data │
│ Version 1.0 │
├────────────────────────────────────────────────────────┤
│ Made by Albert (Technobird22) │
├────────────────────────────────────────────────────────┤
│ GitHub: https://github.com/technobird22/geocapture │
└────────────────────────────────────────────────────────┘
"""
BASIC_HEADER = """\
o--------------------------------------------------------o
| GeoCapture |
| Automatic processing of geostationary satellite data |
| Version 1.0 |
o--------------------------------------------------------o
| Made by Albert (Technobird22) |
o--------------------------------------------------------o
| GitHub: https://github.com/technobird22/geocapture |
o--------------------------------------------------------o
"""
VERY_BASIC_HEADER = """\
--------------------------------------------------------
GeoCapture
Automatic processing of geostationary satellite data
Version 1.0
--------------------------------------------------------
Made by Albert (Technobird22)
--------------------------------------------------------
GitHub: https://github.com/technobird22/geocapture
--------------------------------------------------------
"""