Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加了ID计数,以及4个测试视频 #32

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions count.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#--- START OF FILE count.py ---

from subprocess import list2cmdline
import sys

Expand Down Expand Up @@ -25,7 +27,7 @@
########################################


source_dir = 'inference/input/test3.mp4' # '0' # 要打开的文件。若要调用摄像头,需要设置为字符串'0',而不是数字0,按q退出播放
source_dir = 'inference/input/test4.mp4' # '0' # 要打开的文件。若要调用摄像头,需要设置为字符串'0',而不是数字0,按q退出播放
output_dir = 'inference/output' # 要保存到的文件夹
show_video = True # 运行时是否显示
save_video = True # 是否保存运行结果视频
Expand All @@ -37,8 +39,8 @@

lines = [ # 在这里定义检测线
# 一条线就是一个list,内容为[x1, y1, x2, y2, (R, G, B), 线的粗细],例如:
[300, 1080, 1250, 600, (255,0,0), 2],
[1660, 610, 1920, 900, (0,255,0), 2],
[0, 0, 1300, 300, (255,0,0), 2],
#[0, 0, 0, 0, (0,0,255), 2],

]

Expand Down Expand Up @@ -95,6 +97,10 @@ def big_side(line, x, y) -> bool:

########################################

id_list = [] # 用于记录所有出现过的ID

########################################



palette = (2 ** 11 - 1, 2 ** 15 - 1, 2 ** 20 - 1)
Expand Down Expand Up @@ -362,6 +368,13 @@ def detect(opt):
f.write(('%g ' * 10 + '\n') % (frame_idx, identity, bbox_left,
bbox_top, bbox_w, bbox_h, -1, -1, -1, -1)) # label format
# 修改后的格式为:帧序号、框序号、框到左边距离、框到顶上距离、框横长、框竖高,原命名应该是把顶上和左边命名写反了

# 记录出现过的ID
for output in outputs:
identity = output[-1]
if identity not in id_list:
id_list.append(identity)

else:
deepsort.increment_ages()

Expand All @@ -378,6 +391,9 @@ def detect(opt):
cv2.putText(im0, f'dir1 = {line[6][0]}', (gap*line_idx+25, 25), cv2.FONT_HERSHEY_COMPLEX, 1, line[4], 2) # 画布、内容、左下角坐标、字体、字号(数字越大字越大)、字颜色、笔画粗细
cv2.putText(im0, f'dir2 = {line[6][1]}', (gap*line_idx+25, 50), cv2.FONT_HERSHEY_COMPLEX, 1, line[4], 2) # 画布、内容、左下角坐标、字体、字号(数字越大字越大)、字颜色、笔画粗细

# 显示ID数量
cv2.putText(im0, f'Total IDs: {len(id_list)}', (25, 75), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)

# 写入保存文件
if save_txt:
with open(out+'/number.txt', 'a') as f:
Expand All @@ -399,7 +415,7 @@ def detect(opt):
# Save results (image with detections)
if save_vid:
if vid_path != save_path: # new video
vid_path = save_path
vid_path = save_path
if isinstance(vid_writer, cv2.VideoWriter):
vid_writer.release() # release previous video writer
if vid_cap: # video
Expand Down Expand Up @@ -446,3 +462,5 @@ def detect(opt):

with torch.no_grad():
detect(args)

#--- END OF FILE count.py ---
Binary file added inference/input/test4.mp4
Binary file not shown.
Binary file added inference/input/test5.mp4
Binary file not shown.
Binary file added inference/input/test6.mp4
Binary file not shown.
Binary file added inference/input/test7.mp4
Binary file not shown.