Exemplo n.º 1
0
    def _update_path_color_preview(self):
        path_image_base = np.copy(PUBGISMatch.full_map[create_slice(
            (2943, 2913), 240)])
        path_image = np.copy(PUBGISMatch.full_map[create_slice((2943, 2913),
                                                               240)])

        for start, end in zip(PATH_PREVIEW_POINTS[:-1],
                              PATH_PREVIEW_POINTS[1:]):
            plot_coordinate_line(path_image, [start], end, self.path_color(),
                                 self.thickness_spinbox.value())

        alpha = self.path_color.alpha
        blended = cv2.addWeighted(path_image_base, 1 - alpha, path_image,
                                  alpha, 0)

        self._update_view_with_image(self.path_preview_view, blended)
Exemplo n.º 2
0
def create_output_opencv(input_map, coords, output_file, full_map=False):
    if full_map:
        output_slice = slice(None)
    else:
        output_slice = create_slice(
            *find_path_bounds(input_map.shape[0], coords))
    cv2.imwrite(output_file, input_map[output_slice])
Exemplo n.º 3
0
    def __debug_minimap(self, annotated_minimap, scaled_position):
        if scaled_position is None:
            offset_coords = (0, 0)
        else:
            offset_coords = coordinate_offset(scaled_position,
                                              -self.minimap_iter.size // 2)
        matched_minimap = self.gray_map[create_slice(offset_coords,
                                                     self.minimap_iter.size)]
        matched_minimap = cv2.cvtColor(matched_minimap, cv2.COLOR_GRAY2BGR)

        cv2.imshow(
            "debug",
            np.concatenate((annotated_minimap, matched_minimap), axis=1))
        cv2.waitKey(10)
Exemplo n.º 4
0
    def _get_scaled_context(self):
        # Context defines the area that the template matching will be limited to.
        # This area gets larger each time a match is missed to account for movement processing.
        context_slice = slice(None)

        if self.last_known_position:
            max_reachable_dist = self._calculate_max_travel_distance()

            context_coords, context_size = find_path_bounds(
                self.gray_map.shape[0],
                [scale_coords(self.last_known_position, self.scale)],
                crop_border=0,
                min_size=max_reachable_dist)
            context_slice = create_slice(context_coords, context_size)

        return context_slice
Exemplo n.º 5
0
    def run(self):
        self.percent_max_update.emit(0)
        self.percent_update.emit(0)

        match = PUBGISMatch(self.minimap_iterator)

        self.minimap_update.emit(self.preview_map)

        for percent, timestamp, full_position in match.process_match():
            if percent is not None:
                self.percent_max_update.emit(100)
                self.percent_update.emit(percent)

            plot_coordinate_line(self.preview_map, self.full_positions,
                                 full_position, self.parent.path_color(),
                                 self.parent.thickness_spinbox.value())

            self.full_positions.append(full_position)
            self.timestamps.append(timestamp)

            if self.output_flags & OutputFlags.LIVE_PREVIEW:
                preview_coords, preview_size = find_path_bounds(
                    PUBGISMatch.full_map.shape[0], self.full_positions)

                preview_slice = create_slice(preview_coords, preview_size)

                alpha = self.parent.path_color.alpha
                blended = cv2.addWeighted(self.base_map_alpha[preview_slice],
                                          1 - alpha,
                                          self.preview_map[preview_slice],
                                          alpha, 0)

                self.minimap_update.emit(blended)

            if self.isInterruptionRequested():
                self.minimap_iterator.stop()

        if self.isInterruptionRequested():
            self.percent_max_update.emit(100)

        self.percent_update.emit(100)

        alpha = self.parent.path_color.alpha

        if self.output_flags & OutputFlags.FULL_MAP:
            blended = cv2.addWeighted(self.base_map_alpha, 1 - alpha,
                                      self.preview_map, alpha, 0)
            create_output_opencv(blended,
                                 self.full_positions,
                                 self.output_file,
                                 full_map=True)
        elif self.output_flags & OutputFlags.CROPPED_MAP:
            blended = cv2.addWeighted(self.base_map_alpha, 1 - alpha,
                                      self.preview_map, alpha, 0)
            create_output_opencv(blended, self.full_positions,
                                 self.output_file)

        if self.output_flags & OutputFlags.JSON:
            pre, _ = os.path.splitext(self.output_file)
            json_file = pre + ".json"
            data = create_json_data(self.full_positions, self.timestamps)
            output_json(json_file, data)
Exemplo n.º 6
0
def test_create_slice(coords, size, expected_slice):
    assert create_slice(coords, size) == expected_slice