import sys import argparse import requests from utils.tools import EvaluteMap from utils.retrieval_feature import AntiFraudFeatureDataset from utils.tools import createNet, rotate_bound from utils.monitor import Moniting from cirtorch.networks.imageretrievalnet import init_network, extract_vectors from utils.config import cfg from utils.updateObs import * import numpy as np import cv2 import json import os, base64, stat, shutil import pdb import socket sys.path.append('RAFT') sys.path.append('RAFT/core') sys.path.append('RAFT/core/utils') from RAFT.analysis_video import * class update: def __init__(self): self.net, self.transform, self.ms = createNet() self.updateMonitor = Moniting() def ImageProcess(self): dicts = {} for root, dirs, files in os.walk(self.img_dir): if len(dirs) == 0: for file in files: name = file.split('.')[0].split('_')[-1] if not name in dicts: dicts[name] = [os.sep.join([root, file])] else: dicts[name] = dicts[name] + [os.sep.join([root, file])] return dicts def updateDataCenter(self): for name in os.listdir(cfg.IMG_DIR_TOTAL): img = cv2.imread(os.sep.join([cfg.IMG_DIR_TOTAL, name])) for an in cfg.ANGLES: image = rotate_bound(img, an) cv2.imwrite(os.sep.join([cfg.IMG_DIR_TOTAL, str(an)+'_'+name]), image) self.updateMonitor.update(self.net, self.transform, self.ms) for name in os.listdir(cfg.IMG_DIR_TOTAL): os.remove(os.sep.join([cfg.IMG_DIR_TOTAL, name])) def disposaldata(self): with open(cfg.SAMPLE, 'r', encoding='utf-8') as jsonpath: loadDict = json.load(jsonpath) allsample = set(loadDict['monitor']) for imgname in os.listdir(cfg.TEST_IMG_DIR): imgbarcode = imgname.split('.')[0].split('_')[-1] if not os.path.isdir(cfg.DATA_POOLING): os.mkdir(cfg.DATA_POOLING) if not imgbarcode in allsample: # shutil.move( # os.sep.join([cfg.TEST_IMG_DIR, imgname]), # os.sep.join([cfg.DATA_POOLING, imgname])) os.remove(os.sep.join([cfg.TEST_IMG_DIR, imgname])) else: shutil.move( os.sep.join([cfg.TEST_IMG_DIR, imgname]), os.sep.join([cfg.SAMPLEDIR, imgname])) for vname in os.listdir(cfg.VIDEOPATH): os.remove(os.sep.join([cfg.VIDEOPATH, vname])) if __name__ == '__main__': Update = update() Update.disposaldata() #Update.updateDataCenter()