def parse_data(self, data): instances = data[3:].split('|') for instance in instances: if len(instance) < 1: continue if instance[0] == '+': infos = instance[1:].split(';') cell = int(infos[0]) template = infos[4] type = int(infos[5]) if ',' not in infos[5] else int( infos[5].split(',')[0]) entity_id = int(infos[3]) # SWITCH if type == -1: # creature pass elif type == -2: # mob # monster_team = infos[15] if len(infos) <= 18 else infos[22] self.entities.append( Entity('Mob', cell=cell, id=entity_id, template=template, pa=infos[12], health=infos[13], pm=infos[14])) elif type == -3: # group of mob templates = list(map(int, template.split(','))) levels = list(map(int, infos[7].split(','))) entity_id = int(infos[3]) self.entities.append( Entity('GroupMob', cell=cell, id=entity_id, templates=templates, levels=levels)) elif type == -4: # NPC pass # mapa.entidades.TryAdd(id, new Npc(id, int.Parse(nombre_template), celda)) elif type == -5: # Merchants pass # mapa.entidades.TryAdd(id, new Mercantes(id, celda)) elif type == -6: # resources pass else: # players self.entities.append( Entity('Player', cell=cell, id=entity_id, name=infos[4])) elif instance[0] == '-': # player leave entity_id = int(instance[1:]) self.action = '-' self.entities.append( Entity('Player' if entity_id > 0 else 'GroupMob', cell=0, id=entity_id))
def read_head(head): scene = {} for obj in head.iter('objectdef'): obj_name = obj.attrib['name'] list_of_args = [] for entity in obj: entity_name = 'triangleset' attrs = {k: list(map(float, v.split(','))) for k, v in entity.items() if k != 'name'} if entity.tag == 'triangleset': for triangle in entity: if triangle.tag == 'triangle': vs = [[p.get('x'), p.get('y'), p.get('z')] for p in triangle.iter('vertex')] elif triangle.tag == 'trianglenext': vs = [vs[1]] + [[p.get('x'), p.get('y'), p.get('z')] for p in triangle.iter('vertex')] + [vs[2]] else: raise AttributeError("Tag doesn't match either triangle or trianglenext.") list_of_args.append({'vertices': vs, **attrs}) else: entity_name = entity.tag list_of_args.append(attrs) scene[obj_name] = Entity.create(entity_name, list_of_args, obj_name) return scene
def __init__(self,size,title): super(Demo,self).__init__(size,title) self.circle = Entity((self.screen_width/2,self.screen_height/2)) self.start_pos = None self.end_pos = None self.walls = [] self.caster = None self.ray_number = 500 self. wall_number = 9 self.noise = vnoise.Noise()
def get(url, headers=None, params=None, timeout=default_timeout): response = requests.get(url, headers=headers, params=params, timeout=timeout) code = response.status_code if code == requests.codes.ok: body = response.json() if body: return Entity.from_object(body)
def parse_fight_state( raw_data ): # GTM|-1;0;190;7;4;222;;190|-2;1|-3;1|80146042;0;534;8;5;311;;534 infos = raw_data[4:].split('|') entities = [] for info in infos: data = list( map(lambda x: int(x) if x.lstrip('-').isdigit() else x, info.split(';'))) if data[1] == 1: entities.append(Entity(id=data[0], dead=True)) elif len(data) > 5: entities.append( Entity(id=data[0], health=data[2], pa=data[3], pm=data[4], cell=data[5])) return entities
def post(url, data=None, headers=None, params=None, timeout=default_timeout): response = requests.post(url, data=data, headers=headers, params=params, timeout=timeout) code = response.status_code if code == requests.codes.ok or \ code == requests.codes.created: body = response.json() if body: return Entity.from_object(body)
def to_entity(self): return Entity.from_object({ 'contract_id': self.contract_id, 'plan_id': self.plan_id, 'license_key': self.license_key, 'customer_id': self.customer_id, 'contract_type': self.contract_type, 'contract_status': self.contract_status, 'auto_renew_status': self.auto_renew_status, 'license_start_date': self.license_start_date.__str__(), 'license_end_date': self.license_end_date.__str__(), 'last_updated_vendor': self.last_updated_vendor })
def to_entity(self): return Entity.from_object({ 'user_id': self.user_id, 'user_name': self.username, 'age': self.age })
def test_payload_is_entity_in_success_response(self): entity = Entity.from_object({'key': 'test'}) response = SuccessResponse(data=entity) assert len(response['data'].keys()) is not 0
def mockreturn(_id): return Entity.from_object({ 'id': _id, 'user_name': 'Test', 'age': 15 })
def post(self): args = user_post_parser.parse_args() new_id = user_service.create_user(name=args['user_name'], age=args['age']) return SuccessResponse(data=Entity.from_object({'id': new_id})), 201
def track(video, iou): camera = cv2.VideoCapture(video) print(camera) res, frame = camera.read() y_size = frame.shape[0] x_size = frame.shape[1] print(y_size) print(x_size) # Load CNN classification model model = load_model('model//weights.h5') # Definition of MOG2 Background Subtraction bs = cv2.createBackgroundSubtractorMOG2(detectShadows=True) history = 20 frames = 0 counter = 0 track_list = [] cv2.namedWindow("detection", cv2.WINDOW_NORMAL) while True: res, frame = camera.read() if not res: break # Train the MOG2 with first frames frame fg_mask = bs.apply(frame) if frames < history: frames += 1 continue # Expansion and denoising the original frame th = cv2.threshold(fg_mask.copy(), 244, 255, cv2.THRESH_BINARY)[1] th = cv2.erode(th, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)), iterations=2) dilated = cv2.dilate(th, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (8, 3)), iterations=2) image, contours, hier = cv2.findContours(dilated, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) track_list=[] # Check the bouding boxs for c in contours: x, y, w, h = cv2.boundingRect(c) print('area:', cv2.contourArea(c)) if cv2.contourArea(c) > 500 and cv2.contourArea(c) < 700: # Extract roi img = frame[y: y + h, x: x + w, :] rimg = cv2.resize(img, (64, 64), interpolation=cv2.INTER_CUBIC) image_data = np.array(rimg, dtype='float32') image_data /= 255. roi = np.expand_dims(image_data, axis=0) flag = model.predict(roi) print(flag) if flag[0][0] < 0.4: e = Entity(counter, (x, y, w, h), frame) track_list.append(e) # Exclude existing targets in the tracking list # if track_list: # count = 0 # num = len(track_list) # for p in track_list: # if overlap((x, y, w, h), p.windows) < iou: # count += 1 # if count == num: # track_list.append(e) # else: # track_list.append(e) # counter += 1 # Check and update goals # if track_list: # tlist = copy.copy(track_list) # for e in tlist: # x, y = e.center # if 10 < x < x_size - 10 and 10 < y < y_size - 10: # e.update(frame) # else: # track_list.remove(e) # frames += 1 cv2.imshow("detection", frame) if cv2.waitKey(110) & 0xff == 27: break camera.release()