diff --git a/floder/config.py b/floder/config.py index b1caa13..cc7c37f 100644 --- a/floder/config.py +++ b/floder/config.py @@ -5,13 +5,13 @@ cfg = _C _C.RESIZE = 648 #Monitoring table of commodity identification System -_C.model_path = './checkpoint/best_model.pth' -_C.maskImg = './imgs/mask.jpg' -_C.maskImg1 = './imgs/mask1.jpg' +_C.model_path = '../module/ieemoo-ai-conpurchase/model/now/best_model.pth' +_C.maskImg = '../module/ieemoo-ai-conpurchase/model/now/mask.jpg' +_C.maskImg1 = '../module/ieemoo-ai-conpurchase/model/now/mask1.jpg' -_C.maskAreaImg = './imgs/maskAreaImg.jpg' -_C.maskAreaImg1 = './imgs/maskAreaImg1.jpg' +_C.maskAreaImg = '../module/ieemoo-ai-conpurchase/model/now/maskAreaImg.jpg' +_C.maskAreaImg1 = '../module/ieemoo-ai-conpurchase/model/now/maskAreaImg1.jpg' -_C.streamModel = './checkpoint/raft-things.pth' -_C.hFile = './floder/tempdata' -_C.videoPath = './floder/tempvideos' +_C.streamModel = '../module/ieemoo-ai-conpurchase/model/now/raft-things.pth' +_C.hFile = '../module/ieemoo-ai-conpurchase/document' +_C.videoPath = '../module/ieemoo-ai-conpurchase/videos' diff --git a/ieemoo-ai-conpurchase.py b/ieemoo-ai-conpurchase.py index 62af9d5..502eb3f 100644 --- a/ieemoo-ai-conpurchase.py +++ b/ieemoo-ai-conpurchase.py @@ -4,6 +4,7 @@ from network.vanalysis_video import vanalysis, raft_init_model import argparse from floder.config import cfg from utils.detect import opvideo +from utils.opfile import uploadf, removef from utils.embedding import DataProcessing as dp app = Flask(__name__) @@ -22,18 +23,26 @@ dps = dp(opt.checkpoint, cfg.model_path, opt.device) opv = opvideo(flowmodel, dps) @app.route('/conpurchase', methods=['POST', 'GET']) def conpurchase(): - flag = request.form.get('flag') - num_id = request.form.get('num') - video_name = request.form.get('uuid') - video_data = request.files['video'] - videoPath = os.sep.join([cfg.videoPath, video_name]) - video_data.save(videoPath) - #opv.addFreature(uuid, num_id, videoPath) - #opv.opFreature(uuid, finalnum, videoPath) - if not flag: - opv.addFreature(uuid, num_id, videoPath) - else: - result = opv.opFreature(uuid, num_id, videoPath) + try: + result = 'continue' + flag = request.form.get('flag') + num_id = request.form.get('num') + video_name = request.form.get('uuid') + #print('>>>>>>>>>>flag:{} num_id:{} video_name:{}'.format(flag, num_id, video_name)) + uuid = video_name.split('_')[1] + video_data = request.files['video'] + videoPath = os.sep.join([cfg.videoPath, uuid+'.mp4']) + video_data.save(videoPath) + uploadf(video_name, num_id, videoPath) + if flag == 'False': + opv.addFeature(uuid, num_id, videoPath) + else: + result = opv.opFeature(uuid, num_id, videoPath) + os.remove(videoPath) + #os.remove(os.sep.join([cfg.hFile, uuid+'.h5'])) + removef(uuid) + except Exception as e: + print(e) return result if __name__ == '__main__': app.run('0.0.0.0', 8898) diff --git a/test.py b/test.py index 83420db..beb888c 100644 --- a/test.py +++ b/test.py @@ -26,15 +26,8 @@ if __name__ == '__main__': video2 = './imgs/2.mp4' video3 = './imgs/3.mp4' video4 = './imgs/4.mp4' - opv.addFeature('test', 1, video1) - opv.addFeature('test', 2, video2) - opv.addFeature('test', 3, video3) - opv.opFeature('test', 4, video4) - #imglist = filt(video) - #model = raft_init_model(opt) - #imgs = vanalysis(model, imglist) - #print('>>>>>>>>>>>>>>>>>> {}'.format(type(imgs))) - # - #re = dps.getFeatures(imgs) - - #print(re) + opv.addFeature('test', 0, video1) + opv.addFeature('test', 1, video2) + opv.addFeature('test', 2, video3) + result = opv.opFeature('test', 3, video4) + print('result>>>>> {}'.format(result)) diff --git a/utils/detect.py b/utils/detect.py index d0b80e0..831ac30 100644 --- a/utils/detect.py +++ b/utils/detect.py @@ -21,11 +21,11 @@ class opvideo: def opFeature(self, uuid, finalnum, video): videoFeature = [] self.addFeature(uuid, finalnum, video) - for num_id in range(0, finalnum): + print('>>>>>{}'.format(range(0, int(finalnum)+1))) + for num_id in range(0, int(finalnum)+1): feature = readf(uuid, num_id) videoFeature.append(feature) redic = self.opVideFeature(videoFeature) - #print(redic) return redic def opVideFeature(self, videoFeature): diff --git a/utils/opfile.py b/utils/opfile.py index b7c3bf0..18020ae 100644 --- a/utils/opfile.py +++ b/utils/opfile.py @@ -1,5 +1,14 @@ import h5py, os from floder.config import cfg +from obs import ObsClient +import obs +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" def writef(uuid, num_id, feature): fname = os.sep.join([cfg.hFile, uuid+'.h5']) @@ -9,7 +18,7 @@ def writef(uuid, num_id, feature): else: f = h5py.File(fname, 'a') f[str(num_id)] = feature - print('>>>>>>>have been write') + #print('>>>>>>>have been write') f.close() def readf(uuid, num_id): @@ -22,3 +31,9 @@ def readf(uuid, num_id): def removef(uuid): fname = os.sep.join([cfg.hFile, uuid+'.h5']) os.remove(fname) + +def uploadf(video_name, num, file_path): + time = video_name.split('-')[0] + objectkey = video_name.split('.')[0]+'_'+str(num)+'.mp4' + objectkey = 'conpurchase/'+time+'/'+objectkey + resp = obsClient.putFile(bucketName, objectkey, file_path, headers=headers)