Skip to content

Match

IMatch

Bases: ABC

Source code in src/officialeye/_api/template/match.py
class IMatch(ABC):

    @property
    @abstractmethod
    def template(self) -> ITemplate:
        raise NotImplementedError()

    @property
    @abstractmethod
    def keypoint(self) -> IKeypoint:
        raise NotImplementedError()

    @property
    @abstractmethod
    def keypoint_point(self) -> np.ndarray:
        raise NotImplementedError()

    @property
    @abstractmethod
    def target_point(self) -> np.ndarray:
        raise NotImplementedError()

    @abstractmethod
    def get_score(self) -> float:
        raise NotImplementedError()

    @property
    def template_point(self) -> np.ndarray:
        """Returns the coordinates of the point lying in the keypoint, in the coordinate system of the underlying template."""
        return self.keypoint_point + self.keypoint.top_left

    def __str__(self) -> str:
        return (f"Point ({self.target_point[0]}, {self.target_point[1]}) matches ({self.keypoint_point[0]}, {self.keypoint_point[1]}) "
                f"in '{self.keypoint}' of '{self.template.identifier}'.")

    def __eq__(self, o: Any) -> bool:

        if not isinstance(o, IMatch):
            return False

        if self.template != o.template:
            return False

        if self.keypoint != o.keypoint:
            return False

        return (np.array_equal(self.keypoint_point, o.keypoint_point)
                and np.array_equal(self.target_point, o.target_point))

    def __lt__(self, o: Any) -> bool:
        assert isinstance(o, Match)
        return self.get_score() < o.get_score()

    def __hash__(self):
        return hash((
            self.template.identifier,
            self.keypoint.identifier,
            np.dot(self.keypoint_point, self.keypoint_point),
            np.dot(self.target_point, self.target_point)
        ))

template_point: np.ndarray property

Returns the coordinates of the point lying in the keypoint, in the coordinate system of the underlying template.