Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ import tempfile #创建输出临时文件夹
|
|
| 10 |
import os
|
| 11 |
from detectMotion import * #单独的运动检测
|
| 12 |
import time
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
#导入YoloV8模型,第一次使用会下载模型到当前文件夹当中
|
|
@@ -38,12 +39,13 @@ tracker=Sort(max_age=20,min_hits=3,iou_threshold=0.3)
|
|
| 38 |
def plot_number():
|
| 39 |
global number_of_people_in_one_frame_list, flag
|
| 40 |
if flag == False:
|
| 41 |
-
time.sleep(
|
| 42 |
flag = True
|
| 43 |
-
if number_of_people_in_one_frame_list == None:
|
| 44 |
-
raise gr.Error("请先选择需要处理的视频")
|
| 45 |
plt.close()
|
| 46 |
fig = plt.figure()
|
|
|
|
|
|
|
|
|
|
| 47 |
plt.plot(number_of_people_in_one_frame_list)
|
| 48 |
return fig
|
| 49 |
|
|
@@ -98,7 +100,8 @@ def processVideo(inputPath,codec):
|
|
| 98 |
flag = False
|
| 99 |
number_of_people_in_one_frame = 0
|
| 100 |
number_of_people_in_one_frame_list = []
|
| 101 |
-
number_of_people=0
|
|
|
|
| 102 |
cap = cv2.VideoCapture(inputPath)#从inputPath读入视频
|
| 103 |
fps = cap.get(cv2.CAP_PROP_FPS) #获取视频的帧率
|
| 104 |
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
|
|
@@ -133,7 +136,7 @@ def processVideo(inputPath,codec):
|
|
| 133 |
detections=np.empty((0, 5))#初始化运动检测
|
| 134 |
if not(ret):#当视频全部读完,ret返回false,终止循环,视频帧读取和写入结束
|
| 135 |
break
|
| 136 |
-
img,
|
| 137 |
#读取推理的数据
|
| 138 |
for r in results:
|
| 139 |
boxes=r.boxes
|
|
@@ -151,7 +154,9 @@ def processVideo(inputPath,codec):
|
|
| 151 |
#cvzone.putTextRect(img,f'{classNames[cls]}{conf}',(max(0,x1),max(30,y1)),scale=0.7,thickness=1)
|
| 152 |
currentArray=np.array([x1,y1,x2,y2,conf])
|
| 153 |
detections=np.vstack((detections,currentArray))#按行堆叠数据
|
| 154 |
-
|
|
|
|
|
|
|
| 155 |
#print(type(number_of_people_in_one_frame_list))
|
| 156 |
number_of_people_in_one_frame = 0
|
| 157 |
#运动检测
|
|
|
|
| 10 |
import os
|
| 11 |
from detectMotion import * #单独的运动检测
|
| 12 |
import time
|
| 13 |
+
#from matplotlib.pyplot import MultipleLocator
|
| 14 |
|
| 15 |
|
| 16 |
#导入YoloV8模型,第一次使用会下载模型到当前文件夹当中
|
|
|
|
| 39 |
def plot_number():
|
| 40 |
global number_of_people_in_one_frame_list, flag
|
| 41 |
if flag == False:
|
| 42 |
+
time.sleep(15)
|
| 43 |
flag = True
|
|
|
|
|
|
|
| 44 |
plt.close()
|
| 45 |
fig = plt.figure()
|
| 46 |
+
plt.xlabel('Second')
|
| 47 |
+
plt.ylabel('Traffic')
|
| 48 |
+
plt.grid(linestyle='--', alpha=0.3, linewidth=2)
|
| 49 |
plt.plot(number_of_people_in_one_frame_list)
|
| 50 |
return fig
|
| 51 |
|
|
|
|
| 100 |
flag = False
|
| 101 |
number_of_people_in_one_frame = 0
|
| 102 |
number_of_people_in_one_frame_list = []
|
| 103 |
+
number_of_people = 0
|
| 104 |
+
sum_of_frame = 0
|
| 105 |
cap = cv2.VideoCapture(inputPath)#从inputPath读入视频
|
| 106 |
fps = cap.get(cv2.CAP_PROP_FPS) #获取视频的帧率
|
| 107 |
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
|
|
|
|
| 136 |
detections=np.empty((0, 5))#初始化运动检测
|
| 137 |
if not(ret):#当视频全部读完,ret返回false,终止循环,视频帧读取和写入结束
|
| 138 |
break
|
| 139 |
+
img, __, __= hisEqulColor(img)#视频增强
|
| 140 |
#读取推理的数据
|
| 141 |
for r in results:
|
| 142 |
boxes=r.boxes
|
|
|
|
| 154 |
#cvzone.putTextRect(img,f'{classNames[cls]}{conf}',(max(0,x1),max(30,y1)),scale=0.7,thickness=1)
|
| 155 |
currentArray=np.array([x1,y1,x2,y2,conf])
|
| 156 |
detections=np.vstack((detections,currentArray))#按行堆叠数据
|
| 157 |
+
sum_of_frame += 1
|
| 158 |
+
if sum_of_frame % fps == 0:
|
| 159 |
+
number_of_people_in_one_frame_list.append(number_of_people_in_one_frame)
|
| 160 |
#print(type(number_of_people_in_one_frame_list))
|
| 161 |
number_of_people_in_one_frame = 0
|
| 162 |
#运动检测
|