update
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -137,6 +137,8 @@ dmypy.json
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
data/CamVid/
|
||||
data/test/
|
||||
data/tmp/
|
||||
#*.jpg
|
||||
*.png
|
||||
*.pth
|
||||
|
@ -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))
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user