MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / exec

Method exec

flow-python/examples/application/cat_finder/shaper.py:44–89  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

42 return int(l), int(t), int(r), int(b)
43
44 def exec(self):
45 envelope = self.inp.recv()
46 if envelope is None:
47 logger.info('stream shaper finish')
48 # last frame, throw out all cropped image
49 for id in self._map:
50 self.out.send(self._map[id])
51 self._map.clear()
52 return
53
54 msg = envelope.msg
55
56 # update the BEST
57 if 'tracks' in msg:
58 for track in msg['tracks']:
59 tid = track['tid']
60 box = track['bbox']
61 if tid not in self._map:
62 self._map[tid] = envelope.repack(msg)
63
64 data = msg['data']
65 l, t, r, b = self.expand(box, data.shape[1], data.shape[0], 1.1)
66 crop = data[t:b, l:r]
67 assert crop is not None
68 quality = Quality.area(crop)
69
70 if self._mode == 'BEST':
71 tid_msg = self._map[tid].msg
72 # save best image
73 if 'quality' not in tid_msg:
74 tid_msg['quality'] = -1
75
76 old_quality = tid_msg['quality']
77 if quality > old_quality:
78 tid_msg['quality'] = quality
79 tid_msg['crop'] = crop
80
81 if 'failed_ids' in msg:
82 ids = msg['failed_ids']
83 if len(ids) > 0:
84 logger.debug(f'shaper recv failed_ids {ids}')
85
86 for id in ids:
87 if id in self._map:
88 self.out.send(self._map[id])
89 self._map.pop(id)

Callers

nothing calls this directly

Calls 7

expandMethod · 0.95
areaMethod · 0.80
popMethod · 0.80
recvMethod · 0.45
infoMethod · 0.45
sendMethod · 0.45
repackMethod · 0.45

Tested by

no test coverage detected