def __next__(self): """迭代器返回imgs和imgs_info Raises: StopIteration: 如果不能满足batch_size则停止迭代 Returns: tuple(imgs,imgs_info): imgs是图像list,imgs_info则是每张图像的必需信息 """ imgs = [] imgs_info = [] for _ in range(self.step): img = self.read() if img is not None: imgs.append(img) imgs_info.append({ 'time': get_current_time(), # 使用的时间 'index': self.start_index, # 对应视频中的第几帧 'shape': img.shape, # 图像的shape (H,W,C) 'video_len':len(self) # 视频的长度 }) self.start_index += 1 else: raise StopIteration return {'imgs': imgs, 'imgs_info': imgs_info}
def ttl_exit(self): while True: closer = self.pop_closer() if not closer: break closer.close() debug_print(closer.name + " closed") utils.exit_err("process timeout at: " + utils.get_current_time(), exit_immediately=True)
def run(self): start = time.time() utils.stdout_write("process start at: " + utils.get_current_time(), flush=True) self.__ttlTimer.start() if self.cos.concurrency > 1: self.run_async() else: self.run_sync() self.cancel_timer() utils.stdout_write("run end. used {} seconds".format( '%.2f' % (time.time() - start)), flush=True)
def gen_filename(self, host='', protocol='', username='', connect_ok=False, login_ok=False): time_str = utils.get_current_time(time_format='%Y%m%d_%H%M%S', with_ms=False) m = { "host": host, "protocol": protocol, "username": username, "connect_ok": "connect_" + ("ok" if connect_ok else "err"), "login_ok": "login_" + ("ok" if login_ok else "err"), "time": time_str, } return self.cos.output_filename_format.format(**m)
def debug_print(msg, flush=True): if DEBUG_MODE: caller = getframeinfo(stack()[1][0]) print("[{2}][{0}-DEBUG]: {1}".format(caller.lineno, msg, utils.get_current_time()), flush=flush)
import unittest,time from utils.HTMLTestReportCN import HTMLTestRunner # 导入HTMLTestRunner,用于创建测试执行对象 import utils.utils as ut # 加载指定目录下的所有测试用例文件中的测试用例,测试用例的文件名必须以test开头 cases_dir = ut.CASESPATH # 指定保存测试用例文件的目录 # 加载指定目录下所有以test开头的.py文件中测试用例 # discover(path,pattern) # path,表示测试用例文件所在目录 # pattern,表示需要加载的用例文件名的格式,默认参数 cases = unittest.defaultTestLoader.discover(cases_dir,pattern='test_set_email.py') case_cout = cases.countTestCases() # 返回测试套件中的用例数量 print(f'用例总数:%d' %(case_cout)) time.sleep(2) # 获取系统当前时间,YYYY-MM-DD H-M-S t = ut.get_current_time() # 创建运行对象,执行测试 # 使用当前时间作为测试报告文件名,避免以前的报告被覆盖 # f = open(t+'.html','wb') # 以二进制写的方式打开文件 with open(ut.REPORTPATH+'/'+t+'.html','wb') as f: runner = HTMLTestRunner(stream=f,title='协同OA测试报告') runner.run(cases) file = ut.get_report(t) ut.send_mail(file)
def inputObj(self, img, obj): returnInfo = None # 过滤掉不在检测范围内的目标 if obj['cls_pred'] not in self.classes: return id = obj['id'] centre = get_centre(obj['bbox']) # 初始化第一次出现的目标 if id not in self.objDict.keys(): self.objDict[id] = { 'id': id, 'maybe_classes': { obj['cls_pred']: 1 }, 'path': [centre], 'passState': self.dotByStopLine(centre), 'number_plate': None, } return # 更新已有目标: # 1.拍照检测: # 仅检测合适拍照且没有拍照且速度方向正确的目标 number_plate = None if self.appropriatePhoto( centre) and self.objDict[id]['number_plate'] is None: # todo:拍照识别 bbox = [ int(obj['bbox'][0]), int(obj['bbox'][1]), int(obj['bbox'][2]), int(obj['bbox'][3]) ] number_plate = identify_number_plate(img, bbox=bbox) if number_plate is not None: self.objDict[id]['number_plate'] = number_plate # 2.过线检测: passState = self.dotByStopLine(centre) cls_name = max(self.objDict[id]['maybe_classes'], key=self.objDict[id]['maybe_classes'].get) lastPassState = self.objDict[id]['passState'] if passState == 1 and lastPassState == -1 and cls_name in self.classes: # 只检测由-1 到 1 的跳变 self.objDict[id]['passState'] = passState returnInfo = {'info_type': 'pass'} returnInfo['id'] = id returnInfo['start_time'] = get_current_time() returnInfo['end_time'] = get_current_time() returnInfo['passage_type'] = None returnInfo['obj_type'] = cls_name returnInfo['number_plate'] = self.objDict[id]['number_plate'] self.passCount += 1 print('ID为:' + str(id) + cls_name + '的车辆过线,计数器加一,PassCount' + str(self.passCount)) #print(returnInfo) return returnInfo # 3. 数据更新: self.objDict[id]['path'].append(centre) cls_pred = obj['cls_pred'] if cls_pred not in self.objDict[id]['maybe_classes']: self.objDict[id]['maybe_classes'][cls_pred] = 0 self.objDict[id]['maybe_classes'][cls_pred] += 1