| 45 | return val |
| 46 | |
| 47 | def exec(self): |
| 48 | envelope = self.inp.recv() |
| 49 | if envelope is None: |
| 50 | return |
| 51 | |
| 52 | msg = envelope.msg |
| 53 | msg['items'] = [] |
| 54 | |
| 55 | process = envelope.partial_id % self._interval == 0 |
| 56 | if process: |
| 57 | data = msg['data'] |
| 58 | outputs = self._predictor.inference(data) |
| 59 | # skip if detect nothing |
| 60 | if outputs is not None: |
| 61 | items = [] |
| 62 | |
| 63 | for i in range(outputs.shape[0]): |
| 64 | output = outputs[i] |
| 65 | # if neither cat nor dog, skip |
| 66 | if round(output[6]) != 15 and round(output[6]) != 16: |
| 67 | continue |
| 68 | |
| 69 | item = dict() |
| 70 | item["bbox"] = output[0:4] |
| 71 | item["cls"] = round(output[6]) |
| 72 | item["score"] = output[4] * output[5] |
| 73 | items.append(item) |
| 74 | msg['items'] = items |
| 75 | |
| 76 | # import cv2 |
| 77 | # x = self._predictor.visual(outputs, data) |
| 78 | # name = 'frame{0:07d}.jpg'.format(envelope.partial_id) |
| 79 | # cv2.imwrite(name, x) |
| 80 | |
| 81 | if self._visualize == 1: |
| 82 | msg['data'] = self._predictor.visual(outputs, data) |
| 83 | msg['process'] = process |
| 84 | self.out.send(envelope) |