This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
__init__.py
97 lines (71 loc) · 3.52 KB
/
__init__.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
import cv2
import matplotlib
import matplotlib.pyplot as plt
from utils import PixelLocation
from gpsupdater import GPSUpdater
from geocalculation import GeoCalculation
def main():
image = "src/istanbul_aerial_1pixel_10_centimeters.png"
image = cv2.imread(image, 1)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
height, width = image.shape[:2]
print(width, height, "width, height")
ratio_pixel_centimeters = 10
selected_position = PixelLocation(
label="GPS location known place",
x_pixel=int(width / 2) ,
y_pixel=480,
latitude=28.971832514674194,
longitude= 41.01209534207387,
)
calculation_position = PixelLocation(
label="GPS location, location to be calculated",
x_pixel=int(width / 2) + 1000, # 1000 / ratio_pixel_centimeters = 100 meters east
y_pixel=480 + 2000, # 2000 / ratio_pixel_centimeters = 200 meters south
latitude=0.0,
longitude= 0.0,
)
print('selected_position x:{0}, y:{1}, calculation_position x:{2}, y:{3}'.format(selected_position.x_pixel,
selected_position.y_pixel,
calculation_position.x_pixel,
calculation_position.y_pixel))
text_selected = 'selected_position latitude:{0:.7f}, longitude:{1:.7f}, '.format(selected_position.latitude,
selected_position.longitude)
print(text_selected)
distance, bearing = GPSUpdater.distance_bearing_calculator_using_parameters(destination_x=calculation_position.x_pixel,
destination_y=calculation_position.y_pixel,
source_x=selected_position.x_pixel,
source_y=selected_position.y_pixel,
image_height=height,
pixel_in_centimeters=ratio_pixel_centimeters)
print('distance:{0} bearing:{1}'.format(distance,bearing))
calculation_position.latitude, calculation_position.longitude = GeoCalculation.calculate_new_gps_position(lat1=selected_position.latitude,
lon1=selected_position.longitude,distance=distance,bearing=bearing)
text_calculation = 'calculation_position latitude:{0:.7f}, longitude:{1:.7f}'.format(calculation_position.latitude,calculation_position.longitude)
print(text_calculation)
start_point = (selected_position.x_pixel, selected_position.y_pixel)
end_point = (calculation_position.x_pixel, calculation_position.y_pixel )
thickness = 10
color = (255, 0, 0)
image = cv2.line(image, start_point, end_point, color, thickness)
org_y = 200
org_x = 10
org = (org_x, org_y) # x:column y:row
font = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 3
color = (255, 255, 0)
paddingText = 50
cv2.putText(image, text_selected, org, font, fontScale, color, thickness, cv2.LINE_AA)
org_y = org_y+3*paddingText+thickness
org_x = 10
org = (org_x, org_y)
cv2.putText(image,text_calculation , org, font, fontScale, color, thickness, cv2.LINE_AA)
org_y = org_y+3*paddingText+thickness
org_x = 10
org = (org_x, org_y)
cv2.putText(image,'different distance:{0:.2f} meters'.format(distance) , org, font, fontScale, color, thickness, cv2.LINE_AA)
plt.figure(figsize=(10, 10))
plt.imshow(image)
plt.show()
if __name__ == '__main__':
main()