From f4d1baafb1a5dda4dfcdc001b7b16d66f46fda17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=99=A8?= Date: Thu, 2 Mar 2023 16:22:49 +0800 Subject: [PATCH] update --- .gitignore | 2 ++ checkobject.py | 31 ++++++++++++++++++++++--------- ieemoo-ai-filtervideo.py | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index da236c2..b835c6c 100644 --- a/.gitignore +++ b/.gitignore @@ -137,6 +137,8 @@ dmypy.json # Cython debug symbols cython_debug/ data/CamVid/ +data/test/ +data/tmp/ #*.jpg *.png *.pth diff --git a/checkobject.py b/checkobject.py index f601d05..a4d7626 100644 --- a/checkobject.py +++ b/checkobject.py @@ -3,7 +3,8 @@ import cv2 as cv import os, time def get_object_location(pfile, mask_path = 'lianhua_1.jpg'): - kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (3, 3)) # 定义结构元素 + kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (3, 3)) # 定义膨胀结构元素 + kernel1 = cv.getStructuringElement(cv.MORPH_ELLIPSE, (2, 2)) # 定义腐蚀结构元素 fgbg = cv.createBackgroundSubtractorMOG2(detectShadows=False) nu, nn = 0, 1 flag = False @@ -28,8 +29,10 @@ def get_object_location(pfile, mask_path = 'lianhua_1.jpg'): # 计算前景掩码 fgmask = fgbg.apply(frame_motion) draw1 = cv.threshold(fgmask, 25, 255, cv.THRESH_BINARY)[1] # 二值化 + draw1 = cv.erode(draw1, kernel1, iterations=2) draw1 = cv.dilate(draw1, kernel, iterations=1) - if nn<20: #判断20帧内有入侵动作 + cv.imwrite('data/tmp/'+str(nn)+'.jpg', draw1) + if nn<80: #判断80帧内有入侵动作 flag = check_tings(mask_path, draw1) T2 = time.time() print('single video >>> {}-->{}-->{}'.format(pfile, nn, (T2 - T1))) @@ -46,17 +49,27 @@ def check_tings(mask_path, img): cc = sorted(dics.keys()) iouArea = cv.contourArea(dics[cc[-1]]) #print('iouara>>>>>>> {}'.format(iouArea)) - if iouArea>15000 and iouArea<40000: - return True#'1' + if iouArea>3000 and iouArea<50000: + return True else: - return False #'0' + return False else: - return False #'0' + return False if __name__ == '__main__': - pfile = "videos/20230130-100958_e5910f7d-90dd-4f6b-9468-689ba45fe656.mp4" - mask_path = 'models/lianhua_1.jpg' + path = "data/test" + mask_path = 'lianhua_1.jpg' #frame_path = 'frame' #result_path = 'result' - get_object_location(pfile, mask_path) + nn = 0 + names = [] + for name in os.listdir(path): + pfile = os.sep.join([path, name]) + flag = get_object_location(pfile, mask_path) + if flag == '0': + nn += 1 + names.append(name) + #print('<><><><><<><{}'.format(nn)) + #print('<><><><><<><{}'.format(names)) + diff --git a/ieemoo-ai-filtervideo.py b/ieemoo-ai-filtervideo.py index 644a93c..c05562f 100644 --- a/ieemoo-ai-filtervideo.py +++ b/ieemoo-ai-filtervideo.py @@ -39,6 +39,6 @@ def filtervideo(): os.remove(videopath) print('{} >>>>{}'.format((date),(results))) return json.dumps(results) - + if __name__ == '__main__': app.run(host='0.0.0.0', port=8085)