Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
17ca47ae1c | |||
0452958eed | |||
70fe7069c7 | |||
615d563796 | |||
8bb7820eab | |||
ffe2ad0e1c | |||
52c6ecda01 | |||
ca311b2e71 |
@ -16,6 +16,8 @@ from utils.retrieval_feature import AntiFraudFeatureDataset
|
||||
DEVICE = 'cuda'
|
||||
global Result
|
||||
pre_area = 0
|
||||
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) # 定义膨胀结构元素
|
||||
kernel1 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2, 2)) # 定义腐蚀结构元素
|
||||
def load_image(imfile):
|
||||
#img = np.array(Image.open(imfile)).astype(np.uint8)
|
||||
img = np.array(imfile).astype(np.uint8)
|
||||
@ -65,11 +67,12 @@ def analysis_video(model, video_path, result_path, uuid_barcode, maskpath=None,
|
||||
frame_show = frame
|
||||
nn += 1
|
||||
if flag: #过滤为入侵画面
|
||||
if nn%2==0 or nn%3==0:continue #跳帧
|
||||
#if nn%2==0 or nn%3==0:continue #跳帧
|
||||
flag = img_filter(frame, oriimg, fgbg, nn)
|
||||
if flag: continue
|
||||
else: #RAFT定位
|
||||
if nn%2==0:continue
|
||||
#if nn%2==0:continue #RAFT跳帧
|
||||
pass
|
||||
height, width = frame.shape[:2]
|
||||
frame = cv2.GaussianBlur(frame,(5,5),0)
|
||||
frame = cv2.resize(frame, (int(width/2), int(height/2)), interpolation=cv2.INTER_CUBIC)
|
||||
@ -208,6 +211,8 @@ def img_filter(frame, oriimg, fgbg, nn):
|
||||
# 计算前景掩码
|
||||
fgmask = fgbg.apply(frame)
|
||||
draw1 = cv2.threshold(fgmask, 25, 255, cv2.THRESH_BINARY)[1]
|
||||
draw1 = cv2.erode(draw1, kernel1, iterations=2)
|
||||
draw1 = cv2.dilate(draw1, kernel, iterations=1)
|
||||
if nn==2: return True
|
||||
draw1 = cv2.bitwise_and(oriimg[:, :, 0], draw1)
|
||||
contours_m, hierarchy_m = cv2.findContours(draw1.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
@ -216,7 +221,8 @@ def img_filter(frame, oriimg, fgbg, nn):
|
||||
if len(dics.keys())>0:
|
||||
cc = sorted(dics.keys())
|
||||
iouArea = cv2.contourArea(dics[cc[-1]])
|
||||
if iouArea>10000 and iouArea<40000:
|
||||
#if iouArea>10000 and iouArea<40000:
|
||||
if iouArea>3000 and iouArea<50000:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -58,11 +58,13 @@ def setup_logging(path):
|
||||
return logger
|
||||
|
||||
logger = setup_logging('utils/logging.json')
|
||||
@app.route('/searchv2', methods=['POST'])
|
||||
@app.route('/searchv2', methods=['POST', 'GET'])
|
||||
def search():
|
||||
pre_status = False
|
||||
try:
|
||||
video_name = request.form.get('video_name')
|
||||
if video_name == None:
|
||||
return 'Need video_name'
|
||||
logger.info('get video '+video_name)
|
||||
ocr_file_path = os.sep.join([cfg.Ocrtxt, video_name.split('.')[0]+'.txt'])
|
||||
video_extra_info = request.form.get('video_extra_info')
|
||||
@ -80,16 +82,23 @@ def search():
|
||||
else:
|
||||
state = analysis_video(raft_model, videoPath, '',uuid_barcode,None,net=net, transform=transform,ms=ms, match=True)
|
||||
result = uuid_barcode+'_'+state #参数修改返回结果
|
||||
try:
|
||||
thread = Thread(target=AddObs, kwargs={'file_path':videoPath, 'status':state})
|
||||
thread.start()
|
||||
logger.info(result)
|
||||
print('result >>>>> {}'.format(result))
|
||||
return result
|
||||
except Exception as e:
|
||||
print('result >>>>> {}'.format(result))
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.warning(e) #异常返回00
|
||||
thread = Thread(target=AddObs, kwargs={'file_path':videoPath, 'status':status[3]})
|
||||
thread.start()
|
||||
return uuid_barcode+'_'+status[3] #参数修改返回00
|
||||
thread = Thread(target=AddObs, kwargs={'file_path':videoPath, 'status':state})
|
||||
thread.start()
|
||||
logger.info(result)
|
||||
print('result >>>>> {}'.format(result))
|
||||
return result
|
||||
try:
|
||||
thread = Thread(target=AddObs, kwargs={'file_path':videoPath, 'status':status[3]})
|
||||
thread.start()
|
||||
return uuid_barcode+'_'+status[3] #参数修改返回00
|
||||
except Exception as e:
|
||||
return uuid_barcode+'_'+status[3] #参数修改返回00
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=8085)
|
||||
|
31
up_again.py
Normal file
31
up_again.py
Normal file
@ -0,0 +1,31 @@
|
||||
import os
|
||||
import requests
|
||||
from obs import ObsClient
|
||||
obsClient = ObsClient(
|
||||
access_key_id='LHXJC7GIC2NNUUHHTNVI',
|
||||
secret_access_key='sVWvEItrFKWPp5DxeMvX8jLFU69iXPpzkjuMX3iM',
|
||||
server='https://obs.cn-east-3.myhuaweicloud.com'
|
||||
)
|
||||
bucketName = 'ieemoo-ai'
|
||||
|
||||
def upAgain(path, url):
|
||||
for name in os.listdir(path):
|
||||
try:
|
||||
file_path = os.sep.join([path, name])
|
||||
videoUuid = name.split('_')[1]
|
||||
json_date = {'videoUuid': videoUuid}
|
||||
resp = requests.post(url=url,
|
||||
data=json_date)
|
||||
status = resp.json()['data']
|
||||
time = name.split('-')[0]
|
||||
objectkey = 'videos/'+time+'/'+status+'/'+status+'_'+name
|
||||
#print('>>>>>>>>>',objectkey)
|
||||
resp = obsClient.putFile(bucketName, objectkey, file_path)
|
||||
os.remove(file_path)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
if __name__ == '__main__':
|
||||
path = '../module/ieemoo-ai-searchv2/videos'
|
||||
url = 'https://api.ieemoo.com/emoo-api/intelligence/queryVideoCompareResult.do'
|
||||
upAgain(path, url)
|
@ -1,4 +1,5 @@
|
||||
from obs import ObsClient
|
||||
import obs
|
||||
from datetime import datetime
|
||||
#from config import cfg
|
||||
from utils.config import cfg
|
||||
@ -12,11 +13,14 @@ obsClient = ObsClient(
|
||||
server='https://obs.cn-east-3.myhuaweicloud.com'
|
||||
)
|
||||
bucketName = 'ieemoo-ai'
|
||||
headers = obs.SetObjectMetadataHeader()
|
||||
headers.cacheControl = "no-cache"
|
||||
|
||||
def AddObs(file_path, status):
|
||||
with lock:
|
||||
if not cfg.flag:
|
||||
addobs(file_path, status)
|
||||
os.remove(file_path)
|
||||
else:
|
||||
if status == '02':
|
||||
addobs(file_path, status)
|
||||
@ -26,7 +30,8 @@ def AddObs(file_path, status):
|
||||
shutil.move(file_path, f_dst)
|
||||
|
||||
def addobs(file_path, status): #save videos
|
||||
ti.sleep(3)
|
||||
T1 = ti.time()
|
||||
ti.sleep(1)
|
||||
num = 0
|
||||
videoUuid = os.path.basename(file_path).split('_')[1]
|
||||
json_data = {'videoUuid': videoUuid}
|
||||
@ -34,22 +39,44 @@ def addobs(file_path, status): #save videos
|
||||
data=json_data)
|
||||
status = resp.json()
|
||||
if not 'data' in status:#延迟设置
|
||||
while num < 20:
|
||||
ti.sleep(2)
|
||||
for _ in range(20):
|
||||
ti.sleep(1)
|
||||
num += 1
|
||||
resp = requests.post(url=cfg.Vre, data=json_data)
|
||||
status = resp.json()
|
||||
if not 'data' in status:
|
||||
continue
|
||||
else:break
|
||||
T2 = ti.time()
|
||||
print('videoUuid>>>{} get_status_time>>>{}'.format((videoUuid), (T2-T1)))
|
||||
status = status['data']
|
||||
|
||||
objectkey = os.path.basename(file_path)
|
||||
time = os.path.basename(file_path).split('-')[0]
|
||||
if objectkey.split('.')[-1] in ['avi','mp4']:
|
||||
objectkey = 'videos/'+time+'/'+status+'/'+status+'_'+objectkey
|
||||
resp = obsClient.putFile(bucketName, objectkey, file_path)
|
||||
os.remove(file_path)
|
||||
resp = obsClient.putFile(bucketName, objectkey, file_path, headers=headers)
|
||||
#os.remove(file_path)
|
||||
|
||||
def updateAgain():
|
||||
try:
|
||||
for name in os.listdir(cfg.VIDEOPATH):
|
||||
file_path = os.sep.join([cfg.VIDEOPATH, name])
|
||||
videoUuid = os.path.basename(file_path).split('_')[1]
|
||||
json_data = {'videoUuid': videoUuid}
|
||||
resp = requests.post(url=cfg.Vre,
|
||||
data=json_data)
|
||||
status = resp.json()
|
||||
status = status['data']
|
||||
|
||||
objectkey = os.path.basename(file_path)
|
||||
time = os.path.basename(file_path).split('-')[0]
|
||||
if objectkey.split('.')[-1] in ['avi','mp4']:
|
||||
objectkey = 'videos/'+time+'/'+status+'/'+status+'_'+objectkey
|
||||
resp = obsClient.putFile(bucketName, objectkey, file_path, headers=headers)
|
||||
os.remove(file_path)
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
def Addimg(uuid_barcode):
|
||||
time = uuid_barcode.split('-')[0].split('_')[-1]
|
||||
@ -59,14 +86,14 @@ def Addimg(uuid_barcode):
|
||||
file_path = os.sep.join([cfg.Tempimg, '3_'+uuid_barcode+'.jpg'])
|
||||
if not os.path.exists(file_path):
|
||||
file_path = os.sep.join([cfg.Tempimg, 'ex_'+uuid_barcode+'.jpg'])
|
||||
resp = obsClient.putFile(bucketName, objectkey, file_path)
|
||||
resp = obsClient.putFile(bucketName, objectkey, file_path, headers=headers)
|
||||
|
||||
def Addimg_content(uuid_barcode, context):
|
||||
success, encoded_image = cv2.imencode(".jpg",context)
|
||||
context = encoded_image.tobytes()
|
||||
time = uuid_barcode.split('-')[0]
|
||||
objectkey = 'imgs/'+time+'/'+uuid_barcode+'.jpg'
|
||||
resp = obsClient.putContent(bucketName, objectkey, context)
|
||||
resp = obsClient.putContent(bucketName, objectkey, context, headers=headers)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import cv2
|
||||
|
Reference in New Issue
Block a user