-
Notifications
You must be signed in to change notification settings - Fork 5
/
QGisMap.py
630 lines (579 loc) · 34.1 KB
/
QGisMap.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
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
624
625
626
627
628
629
630
# -*- coding: utf-8 -*-
'''
Video Uav Tracker v 2.0
Replay a video in sync with a gps track displayed on the map.
-------------------
copyright : (C) 2017 by Salvatore Agosta
email : sagost@katamail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
INSTRUCTION:
Syncing:
- Create new project
- Select video and .gpx track (1 trkpt per second)
- Identify first couple Frame/GpsTime and select it.
- Push Synchronize
- Push Start
Replay:
- Move on map
- Create associated DB shapefile
- Add POI with associated video frame saved
- Extract frames with associated coordinates for rapid photogrammetry use
'''
from vut_qgismap import Ui_Form
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QFileInfo,QUrl
from PyQt5.QtWidgets import QMessageBox , QFileDialog , QStyle, QVBoxLayout, QInputDialog, QLineEdit
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtGui import QColor
from SkipTrackTool import *
from AddPoint import *
from CanvasMarkers import PositionMarker
import os
import sys
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from osgeo import osr
from geographiclib.geodesic import Geodesic
from qgis.core import *
from qgis.gui import *
class QGisMap(QtWidgets.QWidget, Ui_Form):
def __init__(self,projectfile,MainWidget):
QtWidgets.QMainWindow.__init__(self)
if os.name == 'nt':
ffmpeg = os.path.dirname(__file__)[0:-18]+'/Video_UAV_Tracker/FFMPEG/ffmpeg.exe'
versione = 'ffmpeg.exe'
else:
ffmpeg = os.path.dirname(__file__)+'/FFMPEG/./ffmpeg'
versione = 'ffmpeg'
if os.path.exists(ffmpeg) == True:
self.setupUi(self)
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.Main = MainWidget
self.projectfile = projectfile
with open(self.projectfile,'r') as File:
for line in File:
if line[0:19] == 'Video file location':
self.videoFile = line.split('=')[-1][1:-1]
elif line[0:23] == 'Video start at msecond:':
self.fps = (1 / (float(line.split()[7]))) * 1000
self.StartMsecond = int(line.split()[4])
elif line[0:4] == 'DB =':
DB = line.split('=')[-1][1:-1]
if DB == 'None':
self.DB = None
else:
self.DB = DB
break
self.pushButton_3.setCheckable(True)
self.EnableMapTool = False
self.ExtractTool = 0
self.dockWidget_4.hide()
self.GPXList = []
self.positionMarker=PositionMarker(self.Main.iface.mapCanvas())
self.muteButton.setIcon(
self.style().standardIcon(QStyle.SP_MediaVolume))
self.playButton.setIcon(
self.style().standardIcon(QStyle.SP_MediaPause))
self.player = QMediaPlayer()
self.player.setVideoOutput(self.video_frame)
self.playButton.clicked.connect(self.PlayPause)
self.muteButton.clicked.connect(self.MuteUnmute)
self.toolButton_11.clicked.connect(self.SkipBackward)
self.toolButton_12.clicked.connect(self.SkipForward)
self.SkipBacktoolButton_8.clicked.connect(self.BackwardFrame)
self.SkipFortoolButton_9.clicked.connect(self.ForwardFrame)
self.toolButton_4.clicked.connect(self.ExtractToolbar)
self.toolButton_5.clicked.connect(self.close)
self.pushButtonCut_2.clicked.connect(self.ExtractCommand)
self.pushButtonCutA_6.clicked.connect(self.ExtractFromA)
self.pushButtonCutB_6.clicked.connect(self.ExtractToB)
self.pushButton_5.clicked.connect(self.CancelVertex)
self.progressBar.hide()
self.Main.pushButton_2.hide()
self.Main.pushButton_8.hide()
self.Main.groupBox.show()
self.Main.groupBox_4.hide()
self.ExtractA = False
self.ExtractB = False
self.ExtractedDirectory = None
self.pushButtonCut_2.setEnabled(False)
self.toolButton_6.setEnabled(False)
self.LoadGPXVideoFromPrj(self.projectfile)
else:
ret = QMessageBox.warning(self, "Warning", 'missing ffmpeg binaries, please download it from https://github.com/sagost/VideoUavTracker/blob/master/FFMPEG/'+versione+' and paste it in /.qgis3/python/plugins/Video_UAV_Tracker/FFMPEG/ ', QMessageBox.Ok)
self.close()
def LoadGPXVideoFromPrj(self,VideoGisPrj):
self.Polyline = []
with open(VideoGisPrj,'r') as File:
Counter = 0
for line in File:
if Counter < 5:
pass
else:
line = line.split()
lat = float(line[0])
lon = float(line[1])
ele = float(line[2])
speed = float(line[3])
course = float(line[4])
time = line[5]
Point = [lat,lon,ele,speed,course,time]
qgsPoint = QgsPoint(lon,lat)
self.Polyline.append(qgsPoint)
self.GPXList.append(Point)
Counter = Counter + 1
self.GpsLayer = QgsVectorLayer("LineString?crs=epsg:4326", self.videoFile.split('.')[-2].split('/')[-1], "memory")
self.pr = self.GpsLayer.dataProvider()
feat = QgsFeature()
feat.setGeometry(QgsGeometry.fromPolyline(self.Polyline))
self.pr.addFeatures([feat])
self.GpsLayer.updateExtents()
if self.DB != None:
try:
self.DBLayer = QgsVectorLayer(self.DB,self.DB.split('.')[-2].split('/')[-1],'ogr')
QgsProject.instance().addMapLayers([self.DBLayer,self.GpsLayer])
self.AddPointMapTool = AddPointTool(self.Main.iface.mapCanvas(),self.DBLayer,self)
self.toolButton_6.clicked.connect(self.AddPointTool)
self.toolButton_6.setEnabled(True)
except:
ret = QMessageBox.warning(self, "Warning", str(self.DB)+' is not a valid shapefile.', QMessageBox.Ok)
return
else:
QgsProject.instance().addMapLayers([self.GpsLayer])
self.duration = len(self.GPXList)
self.ExtractToB = self.duration
self.horizontalSlider.setSingleStep(1000)
self.horizontalSlider.setMinimum(0)
self.horizontalSlider.setMaximum(len(self.GPXList)*1000)
url = QUrl.fromLocalFile(str(self.videoFile))
mc = QMediaContent(url)
self.player.setMedia(mc)
self.player.setPosition(self.StartMsecond)
self.player.play()
self.horizontalSlider.sliderMoved.connect(self.setPosition)
self.player.stateChanged.connect(self.mediaStateChanged)
self.player.positionChanged.connect(self.positionChanged)
self.pushButton_3.clicked.connect(self.MapTool)
self.skiptracktool = SkipTrackTool( self.Main.iface.mapCanvas(),self.GpsLayer , self)
def AddPointTool(self):
self.Main.iface.mapCanvas().setMapTool(self.AddPointMapTool)
def MapTool(self):
if self.EnableMapTool == False:
self.Main.iface.mapCanvas().setMapTool(self.skiptracktool)
self.pushButton_3.setChecked(True)
self.EnableMapTool = True
else:
self.Main.iface.mapCanvas().unsetMapTool(self.skiptracktool)
self.pushButton_3.setChecked(False)
self.EnableMapTool = False
def closeEvent(self, *args, **kwargs):
try:
self.player.stop()
self.Main.iface.mapCanvas().scene().removeItem(self.positionMarker)
self.CancelVertex()
self.Main.pushButton_2.show()
#self.Main.horizontalSpacer_2.show()
self.Main.groupBox.hide()
self.Main.pushButton_8.show()
self.Main.groupBox_4.show()
self.dockWidget_2.close()
except:
pass
return QtWidgets.QWidget.closeEvent(self, *args, **kwargs)
def mediaStateChanged(self, state):
if self.player.state() == QMediaPlayer.PlayingState:
self.playButton.setIcon(
self.style().standardIcon(QStyle.SP_MediaPause))
else:
self.playButton.setIcon(
self.style().standardIcon(QStyle.SP_MediaPlay))
def setPosition(self, position):
self.player.setPosition(position+self.StartMsecond)
def secTotime(self,seconds):
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
return "%d:%02d:%02d" % (h, m, s)
def positionChanged(self, progress):
if progress < self.StartMsecond:
self.player.setPosition(self.StartMsecond)
progress = self.StartMsecond
AssociatedGps = round((progress - self.StartMsecond )/1000)
self.DisplayPoint(AssociatedGps)
totalTime = self.secTotime(self.duration)
actualTime = self.secTotime((progress - self.StartMsecond )/1000)
self.replayPosition_label.setText(actualTime + ' / '+totalTime)
if not self.horizontalSlider.isSliderDown():
self.horizontalSlider.setValue(progress - self.StartMsecond )
def DisplayPoint(self,Point):
if Point >= len(self.GPXList):
Point = len(self.GPXList) - 1
gpx = self.GPXList[Point]
lat = round(gpx[0],7)
lon = round(gpx[1],7)
ele = gpx[2]
speed = gpx[3]
course = gpx[4]
time = gpx[5]
Point = QgsPointXY()
Point.set(lon, lat)
canvas = self.Main.iface.mapCanvas()
crsSrc = QgsCoordinateReferenceSystem(4326) # .gpx is in WGS 84
crsDest = QgsProject.instance().crs()
xform = QgsCoordinateTransform(crsSrc, crsDest)
self.positionMarker.setHasPosition(True)
self.Point = xform.transform(Point)
self.positionMarker.newCoords(self.Point)
self.positionMarker.angle = float(course)
extent = canvas.extent()
boundaryExtent=QgsRectangle(extent)
boundaryExtent.scale(0.7)
if not boundaryExtent.contains(QgsRectangle(Point, self.Point)):
extentCenter= self.Point
newExtent=QgsRectangle(
extentCenter.x()-extent.width()/2,
extentCenter.y()-extent.height()/2,
extentCenter.x()+extent.width()/2,
extentCenter.y()+extent.height()/2
)
self.Main.iface.mapCanvas().setExtent(newExtent)
self.Main.iface.mapCanvas().refresh()
self.Main.label_14.setText('GPS Time: '+str(time))
self.Main.label_15.setText('Course: '+"%.2f" % (course))
self.Main.label_16.setText('Ele: '+"%.2f" %(ele))
self.Main.label_17.setText('Speed m/s: '+"%.2f" %(speed))
self.Main.label_19.setText('Lat : '+str(lat))
self.Main.label_18.setText('Lon : '+str(lon))
def MuteUnmute(self):
if self.player.mediaStatus() == 6 :
if self.player.isMuted() == 1:
self.player.setMuted(0)
self.muteButton.setIcon(
self.style().standardIcon(QStyle.SP_MediaVolume))
elif self.player.isMuted() == 0:
self.player.setMuted(1)
self.muteButton.setIcon(
self.style().standardIcon(QStyle.SP_MediaVolumeMuted))
def SkipForward(self):
position = self.player.position()
self.player.setPosition(position+1000)
def SkipBackward(self):
position = self.player.position()
self.player.setPosition(position-1000)
def ForwardFrame(self):
position = self.player.position()
self.player.setPosition(position+int(self.fps))
def BackwardFrame(self):
position = self.player.position()
self.player.setPosition(position-int(self.fps))
def PlayPause(self):
if self.player.state() == QMediaPlayer.PlayingState:
self.player.pause()
else:
self.player.play()
def findNearestPointInRecording(self, x,y):
ClickPt = QgsPoint(x,y)
Low = ClickPt.distanceSquared(self.Polyline[0])
NearPoint = 0
Counter = 0
for Point in self.Polyline:
dist = ClickPt.distanceSquared(Point)
if dist < Low:
Low = dist
NearPoint = Counter
Counter = Counter + 1
else:
Counter = Counter + 1
self.setPosition(NearPoint*1000)
def ExtractSingleFrameOnTime(self, pos, outputfile):
if os.name == 'nt':
ffmpeg = ('"'+os.path.dirname(__file__)[0:-18]+'/Video_UAV_Tracker/FFMPEG/ffmpeg.exe'+'"')
os.popen(str(ffmpeg)+' -ss '+str(pos/1000)+' -i '+str('"' +self.videoFile+ '"')+ ' -t 1 '+str('"'+outputfile+'"'))
else:
ffmpeg = os.path.dirname(__file__)+'/FFMPEG/./ffmpeg'
os.system(str(ffmpeg)+' -ss '+str(pos/1000)+' -i '+str(self.videoFile)+' -t 1 '+str(outputfile))
def AddPoint(self,x,y):
self.Main.iface.mapCanvas().unsetMapTool(self.AddPointMapTool)
Point = QgsPointXY(x,y)
pos = self.player.position()
if self.player.state() == QMediaPlayer.PlayingState:
self.player.pause()
a = self.DBLayer.name()
last_desc = '///'
LayerName =str(a)
last_desc2 = LayerName + ' Point N '
directory = str(self.DB.split('.')[0])+'_Image/'
if not os.path.exists(directory):
os.makedirs(directory)
fc = int(self.DBLayer.featureCount())
self.ExtractSingleFrameOnTime(pos,directory+LayerName+'_'+str(fc)+'_.jpg')
fields = self.DBLayer.fields()
attributes = []
lat,lon = Point.y(), Point.x()
for field in fields:
a = str(field.name())
b = str(field.typeName())
if a == 'id':
fcnr = fc
attributes.append(fcnr)
elif a == 'Lon(WGS84)':
attributes.append(str(lon))
elif a == 'Lat(WGS84)':
attributes.append(str(lat))
elif a == 'Image link':
attributes.append(str(directory+LayerName+'_'+str(fc)+'_.jpg'))
else:
if b == 'String':
(a,ok) = QInputDialog.getText(
self.Main.iface.mainWindow(),
"Attributes",
a + ' = String',
QLineEdit.Normal)
attributes.append(a)
elif b == 'Real':
(a,ok) = QInputDialog.getDouble(
self.Main.iface.mainWindow(),
"Attributes",
a + ' = Real', decimals = 10)
attributes.append(a)
elif b == 'Integer64':
(a,ok) = QInputDialog.getInt(
self.Main.iface.mainWindow(),
"Attributes",
a + ' = Integer')
attributes.append(a)
feature = QgsFeature()
feature.setGeometry(QgsGeometry.fromPoint(Point))
feature.setAttributes(attributes)
self.DBLayer.startEditing()
self.DBLayer.addFeature(feature)
self.DBLayer.commitChanges()
self.DBLayer.triggerRepaint()
def ExtractCommand(self):
if self.ExtractToB <= self.ExtractFromA:
ret = QMessageBox.warning(self, "Warning", '"To B" point must be after "from A" point', QMessageBox.Ok)
self.CancelVertex()
else:
if os.name == 'nt':
ffmpeg = '"'+os.path.dirname(__file__)[0:-18]+'/Video_UAV_Tracker/FFMPEG/ffmpeg.exe'+'"'
else:
ffmpeg = os.path.dirname(__file__)+'/FFMPEG/./ffmpeg'
Directory,_ = QFileDialog.getSaveFileName(caption= 'Save georeferenced images')
if Directory:
self.progressBar.show()
self.progressBar.setValue(0)
start = self.ExtractFromA
if self.comboBox_6.currentText() == 'seconds':
finish = self.ExtractToB - self.ExtractFromA
fps = self.doubleSpinBox_2.value()
if fps < 1.0:
fps = 1.0 / fps
elif fps > 1:
fps = 1.0 / fps
if os.name == 'nt':
os.popen(str(ffmpeg+ ' -ss ' + str(start) + ' -i '+ str('"'+self.videoFile+'"')+ ' -t ' + str(finish) + ' -vf fps=' + str(fps) + ' ' + '"'+Directory + '_%d.png'+'"'))
else:
os.system(ffmpeg+' -ss '+ str(start) + ' -i '+ str(self.videoFile) + ' -t ' + str(finish) + ' -vf fps=' + str(fps) + ' ' + Directory + '_%d.png')
else:
txtGPSFile = open(Directory + 'UTM_Coordinates.txt', 'w')
txtGPSFile.close()
txtGPSFile = open(Directory+ 'UTM_Coordinates.txt', 'a')
txtGPSFile.write('filename # East UTM # North UTM # Ele '+ '\n')
finish = self.ExtractToB
meters = self.doubleSpinBox_2.value()
Timerange = range(start, finish + 1)
RemainToUseMeterTotal = 0
if os.name == 'nt':
os.popen(ffmpeg+' -ss '+ str(start) + ' -i '+ str('"'+self.videoFile+'"') + ' -frames:v 1 ' + '"'+Directory + '_sec_' + str(start)+'.00.png'+'"')
else:
os.system(ffmpeg+' -ss '+ str(start) + ' -i '+ str(self.videoFile) + ' -frames:v 1 ' + Directory + '_sec_' + str(start)+'.00.png')
lonUTM, latUTM,quotainutile = self.transform_wgs84_to_utm(float(self.GPXList[start][1]) , float(self.GPXList[start][0]))
ele = float(self.GPXList[start][2])
txtGPSFile.write(str(Directory.split('/')[-1]) + '_sec_' + str(start)+'.00.png,'+' '+ str(lonUTM) + ', '+ str(latUTM) + ', ' + str(ele) + '\n')
for i in Timerange:
progessBarValue = ((i-start) * 100) // len(Timerange)
self.progressBar.setValue(int(progessBarValue))
latitude1,longitude1 = float(self.GPXList[i][0]) ,float(self.GPXList[i][1])
latitude2,longitude2 = float(self.GPXList[i+1][0]) ,float(self.GPXList[i+1][1])
ele1 = float(self.GPXList[i][2])
ele2 = float(self.GPXList[i+1][2])
Calculus = Geodesic.WGS84.Inverse(latitude1, longitude1, latitude2, longitude2)
DistanceBetweenPoint = Calculus['s12']
Azimuth = Calculus['azi2']
SpeedMeterSecond = DistanceBetweenPoint #GPS refresh rate is actually 1, change parameter for different rates
# Time = 1
if RemainToUseMeterTotal == 0:
if DistanceBetweenPoint >= meters:
decimalSecondToAdd = meters / DistanceBetweenPoint
RemainToUseMeter = DistanceBetweenPoint - meters
if os.name == 'nt':
os.popen(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str('"'+self.videoFile+'"') + ' -frames:v 1 ' +'"'+ Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png'+'"')
else:
os.system(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str(self.videoFile) + ' -frames:v 1 ' + Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png')
CalculusDirect = Geodesic.WGS84.Direct(latitude1, longitude1, Azimuth,decimalSecondToAdd* SpeedMeterSecond)
X,Y,quotainutile = self.transform_wgs84_to_utm(CalculusDirect['lon2'],CalculusDirect['lat2'] )
Z = ele1 + decimalSecondToAdd*(ele2 - ele1)
txtGPSFile.write(str(Directory.split('/')[-1]) + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4]+'.png,' + ' ' + str(X) + ', ' + str(Y) + ', ' + str(Z) + '\n')
while RemainToUseMeter > meters:
decimalSecondToAddMore = meters / SpeedMeterSecond
RemainToUseMeter = RemainToUseMeter - meters
decimalSecondToAdd = decimalSecondToAdd + decimalSecondToAddMore
if os.name == 'nt':
os.popen(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str('"'+self.videoFile+'"') + ' -frames:v 1 ' +'"'+ Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png'+'"')
else:
os.system(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str(self.videoFile) + ' -frames:v 1 ' + Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png')
CalculusDirect = Geodesic.WGS84.Direct(latitude1, longitude1, Azimuth,decimalSecondToAdd* SpeedMeterSecond)
X,Y,quotainutile = self.transform_wgs84_to_utm(CalculusDirect['lon2'],CalculusDirect['lat2'] )
Z = ele1 + decimalSecondToAdd*(ele2 - ele1)
txtGPSFile.write(str(Directory.split('/')[-1]) + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4]+'.png,' + ' ' + str(X) + ', ' + str(Y) + ', ' + str(Z) + '\n')
if RemainToUseMeter == meters:
decimalSecondToAddMore = meters / SpeedMeterSecond
RemainToUseMeter = RemainToUseMeter - meters
decimalSecondToAdd = decimalSecondToAdd + decimalSecondToAddMore
if os.name == 'nt':
os.popen(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str('"'+self.videoFile+'"') + ' -frames:v 1 ' +'"'+ Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png'+'"')
else:
os.system(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str(self.videoFile) + ' -frames:v 1 ' + Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png')
CalculusDirect = Geodesic.WGS84.Direct(latitude1, longitude1, Azimuth,decimalSecondToAdd* SpeedMeterSecond)
X,Y,quotainutile = self.transform_wgs84_to_utm(CalculusDirect['lon2'],CalculusDirect['lat2'] )
Z = ele1 + decimalSecondToAdd*(ele2 - ele1)
txtGPSFile.write(str(Directory.split('/')[-1]) + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4]+'.png,' + ' ' +str(X) + ', ' + str(Y) + ', ' + str(Z) + '\n')
RemainToUseMeterTotal = 0
elif RemainToUseMeter < meters:
RemainToUseMeterTotal = RemainToUseMeter
pass
else:
RemainToUseMeterTotal = meters - DistanceBetweenPoint
elif RemainToUseMeterTotal > 0:
if DistanceBetweenPoint >= (meters - RemainToUseMeterTotal) :
decimalSecondToAdd = (meters - RemainToUseMeterTotal) / DistanceBetweenPoint
RemainToUseMeter = DistanceBetweenPoint - (meters - RemainToUseMeterTotal)
if os.name == 'nt':
os.popen(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str('"'+self.videoFile+'"') + ' -frames:v 1 ' +'"'+ Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png'+'"')
else:
os.system(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str(self.videoFile) + ' -frames:v 1 ' + Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png')
CalculusDirect = Geodesic.WGS84.Direct(latitude1, longitude1, Azimuth,decimalSecondToAdd* SpeedMeterSecond)
X,Y,quotainutile = self.transform_wgs84_to_utm(CalculusDirect['lon2'],CalculusDirect['lat2'] )
Z = ele1 + decimalSecondToAdd*(ele2 - ele1)
txtGPSFile.write(str(Directory.split('/')[-1]) + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4]+'.png,' + ' ' + str(X) + ', ' + str(Y) + ', ' + str(Z) + '\n')
while RemainToUseMeter > meters:
decimalSecondToAddMore = meters / SpeedMeterSecond
RemainToUseMeter = RemainToUseMeter - meters
decimalSecondToAdd = decimalSecondToAdd + decimalSecondToAddMore
if os.name == 'nt':
os.popen(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str('"'+self.videoFile+'"') + ' -frames:v 1 ' +'"'+ Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png'+'"')
else:
os.system(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str(self.videoFile) + ' -frames:v 1 ' + Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png')
CalculusDirect = Geodesic.WGS84.Direct(latitude1, longitude1, Azimuth,decimalSecondToAdd* SpeedMeterSecond)
X,Y,quotainutile = self.transform_wgs84_to_utm(CalculusDirect['lon2'],CalculusDirect['lat2'] )
Z = ele1 + decimalSecondToAdd*(ele2 - ele1)
txtGPSFile.write(str(Directory.split('/')[-1]) + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4]+'.png,' + ' ' + str(X) + ', ' + str(Y) + ', ' + str(Z) + '\n')
if RemainToUseMeter == meters:
decimalSecondToAddMore = meters / SpeedMeterSecond
RemainToUseMeter = RemainToUseMeter - meters
decimalSecondToAdd = decimalSecondToAdd + decimalSecondToAddMore
if os.name == 'nt':
os.popen(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str('"'+self.videoFile+'"') + ' -frames:v 1 ' +'"'+ Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png'+'"')
else:
os.system(ffmpeg+ ' -ss '+ str(i + decimalSecondToAdd) +
' -i '+ str(self.videoFile) + ' -frames:v 1 ' + Directory + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4] +'.png')
CalculusDirect = Geodesic.WGS84.Direct(latitude1, longitude1, Azimuth,decimalSecondToAdd* SpeedMeterSecond)
X,Y,quotainutile = self.transform_wgs84_to_utm(CalculusDirect['lon2'],CalculusDirect['lat2'] )
Z = ele1 + decimalSecondToAdd*(ele2 - ele1)
txtGPSFile.write(str(Directory.split('/')[-1]) + '_sec_' + str(i) + str(decimalSecondToAdd)[1:4]+'.png,' + ' ' + str(X) + ', ' + str(Y) + ', ' + str(Z) + '\n')
RemainToUseMeterTotal = 0
elif RemainToUseMeter < meters:
RemainToUseMeterTotal = RemainToUseMeter
else:
RemainToUseMeterTotal = (meters - DistanceBetweenPoint) + RemainToUseMeterTotal
txtGPSFile.close()
self.progressBar.hide()
def ExtractFromA(self):
if self.ExtractA == True:
self.Main.iface.mapCanvas().scene().removeItem(self.ExtractAVertex)
self.ExtractA = False
self.ExtractFromA = round((self.player.position()- self.StartMsecond )/1000)
canvas = self.Main.iface.mapCanvas()
crsSrc = QgsCoordinateReferenceSystem(4326) # .gpx is in WGS 84
crsDest = QgsProject.instance().crs()
xform = QgsCoordinateTransform(crsSrc, crsDest)
latitude,longitude = self.Polyline[self.ExtractFromA].y(), self.Polyline[self.ExtractFromA].x()
self.ExtractAVertex = QgsVertexMarker(canvas)
self.ExtractAVertex.setCenter(xform.transform(QgsPointXY(longitude, latitude)))
self.ExtractAVertex.setColor(QColor(0,255,0))
self.ExtractAVertex.setIconSize(10)
self.ExtractAVertex.setIconType(QgsVertexMarker.ICON_X)
self.ExtractAVertex.setPenWidth(10)
self.ExtractA = True
if self.ExtractB == True:
self.pushButtonCut_2.setEnabled(True)
else:
self.pushButtonCut_2.setEnabled(False)
def ExtractToB(self):
if self.ExtractB == True:
self.Main.iface.mapCanvas().scene().removeItem(self.ExtractBVertex)
self.ExtractB = False
self.ExtractToB = round((self.player.position()- self.StartMsecond )/1000)
if self.ExtractA == True:
if self.ExtractToB > self.ExtractFromA:
canvas = self.Main.iface.mapCanvas()
crsSrc = QgsCoordinateReferenceSystem(4326) # .gpx is in WGS 84
crsDest = QgsProject.instance().crs()
xform = QgsCoordinateTransform(crsSrc, crsDest)
latitude,longitude = self.Polyline[self.ExtractToB].y(), self.Polyline[self.ExtractToB].x()
self.ExtractBVertex = QgsVertexMarker(canvas)
self.ExtractBVertex.setCenter(xform.transform(QgsPointXY(longitude, latitude)))
self.ExtractBVertex.setColor(QColor(255,0,0))
self.ExtractBVertex.setIconSize(10)
self.ExtractBVertex.setIconType(QgsVertexMarker.ICON_X)
self.ExtractBVertex.setPenWidth(10)
self.ExtractB = True
self.pushButtonCut_2.setEnabled(True)
else:
self.pushButtonCut_2.setEnabled(False)
def CancelVertex(self):
if self.ExtractA == True:
self.Main.iface.mapCanvas().scene().removeItem(self.ExtractAVertex)
self.ExtractA = False
if self.ExtractB == True:
self.Main.iface.mapCanvas().scene().removeItem(self.ExtractBVertex)
self.ExtractB = False
self.pushButtonCut_2.setEnabled(False)
def ExtractToolbar(self):
if self.ExtractTool == 0:
self.dockWidget_4.show()
self.ExtractTool = 1
else:
self.dockWidget_4.hide()
self.ExtractTool = 0
def transform_wgs84_to_utm(self, lon, lat):
def get_utm_zone(longitude):
return (int(1+(longitude+180.0)/6.0))
def is_northern(latitude):
"""
Determines if given latitude is a northern for UTM
"""
if (latitude < 0.0):
return 0
else:
return 1
utm_coordinate_system = osr.SpatialReference()
utm_coordinate_system.SetWellKnownGeogCS("WGS84") # Set geographic coordinate system to handle lat/lon
utm_coordinate_system.SetUTM(get_utm_zone(lon), is_northern(lat))
wgs84_coordinate_system = utm_coordinate_system.CloneGeogCS() # Clone ONLY the geographic coordinate system
wgs84_to_utm_transform = osr.CoordinateTransformation(wgs84_coordinate_system, utm_coordinate_system) # (<from>, <to>)
return wgs84_to_utm_transform.TransformPoint(lon, lat, 0) # returns easting, northing, altitude