8 Commits
edge ... master

Author SHA1 Message Date
17ca47ae1c update 2023-06-21 15:42:30 +08:00
0452958eed update 2023-06-21 11:22:44 +08:00
70fe7069c7 update 2023-04-26 14:31:18 +08:00
615d563796 update 2023-04-24 17:43:05 +08:00
8bb7820eab update 2023-04-24 17:40:48 +08:00
ffe2ad0e1c update 2023-01-28 13:34:35 +08:00
52c6ecda01 masterUpdate 2023-01-16 09:10:32 +08:00
ca311b2e71 update 2022-12-14 15:20:32 +08:00
7 changed files with 128 additions and 164 deletions

View File

@ -16,6 +16,8 @@ from utils.retrieval_feature import AntiFraudFeatureDataset
DEVICE = 'cuda' DEVICE = 'cuda'
global Result global Result
pre_area = 0 pre_area = 0
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) # 定义膨胀结构元素
kernel1 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2, 2)) # 定义腐蚀结构元素
def load_image(imfile): def load_image(imfile):
#img = np.array(Image.open(imfile)).astype(np.uint8) #img = np.array(Image.open(imfile)).astype(np.uint8)
img = np.array(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 frame_show = frame
nn += 1 nn += 1
if flag: #过滤为入侵画面 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) flag = img_filter(frame, oriimg, fgbg, nn)
if flag: continue if flag: continue
else: #RAFT定位 else: #RAFT定位
if nn%2==0:continue #if nn%2==0:continue #RAFT跳帧
pass
height, width = frame.shape[:2] height, width = frame.shape[:2]
frame = cv2.GaussianBlur(frame,(5,5),0) frame = cv2.GaussianBlur(frame,(5,5),0)
frame = cv2.resize(frame, (int(width/2), int(height/2)), interpolation=cv2.INTER_CUBIC) 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) fgmask = fgbg.apply(frame)
draw1 = cv2.threshold(fgmask, 25, 255, cv2.THRESH_BINARY)[1] 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 if nn==2: return True
draw1 = cv2.bitwise_and(oriimg[:, :, 0], draw1) draw1 = cv2.bitwise_and(oriimg[:, :, 0], draw1)
contours_m, hierarchy_m = cv2.findContours(draw1.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) 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: if len(dics.keys())>0:
cc = sorted(dics.keys()) cc = sorted(dics.keys())
iouArea = cv2.contourArea(dics[cc[-1]]) 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 False
return True return True

View File

@ -31,7 +31,7 @@ app = Flask(__name__)
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
#parser.add_argument('--model', default='../module/ieemoo-ai-search/model/now/raft-things.pth',help="restore checkpoint") #parser.add_argument('--model', default='../module/ieemoo-ai-search/model/now/raft-things.pth',help="restore checkpoint")
parser.add_argument('--model', default='../module/ieemoo-ai-searchv2/model/now/raft-small.pth',help="restore checkpoint") parser.add_argument('--model', default='../module/ieemoo-ai-search/model/now/raft-small.pth',help="restore checkpoint")
#parser.add_argument('--small', action='store_true', help='use small model') #parser.add_argument('--small', action='store_true', help='use small model')
parser.add_argument('--small', type=bool, default=True, help='use small model') parser.add_argument('--small', type=bool, default=True, help='use small model')
parser.add_argument('--mixed_precision', action='store_true', help='use mixed precision') parser.add_argument('--mixed_precision', action='store_true', help='use mixed precision')
@ -89,7 +89,7 @@ def search():
print('result >>>>> {}'.format(result)) print('result >>>>> {}'.format(result))
return result return result
except Exception as e: except Exception as e:
print('Exception >>>>> {}'.format(result)) print('result >>>>> {}'.format(result))
return result return result
except Exception as e: except Exception as e:
logger.warning(e) #异常返回00 logger.warning(e) #异常返回00

View File

@ -1,21 +1,22 @@
apscheduler==3.10.4 esdk_obs_python==3.21.8
cos_python_sdk_v5==1.9.26 Flask==2.0.0
esdk_obs_python==3.23.9.1 gevent==21.1.2
Flask==3.0.0 matplotlib==3.4.1
gevent==23.9.1 numpy==1.20.2
h5py==3.7.0 esdk-obs-python --trusted-host pypi.org
matplotlib==3.6.2 opencv_python==4.5.5.64
numpy==1.19.2 opencv-contrib-python==4.5.5.64
numpy==1.24.4 Pillow==9.1.0
opencv_python==4.8.1.78 scipy==1.6.2
opencv_python_headless==4.7.0.68 setuptools==49.6.0
pandas==1.4.4 coremltools==5.2.0
Pillow==9.4.0 onnx==1.7.0
pandas==1.2.4
pycocotools==2.0.2
PyYAML==6.0 PyYAML==6.0
Requests==2.31.0 requests==2.25.1
scipy==1.3.1 seaborn==0.11.1
setuptools==68.0.0 thop==0.0.31.post2005241907
torch==1.8.1+cu111 tqdm==4.60.0
torchvision==0.9.1+cu111 ml-collections==0.1.1
Werkzeug==3.0.1 apache-skywalking
yacs==0.1.8

31
up_again.py Normal file
View 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)

View File

@ -51,37 +51,9 @@ _C.fgbgmask_old = '../module/ieemoo-ai-searchv2/model/now/ori_old.jpg'
_C.URL = 'https://api.ieemoo.com/emoo-api/intelligence' #online _C.URL = 'https://api.ieemoo.com/emoo-api/intelligence' #online
#_C.URL = 'http://api.test.ieemoo.com/emoo-api/intelligence' #_C.URL = 'http://api.test.ieemoo.com/emoo-api/intelligence'
_C.VreTest = 'http://api.test.ieemoo.cn/emoo-api/intelligence/queryVideoCompareResult.do' #test #_C.Vre = 'http://api.test2.ieemoo.cn/emoo-api/intelligence/queryVideoCompareResult.do'
_C.VreTest2 = 'http://api.test2.ieemoo.cn/emoo-api/intelligence/queryVideoCompareResult.do' #test2
_C.Vre = 'https://api.ieemoo.com/emoo-api/intelligence/queryVideoCompareResult.do' #online _C.Vre = 'https://api.ieemoo.com/emoo-api/intelligence/queryVideoCompareResult.do' #online
_C.backups = '../module/output/videos'
_C.riskControl = 'http://api.test2.ieemoo.com/emoo-api/riskControl/shoporder/checkUploadAiImages?storeId=32001001'
_C.Ocrimg = '../module/ieemoo-ai-assist/imgs'#post ocr img _C.Ocrimg = '../module/ieemoo-ai-assist/imgs'#post ocr img
_C.Ocrtxt = '../module/ieemoo-ai-assist/document'#post ocr txts _C.Ocrtxt = '../module/ieemoo-ai-assist/document'#post ocr txts
_C.Ocrvideo = '../module/ieemoo-ai-assist/videos'#post ocr video _C.Ocrvideo = '../module/ieemoo-ai-assist/videos'#post ocr video
#obs
_C.obs_access_key_id='LHXJC7GIC2NNUUHHTNVI'
_C.obs_secret_access_key='sVWvEItrFKWPp5DxeMvX8jLFU69iXPpzkjuMX3iM'
_C.obs_server='https://obs.cn-east-3.myhuaweicloud.com'
_C.obs_bucketName = 'ieemoo-ai'
#cos
_C.cos_secret_id = 'AKIDIVcVFnBMMLCqbFF6lPr6930tc8VlrlS0'
_C.cos_secret_key = 'oYGrJG2d3LTUPBoFTZVEmC1kQ1ObdTkr'
_C.cos_region = 'ap-shanghai'
_C.cos_Bucket = 'ieemoo-ai-1321281601'
#s3
_C.s3_secret_id = 'v1wAfxqZqJYbA7kuB9dc'
_C.s3_secret_key = 'ZICGRJetjNIXhnqH1yfraoigydWoF2WTggtO9AhR'
_C.s3_region = '172.16.0.186:9000'
_C.s3_Bucket = 'ieemoo-ai'
#cos or obs
_C.obs = True
_C.cos = False
_C.s3 = True

View File

@ -1,68 +0,0 @@
from obs import ObsClient
import obs
from utils.config import cfg
from qcloud_cos import CosConfig,CosS3Client
from qcloud_cos.cos_exception import CosClientError, CosServiceError
from minio import Minio
from minio.error import S3Error
def obsInit():
print('start init obs <<')
obsClient = ObsClient(
access_key_id=cfg.obs_access_key_id,
secret_access_key=cfg.obs_secret_access_key,
server=cfg.obs_server)
bucketName = cfg.obs_bucketName
headers = obs.SetObjectMetadataHeader()
headers.cacheControl = "no-cache"
return obsClient, headers
def cosInit():
print('start init cos <<')
secret_id = cfg.cos_secret_id
secret_key = cfg.cos_secret_key
region = cfg.cos_region
config = CosConfig(Region=region, Secret_id=secret_id, Secret_key=secret_key)
client = CosS3Client(config)
return client
def s3Init():
print('start init s3 <<')
secret_id = cfg.s3_secret_id
secret_key = cfg.s3_secret_key
region = cfg.s3_region
client = Minio(region, secure=False, access_key=secret_id, secret_key=secret_key)
return client
class up_load:
def __init__(self):
if cfg.cos:
self.cosclient = cosInit()
if cfg.obs:
self.obsclient, self.headers = obsInit()
if cfg.s3:
self.s3client = s3Init()
def upLoad(self, key=None, datapath=None):
# 使用高级接口断点续传,失败重试时不会上传已成功的分块(这里重试10次)
response = 'get re'
if cfg.cos:
for i in range(0, 10):
try:
response = self.cosclient.upload_file(
Bucket=cfg.cos_Bucket,
Key=key,
LocalFilePath=datapath)
break
except CosClientError or CosServiceError as e:
print(e)
if cfg.obs:
response = self.obsclient.putFile(cfg.obs_bucketName, key, datapath)
if cfg.s3:
found = self.s3client.bucket_exists(cfg.s3_Bucket)
if not found:
self.s3client.make_bucket(cfg.s3_Bucket)
self.s3client.fput_object(cfg.obs_bucketName, key, datapath)
return response

View File

@ -1,16 +1,26 @@
from obs import ObsClient from obs import ObsClient
import obs
from datetime import datetime from datetime import datetime
#from config import cfg #from config import cfg
from utils.config import cfg from utils.config import cfg
import os, sys import os,threading
import time as ti import time as ti
import base64,requests,cv2,shutil import base64,requests,cv2,shutil
from utils.up_load_file import up_load lock = threading.Lock()
obsClient = ObsClient(
access_key_id='LHXJC7GIC2NNUUHHTNVI',
secret_access_key='sVWvEItrFKWPp5DxeMvX8jLFU69iXPpzkjuMX3iM',
server='https://obs.cn-east-3.myhuaweicloud.com'
)
bucketName = 'ieemoo-ai'
headers = obs.SetObjectMetadataHeader()
headers.cacheControl = "no-cache"
up_load_data = up_load()
def AddObs(file_path, status): def AddObs(file_path, status):
with lock:
if not cfg.flag: if not cfg.flag:
addobs(file_path, status) addobs(file_path, status)
os.remove(file_path)
else: else:
if status == '02': if status == '02':
addobs(file_path, status) addobs(file_path, status)
@ -20,28 +30,53 @@ def AddObs(file_path, status):
shutil.move(file_path, f_dst) shutil.move(file_path, f_dst)
def addobs(file_path, status): #save videos def addobs(file_path, status): #save videos
ti.sleep(0.5) T1 = ti.time()
ti.sleep(1)
num = 0
videoUuid = os.path.basename(file_path).split('_')[1] videoUuid = os.path.basename(file_path).split('_')[1]
json_data = {'videoUuid': videoUuid} json_data = {'videoUuid': videoUuid}
for vre in [cfg.VreTest, cfg.VreTest2, cfg.Vre]: resp = requests.post(url=cfg.Vre,
resp = requests.post(url=vre, data=json_data) data=json_data)
status = resp.json() status = resp.json()
if not 'data' in status:#延迟设置 if not 'data' in status:#延迟设置
ti.sleep(0.5) for _ in range(20):
resp = requests.post(url=vre, data=json_data) ti.sleep(1)
num += 1
resp = requests.post(url=cfg.Vre, data=json_data)
status = resp.json() status = resp.json()
if 'data' in status:
break
else:
break
if not 'data' in status: if not 'data' in status:
return 'can not get the status' continue
else:break
T2 = ti.time()
print('videoUuid>>>{} get_status_time>>>{}'.format((videoUuid), (T2-T1)))
status = status['data'] status = status['data']
objectkey = os.path.basename(file_path) objectkey = os.path.basename(file_path)
time = os.path.basename(file_path).split('-')[0] time = os.path.basename(file_path).split('-')[0]
if objectkey.split('.')[-1] in ['avi','mp4']:
objectkey = 'videos/'+time+'/'+status+'/'+status+'_'+objectkey objectkey = 'videos/'+time+'/'+status+'/'+status+'_'+objectkey
if status == '02' or get_weightStatus(objectkey): resp = obsClient.putFile(bucketName, objectkey, file_path, headers=headers)
up_load_data.upLoad(objectkey, file_path) #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): def Addimg(uuid_barcode):
time = uuid_barcode.split('-')[0].split('_')[-1] time = uuid_barcode.split('-')[0].split('_')[-1]
@ -51,27 +86,14 @@ def Addimg(uuid_barcode):
file_path = os.sep.join([cfg.Tempimg, '3_'+uuid_barcode+'.jpg']) file_path = os.sep.join([cfg.Tempimg, '3_'+uuid_barcode+'.jpg'])
if not os.path.exists(file_path): if not os.path.exists(file_path):
file_path = os.sep.join([cfg.Tempimg, 'ex_'+uuid_barcode+'.jpg']) file_path = os.sep.join([cfg.Tempimg, 'ex_'+uuid_barcode+'.jpg'])
uuid = uuid_barcode.split('_')[-1] resp = obsClient.putFile(bucketName, objectkey, file_path, headers=headers)
if get_weightStatus(uuid):
up_load_data.upLoad(objectkey, file_path)
def Addimg_content(uuid_barcode, context): def Addimg_content(uuid_barcode, context):
file_path = "context.jpg"
cv2.imwrite(file_path, context)
success, encoded_image = cv2.imencode(".jpg",context) success, encoded_image = cv2.imencode(".jpg",context)
context = encoded_image.tobytes() context = encoded_image.tobytes()
time = uuid_barcode.split('-')[0] time = uuid_barcode.split('-')[0]
objectkey = 'imgs/'+time+'/'+uuid_barcode+'.jpg' objectkey = 'imgs/'+time+'/'+uuid_barcode+'.jpg'
if get_weightStatus(uuid_barcode): resp = obsClient.putContent(bucketName, objectkey, context, headers=headers)
up_load_data.upLoad(objectkey, file_path)
def get_weightStatus(uuid):
uuid = uuid.split('_')[1]
resp = requests.post(url = cfg.riskControl)
up_uuid = resp.json()['data']
if uuid in up_uuid:
return True
return False
if __name__ == '__main__': if __name__ == '__main__':
import cv2 import cv2