dot_to_dot_plotter.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:Robo-Plot 作者: JackBuck 项目源码 文件源码
def _retake_photos_until_valid_mode(self, target_number_cluster, mode_is_invalid=lambda m: m is None) -> None:
        """
        Take 0 or more extra photos at the average location of the target numbers to do what we can to ensure a
        valid modal numeric value exists.

        Args:
            target_number_cluster (GlobalNumberCluster):
                The different representations of a single real life number to be recognised. This is extended to
                include all extra photos taken during this method.

            mode_is_invalid:
                A function which accepts a given mode (int) and returns true if it is invalid. By default this simply
                returns True if a unique mode does not exist.
        """
        average_location = target_number_cluster.average_dot_location_yx
        numeric_value = target_number_cluster.modal_numeric_value

        jitters = np.array([[0, 0],
                            [10, 0],
                            [0, 10],
                            [-10, 0],
                            [0, -10]])

        retry_number = -1
        while mode_is_invalid(numeric_value) and retry_number + 1 < len(jitters):
            retry_number += 1

            # Take a new photo
            print('Could not determine number at location ({0[0]:.0f},{0[1]:.0f}), current value {1}\n'
                  'Retrying...'.format(average_location, numeric_value))
            processing_job = self._take_photo_and_extract_numbers(average_location + jitters[retry_number])
            self._processing_station.join()
            new_global_numbers = processing_job.return_value

            new_global_numbers = [n for n in new_global_numbers
                                  if np.linalg.norm(
                    n.dot_location_yx_mm - average_location) < self._min_millimetres_between_distinct_spots]
            number_recognition.print_recognised_global_numbers(new_global_numbers)

            target_number_cluster.extend(new_global_numbers)

            # Try again to get the mode values
            numeric_value = _try_compute_mode([n.numeric_value for n in target_number_cluster])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号