-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTwoImages_ConvectiveSystemTracking.py
More file actions
623 lines (460 loc) · 27.4 KB
/
TwoImages_ConvectiveSystemTracking.py
File metadata and controls
623 lines (460 loc) · 27.4 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
"""Mesoscale Convective System Identification and Tracking using Doppler Weather Radar Images"""
"""by A Niranjan"""
"""Algorithm for correlation between the convective systems of two consecutive images"""
#Importing the necessary libraries for the project
"""
LIBRARY : USE
1. cv2: OpenSourced Computer Vision Library for image recognition.
2. Numpy: Popular Numerical Python library for various matrix calculations.
3. time: Simulation time analysis.
4. os: OS file handling.
5. pytesseract: An opensource text recognition library for image matrix to string conversions.
6. imutils: Image Utilities for basic image processing functions.
7. contours: Potential area boundary formations.
8. skimage: OpenSource Measure analysis and image recognition Library for segmentation, geometric transformations and color space manipulation.
9. argparse: For passing arguments to the algorithm from terminal.
10. scipy.spatial: Displacement analysis.
"""
import cv2 as cv
import numpy as np
import time,os
import pytesseract
import imutils
from imutils import contours
from skimage import measure
import argparse
from scipy.spatial import distance
#Passing arguments to the algorithm
ap = argparse.ArgumentParser()
ap.add_argument("-i1", "--image1", required=True,help="path to the image file")
ap.add_argument("-i2", "--image2", required=True,help="path to the image file")
args = vars(ap.parse_args())
#Setting the path to the tesseract library executable file
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
#Converting and reading .gif
gif1 = cv.VideoCapture(args["image1"])
ret1,image1 = gif1.read()
gif2 = cv.VideoCapture(args["image2"])
ret2,image2 = gif2.read()
#Function for Contour formation with respect to Double Strength bar images.
def formcontour_Double1(x):
#Initializing Time sequence
start = time.time()
#Decleration of global variables for image-1 perspective analysis in later functions
global dresolution_1, Date_1, Time_1, Area_1, cX1, cY1, approx1
img_main = x
#Cropping the image with respect to Radar Field in the image
img_radar = x[43:700,6:722]
#Convertion of the image into Gray scale and then a blur filter is used to patch the image
gray = cv.cvtColor(img_radar, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (11, 11), 0)
#Thresholding the image for potential area identification
thresh = cv.threshold(blurred, 200, 255, cv.THRESH_BINARY)[1]
thresh = cv.erode(thresh, None, iterations=1)
thresh = cv.dilate(thresh, None, iterations=1)
#Connected Component Analysis to find the major patch formations
labels = measure.label(thresh, connectivity = 2, background=0)
mask = np.zeros(thresh.shape, dtype="uint8")
# Loop formation over the unique categories
for label in np.unique(labels):
# If it were the background label then ignore it
if label == 0:
continue
# Construction of the label mask and determining the total number of pixels in the patches
labelMask = np.zeros(thresh.shape, dtype="uint8")
labelMask[labels == label] = 255
numPixels = cv.countNonZero(labelMask)
# Adding the large components to the mask layer if the total number of connected pixels exceed the 150 range
if numPixels > 150:
mask = cv.add(mask, labelMask)
"""Implementation of the pytesseract library for text recognition and processing, the pytesseract library can
only process images in the RGB Spectrucm, so it is converted from BGR to RGB colour space"""
Date_1 = pytesseract.image_to_string((cv.cvtColor(img_main[14:39, 3:137],cv.COLOR_BGR2RGB)))
Time_1 = pytesseract.image_to_string(cv.resize((cv.cvtColor(img_main[14:43, 233:333],cv.COLOR_BGR2RGB)),(150,30)))
#In few cases the image needs to be resized for better recognition
#Lattitude and Logitude detection
lat = pytesseract.image_to_string((cv.resize((cv.cvtColor((img_main[20:39,794:848]),cv.COLOR_BGR2RGB)),(69,25))))
long = pytesseract.image_to_string((cv.resize((cv.cvtColor((img_main[22:39,863:925]),cv.COLOR_BGR2RGB)),(310,75))))
#Kilometer per pixel area recognition.
dresolution_1 =float(pytesseract.image_to_string(cv.resize(((cv.cvtColor((image1[83:100,923:960]),cv.COLOR_BGR2RGB))),(150,70))))
#Potential area contour formation for displaying the largest patches of the Convective_System
_, contours, _=cv.findContours(mask,cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
#Storing all the contour areas in one list
cntArea = [cv.contourArea(c) for c in contours]
for cnt in contours:
#Only the largest contour area is considered for plotting
if(cv.contourArea(cnt) == max(cntArea)):
epsilon = 0.01*cv.arcLength(cnt,True)
#Polygonal Structure approximation
approx1 = cv.approxPolyDP(cnt,epsilon,True)
#Drawing the contour
image = cv.drawContours(img_radar,[approx1],0,(0,0,255),2)
#Total number of pixels enclosed by the contour
TotalPixels = cv.contourArea(cnt)
#Area Calculation with respect to the km/pixel value as the image is in a (xx,xx,3) format the values measured are
#divided with 30 as the colour spectrum of 3 layers is calculated with respect to kilometer squares.
Area_1 = ((TotalPixels/30)*dresolution_1)
#Determining the centroid of the countour
X = cv.moments(cnt)
cX1 = int(X["m10"] / X["m00"])
cY1 = int(X["m01"] / X["m00"])
#Drawing a line perpendicular from the RADAR to the Contour centroid
cv.line(img_radar, (int(363), int(329)), (int(cX1), int(cY1)),(0,255,0), 2)
#Drwing points on the Contour Centroid and the RADAR Origin
cv.circle(img_radar, (cX1, cY1), 3, (0, 0, 0), -5)
cv.circle(img_radar, (363,329),3,(0,0,0),-5)
#Calculating the distance between the Contour Centroid and the RADAR Origin
D = distance.euclidean((363,329),(cX1,cY1))
DistanceFromRadar1 = round(D,2)
print('RADAR 1:')
print('Date : '+ Date_1)
print('Time Stamp : ' + Time_1)
print('Radar Lat&Long: '+lat+" , "+long)
print('Distance From Radar:',round(DistanceFromRadar1*dresolution_1,2), 'km',DirectionOfConvective_System(cX1,cY1))
print("Total Area Covered is: "+str(round(Area_1,2))+" Km.sq")
#Ending the time sequence
end = time.time()
print(f"Runtime {end - start}")
#Displaying the image
cv.imshow("Result 1",image)
return 'Successful'
#Function for Radar statistics of double strength bar image-1
def getRadarStats_Double1(x):
ContourFormation = formcontour_Double1(x)
if(ContourFormation == 'Successful'):
print('\nConvective_System Found in 1st Image')
return 'Successful'
else: print('\nNo Convective_System in 1st Image')
#Function for Contour formation with respect to Double Strength bar images.
def formcontour_Double2(x):
#Initializing Time sequence
start = time.time()
#Decleration of global variables for image-1 perspective analysis in later functions
global dresolution_2, Date_2, Time_2, Area_2, cX2, cY2,img_radar2
img_main = x
#Cropping the image with respect to Radar Field in the image
img_radar2 = x[43:700,6:722]
#Convertion of the image into Gray scale and then a blur filter is used to patch the image
gray = cv.cvtColor(img_radar2, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (11, 11), 0)
#Thresholding the image for potential area identification
thresh = cv.threshold(blurred, 200, 255, cv.THRESH_BINARY)[1]
thresh = cv.erode(thresh, None, iterations=1)
thresh = cv.dilate(thresh, None, iterations=1)
#Connected Component Analysis to find the major patch formations
labels = measure.label(thresh, connectivity = 2, background=0)
mask = np.zeros(thresh.shape, dtype="uint8")
# Loop formation over the unique categories
for label in np.unique(labels):
# If it were the background label then ignore it
if label == 0:
continue
# Construction of the label mask and determining the total number of pixels in the patches
labelMask = np.zeros(thresh.shape, dtype="uint8")
labelMask[labels == label] = 255
numPixels = cv.countNonZero(labelMask)
# Adding the large components to the mask layer if the total number of connected pixels exceed the 150 range
if numPixels > 150:
mask = cv.add(mask, labelMask)
"""Implementation of the pytesseract library for text recognition and processing, the pytesseract library can
only process images in the RGB Spectrucm, so it is converted from BGR to RGB colour space"""
Date_2 = pytesseract.image_to_string((cv.cvtColor(img_main[14:39, 3:137],cv.COLOR_BGR2RGB)))
Time_2 = pytesseract.image_to_string(cv.resize((cv.cvtColor(img_main[14:43, 233:333],cv.COLOR_BGR2RGB)),(150,30)))
#In few cases the image needs to be resized for better recognition
#Lattitude and Logitude detection
lat = pytesseract.image_to_string((cv.resize((cv.cvtColor((img_main[20:39,794:848]),cv.COLOR_BGR2RGB)),(69,25))))
long = pytesseract.image_to_string((cv.resize((cv.cvtColor((img_main[22:39,863:925]),cv.COLOR_BGR2RGB)),(310,75))))
#Kilometer per pixel area recognition.
dresolution_2 =float(pytesseract.image_to_string(cv.resize(((cv.cvtColor((image1[83:100,923:960]),cv.COLOR_BGR2RGB))),(150,70))))
#Potential area contour formation for displaying the largest patches of the Convective_System
_, contours, _=cv.findContours(mask,cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
#Storing all the contour areas in one list
cntArea = [cv.contourArea(c) for c in contours]
for cnt in contours:
#Only the largest contour area is considered for plotting
if(cv.contourArea(cnt) == max(cntArea)):
epsilon = 0.01*cv.arcLength(cnt,True)
#Polygonal Structure approximation
approx = cv.approxPolyDP(cnt,epsilon,True)
#Drawing the contour
img_radar2 = cv.drawContours(img_radar2,[approx],0,(0,0,255),2)
#Total number of pixels enclosed by the contour
TotalPixels = cv.contourArea(cnt)
#Area Calculation with respect to the km/pixel value as the image is in a (xx,xx,3) format the values measured are
#divided with 30 as the colour spectrum of 3 layers is calculated with respect to kilometer squares.
Area_2 = ((TotalPixels/30)*dresolution_2)
#Determining the centroid of the countour
X = cv.moments(cnt)
cX2 = int(X["m10"] / X["m00"])
cY2 = int(X["m01"] / X["m00"])
#Drawing a line perpendicular from the RADAR to the Contour centroid
img_radar2 = cv.line(img_radar2, (int(363), int(329)), (int(cX2), int(cY2)),(0,255,0), 2)
#Drwing points on the Contour Centroid and the RADAR Origin
img_radar2 = cv.circle(img_radar2, (cX2, cY2), 3, (0, 0, 0), -5)
img_radar2 = cv.circle(img_radar2, (363,329),3,(0,0,0),-5)
#Calculating the distance between the Contour Centroid and the RADAR Origin
D = distance.euclidean((363,329),(cX2,cY2))
DistanceFromRadar2 = round(D,2)
#Printing all the necessary details
print('RADAR 2:')
print('Date: '+ Date_2)
print('Time Stamp: ' + Time_2)
print('Radar Lat&Long: '+lat+" , "+long)
print('Distance From Radar:',round(DistanceFromRadar2*dresolution_2,2), 'km',DirectionOfConvective_System(cX2,cY2))
print("Total Area Covered is: "+str(round(Area_2,2))+" Km.sq")
#Ending the time sequence
end = time.time()
print(f"Runtime {end - start}")
#Ending the time sequence
cv.imshow("Result 2",img_radar2)
return 'Successful'
#Function for Radar statistics of double strength bar image-2
def getRadarStats_Double2(x):
ContourFormation = formcontour_Double2(x)
if(ContourFormation == 'Successful'):
print('\nConvective_System Found in 2nd Image')
return 'Successful'
else: print('\nNo Convective_System in 2nd Image')
#Function for Contour formation with respect to Single Strength bar images.
def formcontour_Single1(x):
#Initializing Time sequence
start = time.time()
#Decleration of global variables for image-1 perspective analysis in later functions
global dresolution_1, Date_1, Time_1, Area_1, cX1, cY1, approx1
img_main = x
#Cropping the image with respect to Radar Field in the image
img_radar = x[43:752,6:759]
#Convertion of the image into Gray scale and then a blur filter is used to patch the image
gray = cv.cvtColor(img_radar, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (11, 11), 0)
#Thresholding the image for potential area identification
thresh = cv.threshold(blurred, 200, 255, cv.THRESH_BINARY)[1]
thresh = cv.erode(thresh, None, iterations=1)
thresh = cv.dilate(thresh, None, iterations=1)
#Connected Component Analysis to find the major patch formations
labels = measure.label(thresh, connectivity = 2, background=0)
mask = np.zeros(thresh.shape, dtype="uint8")
# Loop formation over the unique categories
for label in np.unique(labels):
# If it were the background label then ignore it
if label == 0:
continue
# If it were the background label then ignore it
labelMask = np.zeros(thresh.shape, dtype="uint8")
labelMask[labels == label] = 255
numPixels = cv.countNonZero(labelMask)
# Adding the large components to the mask layer if the total number of connected pixels exceed the 150 range
if numPixels > 150:
mask = cv.add(mask, labelMask)
"""Implementation of the pytesseract library for text recognition and processing, the pytesseract library can
only process images in the RGB Spectrucm, so it is converted from BGR to RGB colour space"""
Date_1 = pytesseract.image_to_string((cv.cvtColor(img_main[14:39, 3:137],cv.COLOR_BGR2RGB)))
Time_1 = pytesseract.image_to_string(cv.resize((cv.cvtColor(img_main[14:43, 233:333],cv.COLOR_BGR2RGB)),(110,30)))
#In few cases the image needs to be resized for better recognition
#Lattitude and Logitude detection
lat = pytesseract.image_to_string((cv.resize((cv.cvtColor((img_main[20:39,794:848]),cv.COLOR_BGR2RGB)),(69,25))))
long = pytesseract.image_to_string((cv.resize((cv.cvtColor((img_main[22:39,863:925]),cv.COLOR_BGR2RGB)),(310,75))))
#Kilometer per pixel area recognition.
dresolution_1 =float(pytesseract.image_to_string(cv.resize(((cv.cvtColor((image1[83:100,923:960]),cv.COLOR_BGR2RGB))),(150,70))))
#Potential area contour formation for displaying the largest patches of the Convective_System
_, contours, _=cv.findContours(mask,cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
#Storing all the contour areas in one list
cntArea = [cv.contourArea(c) for c in contours]
for cnt in contours:
#Only the largest contour area is considered for plotting
if(cv.contourArea(cnt) == max(cntArea)):
epsilon = 0.01*cv.arcLength(cnt,True)
#Polygonal Structure approximation
approx1 = cv.approxPolyDP(cnt,epsilon,True)
#Drawing the contour
cv.drawContours(img_radar,[approx1],0,(0,0,255),2)
#Total number of pixels enclosed by the contour
TotalPixels = cv.contourArea(cnt)
#Area Calculation with respect to the km/pixel value as the image is in a (xx,xx,3) format the values measured are
#divided with 30 as the colour spectrum of 3 layers is calculated with respect to kilometer squares.
Area_1 = ((TotalPixels/30)*dresolution_1)
#Determining the centroid of the countour
X = cv.moments(cnt)
cX1 = int(X["m10"] / X["m00"])
cY1 = int(X["m01"] / X["m00"])
#Drawing a line perpendicular from the RADAR to the Contour centroid
cv.line(img_radar, (int(376), int(353)), (int(cX1), int(cY1)),(0,255,0), 2)
#Drwing points on the Contour Centroid and the RADAR Origin
cv.circle(img_radar, (cX1, cY1), 3, (0, 0, 0), -5)
cv.circle(img_radar, (376,353),3,(0,0,0),-5)
#Calculating the distance between the Contour Centroid and the RADAR Origin
D = distance.euclidean((363,329),(cX1,cY1))
DistanceFromRadar = round(D,2)
#Printing all the necessary details
print('RADAR 1:')
print('Date1: '+ Date_1)
print('Time Stamp 1: ' + Time_1)
print('Radar Lat&Long: '+lat+" , "+long)
print('Distance From Radar:',round(DistanceFromRadar*dresolution_1,2), 'km',DirectionOfConvective_System(cX1,cY1))
print("Total Area Covered is: "+str(round(Area_1,2))+" Km.sq")
#Ending the time sequence
end = time.time()
print(f"Runtime {end - start}")
#Displaying the image
cv.imshow("Result 1",img_radar)
return 'Successful'
def getRadarStats_Single1(x):
ContourFormation = formcontour_Single1(x)
if(ContourFormation == 'Successful'):
print('\nConvective_System Found in 1st Image')
return 'Successful'
else: print('\nNo Convective_System in 1st Image')
#Function for Contour formation with respect to Single Strength bar images.
def formcontour_Single2(x):
#Initializing Time sequence
start = time.time()
#Decleration of global variables for image-1 perspective analysis in later functions
global dresolution_2, Date_2, Time_2, Area_2, cX2, cY2, img_radar2
img_main = x
#Decleration of global variables for image-1 perspective analysis in later functions
img_radar2 = x[43:752,6:759]
#Convertion of the image into Gray scale and then a blur filter is used to patch the image
gray = cv.cvtColor(img_radar2, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (11, 11), 0)
#Thresholding the image for potential area identification
thresh = cv.threshold(blurred, 200, 255, cv.THRESH_BINARY)[1]
thresh = cv.erode(thresh, None, iterations=1)
thresh = cv.dilate(thresh, None, iterations=1)
#Connected Component Analysis to find the major patch formations
labels = measure.label(thresh, connectivity = 2, background=0)
mask = np.zeros(thresh.shape, dtype="uint8")
# Loop formation over the unique categories
for label in np.unique(labels):
# If it were the background label then ignore it
if label == 0:
continue
# Construction of the label mask and determining the total number of pixels in the patches
labelMask = np.zeros(thresh.shape, dtype="uint8")
labelMask[labels == label] = 255
numPixels = cv.countNonZero(labelMask)
# Adding the large components to the mask layer if the total number of connected pixels exceed the 150 range
if numPixels > 150:
mask = cv.add(mask, labelMask)
"""Implementation of the pytesseract library for text recognition and processing, the pytesseract library can
only process images in the RGB Spectrucm, so it is converted from BGR to RGB colour space"""
Date_2 = pytesseract.image_to_string((cv.cvtColor(img_main[14:39, 3:137],cv.COLOR_BGR2RGB)))
Time_2 = pytesseract.image_to_string(cv.resize((cv.cvtColor(img_main[14:43, 233:333],cv.COLOR_BGR2RGB)),(110,30)))
#In few cases the image needs to be resized for better recognition
#Lattitude and Logitude detection
lat = pytesseract.image_to_string((cv.resize((cv.cvtColor((img_main[20:39,794:848]),cv.COLOR_BGR2RGB)),(69,25))))
long = pytesseract.image_to_string((cv.resize((cv.cvtColor((img_main[22:39,863:925]),cv.COLOR_BGR2RGB)),(310,75))))
#Kilometer per pixel area recognition.
dresolution_2 =float(pytesseract.image_to_string(cv.resize(((cv.cvtColor((image1[83:100,923:960]),cv.COLOR_BGR2RGB))),(150,70))))
#Potential area contour formation for displaying the largest patches of the Convective_System
_, contours, _=cv.findContours(mask,cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
#Storing all the contour areas in one list
cntArea = [cv.contourArea(c) for c in contours]
for cnt in contours:
#Only the largest contour area is considered for plotting
if(cv.contourArea(cnt) == max(cntArea)):
epsilon = 0.01*cv.arcLength(cnt,True)
#Polygonal Structure approximation
approx = cv.approxPolyDP(cnt,epsilon,True)
#Drawing the contour
img_radar2 = cv.drawContours(img_radar2,[approx],0,(0,0,255),2)
#Total number of pixels enclosed by the contour
TotalPixels = cv.contourArea(cnt)
#Area Calculation with respect to the km/pixel value as the image is in a (xx,xx,3) format the values measured are
#divided with 30 as the colour spectrum of 3 layers is calculated with respect to kilometer squares.
Area_2 = ((TotalPixels/30)*dresolution_2)
#Determining the centroid of the countour
X = cv.moments(cnt)
cX2 = int(X["m10"] / X["m00"])
cY2 = int(X["m01"] / X["m00"])
#Drawing a line perpendicular from the RADAR to the Contour centroid
img_radar2 = cv.line(img_radar2, (int(376), int(353)), (int(cX2), int(cY2)),(0,255,0), 2)
#Drwing points on the Contour Centroid and the RADAR Origin
img_radar2 = cv.circle(img_radar2, (cX2, cY2), 3, (0, 0, 0), -5)
img_radar2 = cv.circle(img_radar2, (376,353),3,(0,0,0),-5)
#Calculating the distance between the Contour Centroid and the RADAR Origin
D = distance.euclidean((363,329),(cX2,cY2))
DistanceFromRadar = round(D,2)
#Printing all the necessary details
print('RADAR 2:')
print('Date2: '+ Date_2)
print('Time Stamp 2: ' + Time_2)
print('Radar Lat&Long: '+lat+" , "+long)
print('Distance From Radar:',round(DistanceFromRadar*dresolution_2,2), 'km',DirectionOfConvective_System(cX2,cY2))
print("Total Area Covered is: "+str(round(Area_2,2))+" Km.sq")
#Ending the time sequence
end = time.time()
print(f"Runtime {end - start}")
#Ending the time sequence
cv.imshow("Result 2",img_radar2)
return 'Successful'
#Function for Radar statistics of Single strength bar image-2
def getRadarStats_Single2(x):
ContourFormation = formcontour_Single2(x)
if(ContourFormation == 'Successful'):
print('\nConvective_System Found in 2nd Image')
return 'Successful'
else: print('\nNo Convective_System in 2nd Image')
"""A conditional function to determine the direction of the Convective_System/Potential area
i.e, 0 = North; 90 = East; 180 = South; 270 = West; 360 = North
for the NE, NW, SE, SW detection, the complete radar area is subdivided into 4 Quadrants and then calculated accordingly."""
def DirectionOfConvective_System(x,y):
if(x == 363 and y < 329): return 'North'
elif(x >= 358 and x <= 369 and y < 288): return 'North'
elif(x > 369 and y < 329): return 'North East '
elif(x > 363 and y == 329): return 'Easy'
elif(x > 490 and y >= 324 and y <= 334): return 'East'
elif (x > 363 and y > 334): return 'South East'
elif(x == 363 and y > 329): return 'South'
elif(x >= 358 and x <= 369 and y > 500): return 'South'
elif(x < 358 and y > 334): return 'South West'
elif(x < 363 and y == 329): return 'West'
elif(x < 230 and y >= 324 and y <= 334): return 'West'
elif(x < 358 and y < 334): return 'North West'
"""The pytesseract library converts the image matrix into string values, but for time calculation purpose we use the following
function to calculate the total number of seconds by splitting the time string value in to sub divisions as Hours,Mininutes & Seconds"""
def get_sec(time_str):
#Splitting with respect to collon as the time in string is of the form HH:MM:SS
h, m, s = time_str.split(':')
#Multiplying the respective values with seconds equivalents and returning from the called function
return int(h) * 3600 + int(m) * 60 + int(s)
#Combined function for RADAR information determination and tracking.
#In the following function the conditional statements are used to execute various functions depending on the image dimensions.
def FinalRadarStats(image1,image2):
global radar1_info, radar2_info
if(image1.shape == (770,1078,3)):
radar1_info = getRadarStats_Single1(image1)
elif(image1.shape == (720,1082,3)):
radar1_info = getRadarStats_Double1(image1)
if(image2.shape == (770,1078,3)):
radar2_info = getRadarStats_Single2(image2)
elif(image2.shape == (720,1082,3)):
radar2_info = getRadarStats_Double2(image2)
#Calling the combined function for complete RADAR Stats
FinalRadarStats(image1,image2)
# The following statement will run if the time difference is less than 70minutes, Area difference is less than 20 km.sq
# and displacement less than 100 km
if(radar1_info == 'Successful' and radar2_info == 'Successful'):
#Time difference between the two detections in minutes
time_difference = round((abs(get_sec(Time_1)-get_sec(Time_2)))/60,2)
#Area difference between two detections
area_difference = round((abs(Area_1 - Area_2)),2)
#Displacement between two time stamps with respect to the respective centroids
distance_travelled = round((distance.euclidean((cX1,cY1),(cX2,cY2)))*dresolution_2 ,2)
if(time_difference < 70 and area_difference < 40 and distance_travelled < 60):
#Printing the time difference, area difference & the displacement of the convective systems.
print('Time Difference: ', time_difference, 'Minutes')
print('Area Difference: ',area_difference, 'Km.sq')
print('Distance Travelled by Convective_System: ', distance_travelled,'Km')
print('Convective_System TRACKED SUCCESSFULLY!!!!')
#Drawing relationg between consecutive frames
img_radar2 = cv.drawContours(img_radar2,[approx1],0,(0,255,0),2)
img_radar2 = cv.line(img_radar2, (int(cX1), int(cY1)), (int(cX2), int(cY2)),(0,0,0), 2)
img_radar2 = cv.circle(img_radar2, (cX1, cY1), 3, (0, 0, 0), -5)
img_radar2 = cv.circle(img_radar2, (cX2, cY2), 3, (0, 0, 0), -5)
cv.imshow('Final', img_radar2)
else: print("\nConvective_System Couldn't be traced")
else: print('\nConvective_System Not Traced')
#Displaying the Convective_System
cv.waitKey(0)
#The following command can be uncommented to save the final image to the required destination
# cv.imwrite('Destination_Path',img_radar2)