Adds a stop class to the segmentation image Args: seg_img ([type]): [description] depth_img ([type]): [description] stop_signs ([type]): [description] cam ([type]): [description] _region_size (int, optional): [description]. Default
(self, seg_img, depth_img, stop_signs, cam, _region_size=6)
| 648 | |
| 649 | |
| 650 | def _change_seg_stop(self, seg_img, depth_img, stop_signs, cam, _region_size=6): |
| 651 | """Adds a stop class to the segmentation image |
| 652 | |
| 653 | Args: |
| 654 | seg_img ([type]): [description] |
| 655 | depth_img ([type]): [description] |
| 656 | stop_signs ([type]): [description] |
| 657 | cam ([type]): [description] |
| 658 | _region_size (int, optional): [description]. Defaults to 6. |
| 659 | """ |
| 660 | for stop in stop_signs: |
| 661 | |
| 662 | _dist = self._get_distance(stop.get_transform().location) |
| 663 | |
| 664 | _region = np.abs(depth_img - _dist) |
| 665 | |
| 666 | seg_img[(_region < _region_size) & (seg_img == 12)] = 26 |
| 667 | |
| 668 | # lane markings |
| 669 | trigger = stop.trigger_volume |
| 670 | |
| 671 | _trig_loc_world = self._trig_to_world(np.array([[0], [0], [0], [1.0]]).T, stop, trigger) |
| 672 | _x = self._world_to_sensor(_trig_loc_world, self._get_sensor_position(cam))[0,0] |
| 673 | |
| 674 | if _x > 0: # stop is in front of camera |
| 675 | |
| 676 | bb = self._create_2d_bb_points(trigger, 4) |
| 677 | trig_loc_world = self._trig_to_world(bb, stop, trigger) |
| 678 | cords_x_y_z = self._world_to_sensor(trig_loc_world, self._get_sensor_position(cam), True) |
| 679 | |
| 680 | #if cords_x_y_z.size: |
| 681 | cords_x_y_z = cords_x_y_z[:3, :] |
| 682 | cords_y_minus_z_x = np.concatenate([cords_x_y_z[1, :], -cords_x_y_z[2, :], cords_x_y_z[0, :]]) |
| 683 | bbox = (self._sensor_data['calibration'] @ cords_y_minus_z_x).T |
| 684 | |
| 685 | camera_bbox = np.concatenate([bbox[:, 0] / bbox[:, 2], bbox[:, 1] / bbox[:, 2], bbox[:, 2]], axis=1) |
| 686 | |
| 687 | if np.any(camera_bbox[:,2] > 0): |
| 688 | |
| 689 | camera_bbox = np.array(camera_bbox) |
| 690 | |
| 691 | polygon = [(camera_bbox[i, 0], camera_bbox[i, 1]) for i in range(len(camera_bbox))] |
| 692 | |
| 693 | img = Image.new('L', (self._sensor_data['width'], self._sensor_data['height']), 0) |
| 694 | ImageDraw.Draw(img).polygon(polygon, outline=1, fill=1) |
| 695 | _region = np.array(img) |
| 696 | |
| 697 | #seg_img[(_region == 1)] = 27 |
| 698 | seg_img[(_region == 1) & (seg_img == 6)] = 27 |
| 699 | |
| 700 | |
| 701 | def _trig_to_world(self, bb, parent, trigger): |
nothing calls this directly
no test coverage detected