Files
ieemoo-ai-searchv2/utils/updateObs.py
2023-11-23 15:11:14 +08:00

81 lines
2.9 KiB
Python

from obs import ObsClient
from datetime import datetime
#from config import cfg
from utils.config import cfg
import os, sys
import time as ti
import base64,requests,cv2,shutil
from utils.up_load_file import up_load
up_load_data = up_load()
def AddObs(file_path, status):
if not cfg.flag:
addobs(file_path, status)
else:
if status == '02':
addobs(file_path, status)
else:
objectkey = os.path.basename(file_path)
f_dist = os.sep.join([cfg.tempvideos, status+'_'+objectkey])
shutil.move(file_path, f_dst)
def addobs(file_path, status): #save videos
ti.sleep(0.5)
videoUuid = os.path.basename(file_path).split('_')[1]
json_data = {'videoUuid': videoUuid}
for vre in [cfg.VreTest, cfg.VreTest2, cfg.Vre]:
resp = requests.post(url=vre, data=json_data)
status = resp.json()
if not 'data' in status:#延迟设置
ti.sleep(0.5)
resp = requests.post(url=vre, data=json_data)
status = resp.json()
if 'data' in status:
break
else:
break
if not 'data' in status:
return 'can not get the status'
status = status['data']
objectkey = os.path.basename(file_path)
time = os.path.basename(file_path).split('-')[0]
objectkey = 'videos/'+time+'/'+status+'/'+status+'_'+objectkey
if status == '02' or get_weightStatus(objectkey):
up_load_data.upLoad(objectkey, file_path)
def Addimg(uuid_barcode):
time = uuid_barcode.split('-')[0].split('_')[-1]
objectkey = 'imgs/'+time+'/'+uuid_barcode+'.jpg'
file_path = os.sep.join([cfg.Tempimg, '5_'+uuid_barcode+'.jpg'])
if not os.path.exists(file_path):
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'])
uuid = uuid_barcode.split('_')[-1]
if get_weightStatus(uuid):
up_load_data.upLoad(objectkey, file_path)
def Addimg_content(uuid_barcode, context):
file_path = "context.jpg"
cv2.imwrite(file_path, context)
success, encoded_image = cv2.imencode(".jpg",context)
context = encoded_image.tobytes()
time = uuid_barcode.split('-')[0]
objectkey = 'imgs/'+time+'/'+uuid_barcode+'.jpg'
if get_weightStatus(uuid_barcode):
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__':
import cv2
context = cv2.imread('/home/lc/project/ieemoo-ai-search/data/imgs/20230625-094651_37dd99b0-520d-457b-8615-efdb7f53b5b4_6907992825762.jpg')
uuid_barcode = '20230625-094651_37dd99b0-520d-457b-8615-efdb7f53b5b4'
Addimg_content(uuid_barcode, context)