forked from Ytimed2020/PP-Tracking_GUi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
1426 lines (1275 loc) · 67.4 KB
/
main.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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from PySide2.QtWidgets import *
from PySide2.QtUiTools import *
from PySide2.QtCore import *
from PySide2 import QtGui, QtCore, QtWidgets
from PySide2.QtGui import *
from moviepy.editor import VideoFileClip
import threading
import cv2
import sys, os
import PySide2
import datetime
import firstSource
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import secondSource
from PySide2.QtGui import QMovie
import sys
import numpy as np
import shutil
from decimal import Decimal
sys.path.append('deploy')
from MyControl import *
from PIL import Image
from pylab import xticks,yticks,np
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
os.environ['PYTHON_EXE'] = sys.executable
class status():
def __init__(self):
# self.handleCalc()
#正常情况下应该是先跳转到主页menu,现在主页还没完善好,因此先跳转到行人单目标检测
self.id_num = 0
self.handleCalc()
# note: 添加变量
self.file_path = [] # 用于保存结果文件
self.video_path = [] # 用于保存选择的视频路径
self.final_time = 0
self.txt_output_path = ''
self.video_output_path = ''
self.txt_statistic_output_path = ''
# self.is_enter = False
def show_ui(self, location):
loca="ui/"+location
qfile_staus = QFile(loca)
qfile_staus.open(QFile.ReadOnly)
qfile_staus.close()
self.ui = QUiLoader().load(qfile_staus)
self.ui.setWindowTitle("百度飞桨PP-Tracking")
appIcon = QIcon("source/first/logo.jpg")
self.ui.setWindowIcon(appIcon)
def help_set_shadow(self, x_offset
, y_offset
, radius
, color
, *control):
for x in control:
tempEffect = QGraphicsDropShadowEffect(self.ui)
tempEffect.setOffset(x_offset, y_offset)
tempEffect.setBlurRadius(radius) # 阴影半径
tempEffect.setColor(color)
x.setGraphicsEffect(tempEffect)
def help_set_style_sheet(self, s, *controllers):
for x in controllers:
x.setStyleSheet(s)
def help_hide(self, *control):
for x in control:
x.setVisible(False)
def help_set_up(self, *control):
for x in control:
x.raise_()
def help_set_edit(self, edit, one):
if one == 1 or one == -1:
self.time = self.time + one
if self.time>999: self.time=999
if self.time<0: self.time=0
edit.setText(str(self.time))
else:
# self.confi = float(float(self.confi) + float(one))
self.confi = Decimal(str(self.confi)) + Decimal(str(one))
self.confi = Decimal(self.confi).quantize(Decimal("0.00"))
if self.confi > 1.0: self.confi = 1.0
if self.confi < 0.0: self.confi = 0.0
edit.setText(str(self.confi))
def help_set_edit_by_hand_new(self, edit):
text = edit.text()
if not text.isdigit():
QMessageBox.warning(self.ui, '错误提示', '密度标准只能输入整形数字!')
else:
self.std = int(edit.text())
now = int(edit.text())
if self.std>9999: self.std = 9999
if self.std<0: self.std = 0
if now != self.std: edit.setText(str(self.std))
def help_set_edit_by_hand(self, edit, one):
if one == 1:
text = edit.text()
if not text.isdigit():
QMessageBox.warning(self.ui, '错误提示', '只能输入整形数字!')
else:
self.time = int(edit.text())
now = int(edit.text())
if self.time>999: self.time = 999
if self.time<0: self.time = 0
if now != self.time: edit.setText(str(self.time))
else:
self.confi = int(Decimal(str(edit.text())) * 100)
self.confi = Decimal(str(self.confi / 100.0))
now = Decimal(str(edit.text()))
if self.confi > 1.0: self.confi = 1.0
if self.confi < 0.0: self.confi = 0.0
if now != self.confi:
edit.setText(str(self.confi))
def help_set_spinBox(self, edit, add, down, one):
edit.textChanged.connect(lambda: self.help_set_edit_by_hand(edit, one))
add.clicked.connect(lambda: self.help_set_edit(edit, one))
down.clicked.connect(lambda: self.help_set_edit(edit, -1*one))
def help_set_progress(self, len, progress, show_label):
"""
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
用来更新那个进度条的函数
!!!注意更新进度条的时候一定要先修改self.progressPos,
self.progressPos是一个0到1的小数
:param len:指的是总进度条的长度,是120
:param progress: 指的是self.ui.label_progressBar,直接传这个参数就可以
:param show_label:是self.ui.label_progressBar_num,直接传这个
:return:
"""
show_label.setText(' ')
progress.resize(int(self.progressPos*len), progress.height())
def handleCalc(self):
self.show_ui("main_menu.ui")
self.have_show_video = 0
self.is_tracking = '--draw_center_traj'
self.is_enter_surely = 0
self.help_set_shadow(0, 0, 50, QColor(0, 0, 0, 0.06 * 255)
, self.ui.widget1
, self.ui.widget1_2
, self.ui.widget1_3)
self.help_set_shadow(-10, 10, 30, QColor(0, 0, 0, 0.06 * 255)
, self.ui.widget
, self.ui.widget_3
, self.ui.widget_4
, self.ui.widget_5
, self.ui.widget_6
, self.ui.widget_7
, self.ui.widget_8)
test_video=r"C:\Users\Administrator\Desktop\university\d4199e42f744cbe3be7f5ac262cd9056.mp4"
label1 = MyMenuVideoLabel("source/second/menu_pedestrian.PNG"
, 360, 184, 320, 180
, test_video
, self.ui)
label2 = MyMenuVideoLabel("source/second/menu_car.PNG"
, 800, 184, 320, 180
, test_video
, self.ui)
label3 = MyMenuVideoLabel("source/second/menu_muti_object.PNG"
, 1240, 184, 320, 180
, test_video
, self.ui)
self.ui.show()
self.ui.pushButton.clicked.connect(self.pedestrian_menu)
self.ui.pushButton_2.clicked.connect(self.car_menu)
self.ui.pushButton_3.clicked.connect(self.mult_menu)
def load_son_menu(self, menu_ui, id):
# 后面完善的话还要传入那些video和video的一开始的图片
self.clear_video()
self.show_ui(menu_ui)
self.help_set_shadow(0, 0, 50, QColor(0, 0, 0, 0.06 * 255)
, self.ui.widget1
, self.ui.widget1_2
, self.ui.widget1_3)
self.help_set_shadow(0, 4, 0, QColor(221, 221, 221, 0.3 * 255), self.ui.label_3)
test_video = r"C:\Users\Administrator\Desktop\university\d4199e42f744cbe3be7f5ac262cd9056.mp4"
if id == 1:
label1 = MyMenuVideoLabel("source/second/people_one.PNG"
, 360, 400, 320, 180
, test_video
, self.ui)
label2 = MyMenuVideoLabel("source/second/people_small.PNG"
, 800, 400, 320, 180
, test_video
, self.ui)
label3 = MyMenuVideoLabel("source/second/people_two.PNG"
, 1240, 400, 320, 180
, test_video
, self.ui)
elif id == 2:
label1 = MyMenuVideoLabel("source/second/car_one.PNG"
, 360, 400, 320, 180
, test_video
, self.ui)
label2 = MyMenuVideoLabel("source/second/car_small.PNG"
, 800, 400, 320, 180
, test_video
, self.ui)
label3 = MyMenuVideoLabel("source/second/car_two.PNG"
, 1240, 400, 320, 180
, test_video
, self.ui)
self.ui.show()
def pedestrian_menu(self):
self.is_mult = False
self.is_enter_surely = 0
self.load_son_menu("pedestrian_menu.ui", 1)
self.ui.pushButton.clicked.connect(self.pedestrian_one_photo)
self.ui.pushButton_2.clicked.connect(self.pedestrian_small_object)
self.ui.pushButton_3.clicked.connect(self.pedestrian_double_photo)
self.ui.pushButton_12.clicked.connect(self.handleCalc)
def car_menu(self):
self.is_mult = False
self.is_enter_surely = 0
self.load_son_menu("car_menu.ui", 2)
self.ui.pushButton_12.clicked.connect(self.handleCalc)
self.ui.pushButton.clicked.connect(self.car_one_photo)
self.ui.pushButton_2.clicked.connect(self.car_small_object)
self.ui.pushButton_3.clicked.connect(self.car_double_photo)
def mult_menu(self):
self.clear_video()
self.is_mult=True
self.show_ui("mult_menu.ui")
self.help_set_shadow(0, 0, 50, QColor(0, 0, 0, 0.06 * 255)
, self.ui.widget1_2
, self.ui.widget1_3)
self.help_set_shadow(0, 4, 0, QColor(221, 221, 221, 0.3 * 255), self.ui.label_3)
test_video = r"C:\Users\Administrator\Desktop\university\d4199e42f744cbe3be7f5ac262cd9056.mp4"
label1 = MyMenuVideoLabel("source/second/other_one.PNG"
, 580, 400, 320, 180
, test_video
, self.ui)
label2 = MyMenuVideoLabel("source/second/other_two.PNG"
, 1020, 400, 320, 180
, test_video
, self.ui)
self.ui.pushButton_12.clicked.connect(self.handleCalc)
self.ui.show()
self.show_list = []
self.ui.pushButton_2.clicked.connect(self.mult_one_photo)
self.ui.pushButton_3.clicked.connect(self.mult_small_object)
def pedestrian_one_photo(self):
self.universe_for_one_small("pedestrian_one_photo.ui",
"pedestrian_one_photo_working.ui",
"pedestrian_one_photo_working_enter.ui")
self.page_id = 1
self.is_draw_line = ''
self.come_back=self.pedestrian_menu
self.ui.pushButton_13.clicked.connect(self.come_back)
def pedestrian_small_object(self):
self.page_id = 3
self.universe_for_one_small("pedestrian_small_object.ui",
"pedestrian_small_object_working.ui",
"pedestrian_small_object_working_enter.ui")
self.is_draw_line = ''
self.come_back = self.pedestrian_menu
self.ui.pushButton_13.clicked.connect(self.come_back)
def pedestrian_double_photo(self):
self.page_id = 4
self.universe_for_double("pedestrian_double_photo.ui",
"pedestrian_double_photo_working.ui")
self.come_back = self.pedestrian_menu
self.is_draw_line = ''
self.ui.pushButton_13.clicked.connect(self.come_back)
def car_one_photo(self):
self.page_id = 2
self.universe_for_one_small("car_one_photo.ui",
"car_one_photo_working.ui",
"car_one_photo_working_enter.ui")
self.is_draw_line = ''
self.come_back=self.car_menu
self.ui.pushButton_13.clicked.connect(self.come_back)
def car_small_object(self):
self.page_id = 5
self.universe_for_one_small("car_small_object.ui",
"car_small_object_working.ui",
"car_small_object_working_enter.ui")
self.is_draw_line = ''
self.come_back = self.car_menu
self.ui.pushButton_13.clicked.connect(self.come_back)
def car_double_photo(self):
self.page_id = 6
self.universe_for_double("car_double_photo.ui",
"car_double_photo_working.ui")
self.come_back = self.car_menu
self.is_draw_line = ''
self.ui.pushButton_13.clicked.connect(self.come_back)
def universe_for_double(self, first_ui, next_ui):
self.show_ui(first_ui)
self.help_set_shadow(0, 0, 50, QColor(0, 0, 0, 0.06 * 255)
, self.ui.widget_2)
self.have_show_video = 2
self.is_draw_line = ''
self.ui.pushButton_5.clicked.connect(
lambda: self.load_video1(self.ui.pushButton_5
, self.ui.label_15)
)
self.ui.pushButton_10.clicked.connect(
lambda: self.load_video1(self.ui.pushButton_10
, self.ui.label_16)
)
self.not_enter_ui = next_ui
self.confi = 0.5
self.time = 0
self.std = 10
self.progressPos = 0.0
self.ui.show()
def universe_for_one_small(self,
first_ui,
not_enter_ui,
is_enter_ui):
self.show_ui(first_ui)
self.file_path = []
self.video_path = []
self.is_draw_line = ''
# 先设置shadow
self.have_show_video=1
self.help_set_shadow(0, 4, 0, QColor(221, 221, 221, 0.3 * 255)
, self.ui.label_3)
self.help_set_shadow(0, 0, 50, QColor(221, 221, 221, 0.3 * 255)
, self.ui.widget_2, self.ui.widget_3)
self.not_enter_ui = not_enter_ui
self.is_enter_ui = is_enter_ui
self.confi = 0.5
self.time = 0
self.std = 10
self.progressPos = 0.00
self.ui.pushButton_addVideo.clicked.connect(
lambda: self.load_video1(self.ui.pushButton_addVideo,
self.ui.label_24)
)
self.ui.show()
def mult_one_photo(self):
self.page_id = 7
self.is_draw_line = ''
self.show_ui("mult_one_photo.ui")
self.help_set_shadow(0, 0, 50, QColor(0, 0, 0, 0.06 * 255)
, self.ui.widget_2)
self.come_back = self.mult_menu
self.have_show_video = 1
self.ui.pushButton_addVideo.clicked.connect(
lambda: self.load_video1(self.ui.pushButton_addVideo
, self.ui.label_24)
)
self.ui.pushButton_13.clicked.connect(self.come_back)
self.not_enter_ui = "mult_one_photo_working.ui"
self.confi = 0.5
self.time = 0
self.std = 10
self.progressPos = 0.00
self.ui.show()
def mult_small_object(self):
self.page_id = 8
self.show_ui("mult_small_object.ui")
self.is_draw_line = ''
self.help_set_shadow(0, 0, 50, QColor(0, 0, 0, 0.06 * 255)
, self.ui.widget_2)
self.come_back = self.mult_menu
self.have_show_video = 1
self.ui.pushButton_addVideo.clicked.connect(
lambda: self.load_video1(self.ui.pushButton_addVideo
, self.ui.label_24)
)
self.ui.pushButton_13.clicked.connect(self.come_back)
# note:初始时加载的界面错了,此处做了调整
self.not_enter_ui = "mult_small_object_working.ui"
self.confi = 0.5
self.time = 0
self.std = 10
self.progressPos = 0.00
self.ui.show()
def one_photo_change_enter(self):
"""
每一次改变是否切换出入口,要先:
1.配置基本需要用代码配置的ui
2.手动调整的值要从原来的复制过去
每个控件的值,除了手动调整的,其他都是根据推理结果更新,不用管
3.将暂停键之类的各种键配置好
:return:
"""
result = []
result.append(self.lineEditConfi.text())
# result.append(self.ui.lineEdit_2.text())
# print(self.ui.lineEdit_2.text())
if self.is_enter == False:
self.is_enter = True
self.is_enter_surely = 1
self.is_draw_line = '--do_entrance_counting'
self.confi = 0.5
self.init_base_ui_for_one_photo_changing_enter(self.is_enter_ui)
elif self.is_enter == True:
self.is_enter = False
self.is_enter_surely = 0
self.is_draw_line = ''
self.confi = 0.5
self.init_base_ui_for_one_photo_changing_enter(self.not_enter_ui)
self.lineEditConfi.setText("0.5")
# self.ui.lineEdit_2.setText(result[1])
# note:无法选择按钮暂时变灰
self.ui.pushButton_2.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #F5F5F5;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #B8B8B8;\nline-height: 26px;\nfont-weight:bold\n}")
self.ui.pushButton_3.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #F5F5F5;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #B8B8B8;\nline-height: 26px;\nfont-weight:bold\n}")
self.ui.pushButton_8.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #F5F5F5;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #B8B8B8;\nline-height: 26px;\nfont-weight:bold\n}")
self.cap4 = cv2.VideoCapture(self.video_path[0])
ret, frame = self.cap4.read()
self.have_show_time = 0
self.Display_Image(frame, self.ui.label_7)
# to do: 解决出入口界面的问题
# self.is_enter_surely = 1
print(self.is_enter_surely)
self.load_video_controller()
self.load_control_for_one_photo()
return
def init_base_ui_for_double_photo(self, ui_location):
self.show_ui(ui_location)
s = """QLineEdit{\nwidth: 80px;\nheight: 40px;\nbackground: #FFFFFF;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\n\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #333333;\nline-height: 26px;\nfont-weight:bold;\n}"""
self.lineEditConfi = MyLineEdit(self.ui.label_confi_tip, s
, 0, 352, 930, 57, 42, self.ui)
# s = """QPushButton{\nwidth: 120px;\nheight: 40px;\nborder-radius: 4px;\nborder: 1px solid #4E4EF2;\nfont-weight:bold;\n\nfont-size: 16px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #4E4EF2;\nline-height: 24px;\n}\nQPushButton:hover{\nwidth: 120px;\nheight: 44px;\nbackground: rgba(255, 255, 255, 204);\nborder-radius: 4px;\nborder: 1px solid rgba(78, 78, 242, 204);\n\nfont-weight:bold;\nfont-size: 16px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: rgba(78, 78, 242, 204);\nline-height: 24px;\n}"""
# self.output_txt = MyPushButton(self.ui.label_txt_tip, s
# , "导出文件", 1507.5, 290, 126, 44, self.ui)
self.help_set_shadow(0, 0, 50, QColor(0, 0, 0, 0.06 * 255)
, self.ui.widget_2)
if self.have_show_video == 2:
self.listWidget = QListWidget(self.ui)
self.listWidget.setStyleSheet("""QListWidget{border:0px;}QListWidget:item{margin:10px 0px 10px 0px;}""")
self.listWidget.move(1322, 358 + 16 + 36)
self.listWidget.resize(370, 540 - 16 - 40)
self.ui.pushButton_13.clicked.connect(self.come_back)
# note:无法选择按钮暂时变灰
self.ui.pushButton_2.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #F5F5F5;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #B8B8B8;\nline-height: 26px;\nfont-weight:bold\n}")
self.ui.pushButton_3.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #F5F5F5;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #B8B8B8;\nline-height: 26px;\nfont-weight:bold\n}")
self.ui.pushButton_8.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #F5F5F5;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #B8B8B8;\nline-height: 26px;\nfont-weight:bold\n}")
# note:初始时隐藏当前视频帧数显示,点击结果显示按钮后才显示出来
self.ui.label_22.setVisible(False)
self.ui.label_frames.setVisible(False)
self.ui.show()
# note: 添加双镜头显示视频图片:
if(len(self.video_path)==2):
self.cap4 = cv2.VideoCapture(self.video_path[0])
ret, frame = self.cap4.read()
self.have_show_time = 0
self.Display_Image(frame, self.ui.label_7)
self.cap5 = cv2.VideoCapture(self.video_path[1])
ret, frame = self.cap5.read()
self.have_show_time = 0
self.Display_Image(frame, self.ui.label_14)
elif(len(self.video_path)==1):
self.cap4 = cv2.VideoCapture(self.video_path[0])
ret, frame = self.cap4.read()
self.have_show_time = 0
self.Display_Image(frame, self.ui.label_7)
def init_base_ui_for_one_photo_changing_enter(self, ui_location):
self.show_ui(ui_location)
s = """QLineEdit{\nwidth: 80px;\nheight: 40px;\nbackground: #FFFFFF;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\n\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #333333;\nline-height: 26px;\nfont-weight:bold;\n}"""
self.lineEditConfi = MyLineEdit(self.ui.label_confi_tip, s
, 0, 352, 930, 57, 42, self.ui)
# s = """QPushButton{\nwidth: 126px;\nheight: 44px;\nbackground: #FFFFFF;\nborder-radius: 4px;\nborder: 1px solid #4E4EF2;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #4E4EF2;\nline-height: 26px;\nfont-weight:bold;\n}"""
# self.output_txt = MyPushButton(self.ui.label_txt_tip, s
# , "导出文件", 1507.5, 290, 126, 44, self.ui)
self.help_set_shadow(0, 4, 0, QColor(221, 221, 221, 0.3 * 255)
, self.ui.label_3)
self.help_set_shadow(0, 0, 50, QColor(221, 221, 221, 0.3 * 255)
, self.ui.widget_2, self.ui.widget_3)
# note:无法选择按钮暂时变灰
self.ui.pushButton_2.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #F5F5F5;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #B8B8B8;\nline-height: 26px;\nfont-weight:bold\n}")
self.ui.pushButton_3.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #F5F5F5;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #B8B8B8;\nline-height: 26px;\nfont-weight:bold\n}")
self.ui.pushButton_8.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #F5F5F5;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #B8B8B8;\nline-height: 26px;\nfont-weight:bold\n}")
self.ui.pushButton_10.clicked.connect(self.one_photo_change_enter)
self.ui.pushButton_13.clicked.connect(self.come_back)
# note:初始时隐藏当前视频帧数显示,点击结果显示按钮后才显示出来
self.ui.label_22.setVisible(False)
self.ui.label_frames.setVisible(False)
self.ui.show()
# note:添加显示视频图片
self.cap3 = cv2.VideoCapture(self.video_path[0])
ret, frame = self.cap3.read()
self.have_show_time = 0
self.Display_Image(frame, self.ui.label_7)
def load_control_for_double_photo(self):
self.help_set_spinBox(self.lineEditConfi,
self.ui.pushButton_7,
self.ui.pushButton_11,
0.01)
def load_control_for_one_photo(self):
self.help_set_spinBox(self.lineEditConfi,
self.ui.pushButton_7,
self.ui.pushButton_11,
0.01)
# 可视化界面: 时段长度和人流密度标准添加限制
if self.is_enter_surely == 0:
self.help_set_spinBox(self.ui.lineEdit_2,
self.ui.pushButton_5,
self.ui.pushButton_6,
1)
self.ui.lineEdit_3.textChanged.connect(lambda: self.help_set_edit_by_hand_new(self.ui.lineEdit_3))
return
def load_control_for_one_mult_photo(self):
self.help_set_spinBox(self.lineEditConfi, self.ui.pushButton_7
, self.ui.pushButton_11, 0.01)
# self.help_set_spinBox(self.ui.lineEdit_2, self.ui.pushButton_5
# , self.ui.pushButton_6, 1)
return
def load_video(self, control_hide, control_label):
"""
:param video_count: 要导入视频的数量,单镜头是1,跨境是2
:return:
"""
num_now = len(self.file_path)
filePath = self.open_one_file_dialog("选择视频", 0)
if filePath == "":
return
self.file_path.append(filePath)
# note: 保存选择的视频路径
self.video_path.append(filePath)
if len(self.file_path) < self.have_show_video:
# 数量对不上就return,说明没有给够
return
self.time = 2
self.std = 10
# note: 判断是否打开出入口界面并进行跳转
if self.have_show_video == 1 and self.is_mult == False:
self.is_enter = False
self.init_base_ui_for_one_photo_changing_enter(self.not_enter_ui)
else:
self.init_base_ui_for_double_photo(self.not_enter_ui)
self.lineEditConfi.setText("0.5")
self.model_file_path = self.file_path[0]
file_temp_split_path = self.file_path[0].split('.')
self.file_name = file_temp_split_path[0]
# note: 修改使得支持多视频格式
# self.file_path[0] = 'output/' + file_temp_split_path[0].split('/')[-1] + '.mp4'
self.file_path[0] = 'output/' + self.file_path[0].split('/')[-1]
# 结果文件默认输出路径
self.video_output_path = self.file_path[0]
if self.page_id == 7 or self.page_id == 8:
self.txt_output_path = 'output/' + file_temp_split_path[0].split('/')[-1] + '.txt'
else:
self.txt_output_path = 'output/' + file_temp_split_path[0].split('/')[-1] + '.txt'
self.txt_statistic_output_path = 'output/' + file_temp_split_path[0].split('/')[-1] + '_flow_statistic.txt'
print(self.txt_output_path)
if self.page_id == 7:
pic = QPixmap('source/second/mul_one.png')
self.ui.label_9.setPixmap(pic)
self.ui.label_9.setScaledContents(True)
elif self.page_id == 8:
# note:初始时加载路径错了,进行修正
pic = QPixmap('source/second/small_mul.png')
self.ui.label_9.setPixmap(pic)
self.ui.label_9.setScaledContents(True)
self.open_video()
def load_model(self):
if self.is_enter_surely == 0:
# 获取时段长度值
period_length = self.ui.lineEdit_2.text()
period = '--secs_interval=%s'%(period_length)
print(period)
# 时段长度失效
self.ui.pushButton_5.setEnabled(False)
self.ui.pushButton_6.setEnabled(False)
self.ui.lineEdit_2.setEnabled(False)
text = self.ui.lineEdit_2.text()
if not text.isdigit():
QMessageBox.warning(self.ui, '错误提示', '人流密度值只能为整形数字!')
return
else:
period = ''
print(period)
print('加载单类别模型')
print(self.file_name)
file_name_test = self.file_name.split('/')
file_path_test = self.file_path[0].split('/')
file_name_test_start = file_name_test[len(file_name_test) - 1]
self.file_name = file_name_test_start + '.mp4'
self.end_file_name = self.file_name
# self.ui.label_23.setFixedSize \
# (self.ui.label_23.width(), self.ui.label_23.height())
# note:是否绘制轨迹
if self.ui.checkBox.checkState() == Qt.Checked:
self.is_tracking = '--draw_center_traj'
else:
self.is_tracking = ''
# 模型开始运行及运行完成后让按钮及复选框失效掉
self.ui.checkBox.setEnabled(False) # 取消轨迹复选框
# 阈值调试失效
self.ui.pushButton_7.setEnabled(False)
self.ui.pushButton_11.setEnabled(False)
self.lineEditConfi.setEnabled(False)
# 让人流密度指标调整失效
if self.is_enter_surely == 0:
self.standard = self.ui.lineEdit_3.text()
self.ui.lineEdit_3.setEnabled(False)
self.ui.pushButton_10.setEnabled(False) # 让开关出入口失效
# 将开关出入口设置为灰色,表示不可选
self.ui.pushButton_10.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 40px;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-weight:bold;\nwidth: 80px;\nheight: 24px;\nfont-size: 16px;\nfont-family:\nAlibabaPuHuiTi_2_65_Medium;\nline-height: 24px;\ncolor: #888888;\n}")
self.confi = self.lineEditConfi.text()
starttime = datetime.datetime.now()
# note:添加异常捕获
try:
#判断是行人模型还是车辆模型
print("*******************************************************")
print(self.confi)
# draw_center_traj
print(self.is_draw_line)
print(self.is_tracking)
print("模型开始运行!")
python_exe = os.environ['PYTHON_EXE']
if self.page_id == 1:
print("当前是行人模型")
val = os.system(
'%s deploy/pptracking/python/mot_jde_infer.py --model_dir=output_inference/fairmot_hrnetv2_w18_dlafpn_30e_576x320 --video_file=%s --save_mot_txts --device=GPU --threshold=%s %s %s %s' \
% (python_exe, self.model_file_path, self.confi, self.is_tracking, self.is_draw_line, period))
elif self.page_id == 2:
print("当前是车辆模型")
val = os.system(
'%s deploy/pptracking/python/mot_jde_infer.py --model_dir=output_inference/fairmot_hrnetv2_w18_dlafpn_30e_576x320_bdd100kmot_vehicle --video_file=%s --save_mot_txts --device=GPU --threshold=%s %s %s %s' \
% (python_exe, self.model_file_path, self.confi, self.is_tracking, self.is_draw_line, period))
elif self.page_id == 3:
print("当前是行人小目标跟踪模型")
val = os.system(
'%s deploy/pptracking/python/mot_jde_infer.py --model_dir=output_inference/fairmot_hrnetv2_w18_dlafpn_30e_1088x608_visdrone_pedestrian --video_file=%s --save_mot_txts --device=GPU --threshold=%s %s %s %s' \
% (python_exe, self.model_file_path, self.confi, self.is_tracking, self.is_draw_line, period))
elif self.page_id == 5:
print("当前是车辆小目标跟踪模型")
val = os.system(
'%s deploy/pptracking/python/mot_jde_infer.py --model_dir=output_inference/fairmot_hrnetv2_w18_dlafpn_30e_576x320_visdrone_vehicle --video_file=%s --save_mot_txts --device=GPU --threshold=%s %s %s %s' \
% (python_exe, self.model_file_path, self.confi, self.is_tracking, self.is_draw_line, period))
elif self.page_id == 7:
val = os.system(
'%s deploy/pptracking/python/mot_jde_infer.py --model_dir=output_inference/mcfairmot_hrnetv2_w18_dlafpn_30e_576x320_bdd100k_mcmot --video_file=%s --save_mot_txts --device=GPU --threshold=%s %s %s' \
% (python_exe, self.model_file_path, self.confi, self.is_tracking, self.is_draw_line))
else:
val = os.system(
'%s deploy/pptracking/python/mot_jde_infer.py --model_dir=output_inference/mcfairmot_hrnetv2_w18_dlafpn_30e_1088x608_visdrone --video_file=%s --save_mot_txts --device=GPU --threshold=%s %s %s' \
% (python_exe, self.model_file_path, self.confi, self.is_tracking, self.is_draw_line))
except Exception as e:
print(e) # 打印所有异常到屏幕
QMessageBox.warning(self.ui, '错误提示', '模型运行发生异常!\n报错信息:' + e)
return
endtime = datetime.datetime.now()
starttime_count = starttime.hour * 3600 + starttime.minute * 60 + starttime.second
endtime_count = endtime.hour * 3600 + endtime.minute * 60 + endtime.second
self.final_time = str(endtime_count - starttime_count)
self.ui.label_28.setText(str((endtime_count - starttime_count)))
# note: 优化FPS显示问题
if self.is_enter_surely == 0:
self.cap1 = cv2.VideoCapture(self.file_path[0])
self.ui.label_26.setText(str(round(self.cap1.get(cv2.CAP_PROP_FPS))))
# self.ui.label_26.setText(str(round(self.cap1.get(cv2.CAP_PROP_FPS))))
# self.synthesis_vide(val, self.file_name)
if self.is_enter_surely == 0:
self.read_txt_file()
else:
self.read_enter_txt_file()
pic = QPixmap('source/second/model_ok.png')
self.ui.label_7.setFixedSize(960, 540)
self.ui.label_7.move(60, 108)
self.ui.label_7.setPixmap(pic)
self.ui.label_7.setScaledContents(True)
# note:运行结束重新把按钮由灰变蓝
self.ui.pushButton_2.setStyleSheet("QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #4E4EF2;;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF;\nline-height: 26px;\nfont-weight:bold\n}\nQPushButton:hover{\nwidth: 120px;\nheight: 44px;\nbackground: rgba(78, 78, 242, 204);\nborder-radius: 4px;\nopacity: 0.8;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF; \nline-height: 26px;\nfont-weight: bold;}")
self.ui.pushButton_3.setStyleSheet("QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #4E4EF2;;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF;\nline-height: 26px;\nfont-weight:bold\n}\nQPushButton:hover{\nwidth: 120px;\nheight: 44px;\nbackground: rgba(78, 78, 242, 204);\nborder-radius: 4px;\nopacity: 0.8;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF; \nline-height: 26px;\nfont-weight: bold;}")
self.ui.pushButton_8.setStyleSheet("QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #4E4EF2;;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF;\nline-height: 26px;\nfont-weight:bold\n}\nQPushButton:hover{\nwidth: 120px;\nheight: 44px;\nbackground: rgba(78, 78, 242, 204);\nborder-radius: 4px;\nopacity: 0.8;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF; \nline-height: 26px;\nfont-weight: bold;}")
# note: 运行结束后重新开放开启出入口功能
self.ui.pushButton_10.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 40px;\nborder-radius: 4px;\nborder: 1px solid #4E4EF2;\nfont-weight:bold;\nfont-size: 16px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #4E4EF2;\nline-height: 24px;\n}\nQPushButton:hover{\nwidth: 120px;\nheight: 44px;\nbackground: #FFFFFF;\nborder-radius: 4px;\nborder: 1px solid #4E4EF2;\nfont-weight:bold;\nfont-size: 16px;\nfont-family:AlibabaPuHuiTi_2_65_Medium;\ncolor: #4E4EF2;\nline-height: 24px;\n}")
self.ui.pushButton_10.setEnabled(True)
# 模型运行结束后开放功能
self.ui.pushButton_2.setEnabled(True) # 结果显示
self.ui.pushButton_3.setEnabled(True) # 停止运行
self.ui.pushButton_8.setEnabled(True) # 导出结果
def load_model_mult(self):
print('加载多类别模型')
print(self.file_name)
file_name_test = self.file_name.split('/')
file_path_test = self.file_path[0].split('/')
file_name_test_start = file_name_test[len(file_name_test) - 1]
self.file_name = file_name_test_start + '.mp4'
self.end_file_name = self.file_name
# self.ui.label_23.setFixedSize \
# (self.ui.label_23.width(), self.ui.label_23.height())
# note:是否绘制轨迹
if self.ui.checkBox.checkState() == Qt.Checked:
self.is_tracking = '--draw_center_traj'
else:
self.is_tracking = ''
# 模型开始运行及运行完成后让按钮及复选框失效掉
self.ui.checkBox.setEnabled(False) # 取消轨迹复选框
# 阈值调试失效
self.ui.pushButton_7.setEnabled(False)
self.ui.pushButton_11.setEnabled(False)
self.lineEditConfi.setEnabled(False)
starttime = datetime.datetime.now()
# note: 添加异常捕获
try:
# 判断是行人模型还是车辆模型
print("*******************************************************")
print(self.confi)
# draw_center_traj
print(self.is_draw_line)
print(self.is_tracking)
print("lzclzclzclzclzclzc")
if self.page_id == 7:
val = os.system(
'python deploy/pptracking/python/mot_jde_infer.py --model_dir=output_inference/mcfairmot_hrnetv2_w18_dlafpn_30e_576x320_bdd100k_mcmot --video_file=%s --save_mot_txts --device=GPU --threshold=%s %s %s' \
% (self.model_file_path, self.confi, self.is_tracking, self.is_draw_line))
else:
val = os.system(
'python deploy/pptracking/python/mot_jde_infer.py --model_dir=output_inference/mcfairmot_hrnetv2_w18_dlafpn_30e_1088x608_visdrone --video_file=%s --save_mot_txts --device=GPU --threshold=%s %s %s' \
% (self.model_file_path, self.confi, self.is_tracking, self.is_draw_line))
except Exception as e:
print(e) # 打印所有异常到屏幕
QMessageBox.warning(self.ui, '错误提示', '模型运行发生异常!\n报错信息:' + e)
return
endtime = datetime.datetime.now()
starttime_count = starttime.hour * 3600 + starttime.minute * 60 + starttime.second
endtime_count = endtime.hour * 3600 + endtime.minute * 60 + endtime.second
pic = QPixmap('source/second/model_ok.png')
self.ui.label_7.setFixedSize(960, 540)
self.ui.label_7.move(60, 108)
self.ui.label_7.setPixmap(pic)
self.ui.label_7.setScaledContents(True)
# self.synthesis_vide(val, self.file_name)
# self.ui.label_17.setText("运行时间" + str((endtime_count - starttime_count)) /
# +"运行FPS" + str(round(self.cap1.get(cv2.CAP_PROP_FPS))))
# note:运行结束重新把按钮由灰变蓝
self.ui.pushButton_2.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #4E4EF2;;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF;\nline-height: 26px;\nfont-weight:bold\n}\nQPushButton:hover{\nwidth: 120px;\nheight: 44px;\nbackground: rgba(78, 78, 242, 204);\nborder-radius: 4px;\nopacity: 0.8;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF; \nline-height: 26px;\nfont-weight: bold;}")
self.ui.pushButton_3.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #4E4EF2;;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF;\nline-height: 26px;\nfont-weight:bold\n}\nQPushButton:hover{\nwidth: 120px;\nheight: 44px;\nbackground: rgba(78, 78, 242, 204);\nborder-radius: 4px;\nopacity: 0.8;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF; \nline-height: 26px;\nfont-weight: bold;}")
self.ui.pushButton_8.setStyleSheet(
"QPushButton{\nwidth: 120px;\nheight: 44px;\nbackground: #4E4EF2;;\nborder-radius: 4px;\nborder: 1px solid #CCCCCC;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF;\nline-height: 26px;\nfont-weight:bold\n}\nQPushButton:hover{\nwidth: 120px;\nheight: 44px;\nbackground: rgba(78, 78, 242, 204);\nborder-radius: 4px;\nopacity: 0.8;\nfont-size: 18px;\nfont-family: AlibabaPuHuiTi_2_65_Medium;\ncolor: #FFFFFF; \nline-height: 26px;\nfont-weight: bold;}")
# 模型运行结束后开放功能
self.ui.pushButton_2.setEnabled(True) # 结果显示
self.ui.pushButton_3.setEnabled(True) # 停止运行
self.ui.pushButton_8.setEnabled(True) # 导出结果
# note: 添加导出结果功能:选择输出文件夹,将结果文件拷贝到该路径下
def output_result(self):
# 选择目录,返回选中的路径
output_path = QFileDialog.getExistingDirectory(self.ui,
"选择文件输出路径",
r"./")
if output_path is None:
return
else:
print('导出文件路径:' + output_path)
video = self.file_path[0].split('/')[-1]
new_video_path = output_path + '/' + video
print(new_video_path)
if self.page_id == 7 or self.page_id == 8:
if not os.path.exists(new_video_path):
shutil.copy(self.video_output_path, output_path)
shutil.copy(self.txt_output_path, output_path)
temp = self.file_path[0].split('.')
txt = temp[0].split('/')[-1] + '.txt'
QMessageBox.information(self.ui, 'success', '结果导出成功!\n效果视频:' + video + '\n结果文件:' + txt)
else:
if not os.path.exists(new_video_path):
shutil.copy(self.video_output_path, output_path)
shutil.copy(self.txt_output_path, output_path)
shutil.copy(self.txt_statistic_output_path, output_path)
temp = self.file_path[0].split('.')
txt = temp[0].split('/')[-1] + '.txt'
txt_statistic = temp[0].split('/')[-1] + '_flow_statistic.txt'
if self.page_id == 1 or self.page_id == 3:
if self.is_enter_surely == 0:
if not os.path.exists(output_path + '/people_image.png'):
shutil.copy('output/people_image.png', output_path)
QMessageBox.information(self.ui, 'success', '结果导出成功!\n效果视频:' + video + '\n结果文件:' + txt + '\n数据统计文件:' + txt_statistic + '\n可视化绘图:people_image.png')
else:
QMessageBox.information(self.ui, 'success',
'结果导出成功!\n效果视频:' + video + '\n结果文件:' + txt + '\n数据统计文件:' + txt_statistic)
elif self.page_id == 3 or self.page_id == 5:
if self.is_enter_surely == 0:
if not os.path.exists(output_path + '/car_image.png'):
shutil.copy('output/car_image.png', output_path)
QMessageBox.information(self.ui, 'success', '结果导出成功!\n效果视频:' + video + '\n结果文件:' + txt + '\n数据统计文件:' + txt_statistic + '\n可视化绘图:car_image.png')
else:
QMessageBox.information(self.ui, 'success',
'结果导出成功!\n效果视频:' + video + '\n结果文件:' + txt + '\n数据统计文件:' + txt_statistic)
else:
QMessageBox.information(self.ui, 'success', '结果导出成功!\n效果视频:' + video + '\n结果文件:' + txt + '\n数据统计文件:' + txt_statistic)
def read_enter_txt_file(self):
self.ui.label_26.setText(str(self.final_time))
end_file_name_list = self.end_file_name.split('.')
self.end_file_name = end_file_name_list[0]
f = open('output/' + self.end_file_name + '_flow_statistic.txt', 'r')
with open('output/' + self.end_file_name + '_flow_statistic.txt', 'r') as f1:
list = f1.readlines()
current_count_list_y = []
current_count_list_x = []
for i in range(len(list)):
new_temp_list = list[i].strip('\n').split(' ')
current_count = new_temp_list[8]
current_count_in = current_count.split(',')
current_count_in_true = current_count_in[0]
current_count_1 = new_temp_list[11]
current_count_2 = new_temp_list[5].split(',')
self.current_count = current_count_2[0]
current_count_out = current_count_1.split(',')
current_count_out_true = current_count_out[0]
current_count = new_temp_list[len(new_temp_list) - 1]
current_count_list_y.append(current_count)
current_count_list_x.append(i)
self.end_line_enter_one_eidt = int(float(self.lineEditConfi.text()))
print(self.current_count)
self.ui.label_28.setText(str(self.current_count))
self.ui.label_32.setText(str(self.current_count))
self.ui.label_34.setText(str(current_count_in_true))
self.ui.label_36.setText(str(current_count_out_true))
def read_txt_file_mult(self):
end_file_name_list = self.end_file_name.split('.')
self.end_file_name = end_file_name_list[0]
f = open('output/' + self.end_file_name + '_flow_statistic.txt', 'r')
with open('output/' + self.end_file_name + '_flow_statistic.txt', 'r') as f1:
list = f1.readlines()
current_count_list_y = []
current_count_list_x = []
y_test = []
line_text_2 = self.ui.lineEdit_2.text()
test = int(int(line_text_2) / 50) + 1
iter = 0
for i in range(test):
new_temp_list = list[iter - 1].strip('\n').split(' ')
current_count = new_temp_list[len(new_temp_list) - 1]
print(new_temp_list)
temp_current_count = current_count.split(',')
print(temp_current_count[0])
current_count = int(temp_current_count[0])
current_count_list_y.append(current_count)
current_count_list_x.append(i)
iter = iter + 50
for i in range(len(current_count_list_y)):
y_test.append(10)
plt.plot(current_count_list_x,current_count_list_y, mec='r', mfc='w', label='people')
plt.plot(current_count_list_x, y_test, ms=10, label='Boundary')
plt.legend() # 让图例生效
plt.margins(0)
plt.subplots_adjust(bottom=0.10)
plt.savefig('output/people_image.png')
# plt.show()
# 当前的人数计数
self.current_count = current_count_list_y[len(current_count_list_y) - 1]
f.close()
frames_num = self.cap1.get(7)
fps = int(round(self.cap1.get(cv2.CAP_PROP_FPS)))
def read_txt_file(self):
end_file_name_list = self.end_file_name.split('.')
self.end_file_name = end_file_name_list[0]
# f = open('output/' + self.end_file_name + '_flow_statistic.txt', 'r')
with open('output/' + self.end_file_name + '_flow_statistic.txt', 'r') as f1:
list = f1.readlines()
current_count_list_y = []
current_count_list_x = []
# 人流密度标准
standard = int(self.standard)
# 时段长度
interval = int(self.ui.lineEdit_2.text())
first = list[0].split(' ')[-1].replace("\n", "")
current_count_list_y.append(int(first))
current_count_list_x.append(0)
y_test = []
iter = 1
for i in range(len(list)):
judge = list[i].split(' ')[-2]
if judge == 'secs:':
count = list[i].split(' ')[-1].replace("\n", "")
count = int(count)
current_count_list_y.append(count)
current_count_list_x.append(iter * interval)
iter += 1
for i in range(len(current_count_list_y)):
y_test.append(standard)
# 判断是人流还是车流
if self.page_id == 1 or self.page_id == 3:
# note: 画图前先清空
plt.cla()
plt.clf()
fig = plt.figure(figsize=(7, 3))
plt.plot(current_count_list_x, current_count_list_y, c='blue', mec='r', mfc='w', label='Pedestrian volume')
plt.plot(current_count_list_x, y_test, c='brown', ms=standard, label='Density standard')
below_threshold = np.array(current_count_list_y) < int(standard)
plt.scatter(np.array(current_count_list_x)[below_threshold],
np.array(current_count_list_y)[below_threshold],