LAB4でARMarkerの「向き」をクラスに保存するとどうなるのかわからない

「向き」を検出するコードをクラスの外に関数で作成すると、ARMarkerの向きを知りたいときに、毎回関数を呼び出す必要があります。

しかし、クラスの中に入れるとARMarkerを読み込むたびに自動で、「向き」を保存しておいてくれるようになります。そうなると「向き」を知りたいときにわざわざ関数を記載しなくてもクラスで「向き」を呼び出せば済みます!と記載されています。

サンプルコード

class ARMarker:
    
    def __init__(self, marker_id, marker_corners):
        # TODO: Copy implementation of __id and __corners from your previous ARMarker class
        self.__id = marker_id
        self.__corners = marker_corners
              
        # TODO: Set the __orientation field based on the corners
        if self.__corners[0][1] > self.__corners[2][1]:
            if self.__corners[0][0] > self.__corners[2][0]:
                self.__orientation = Orientation.DOWN
            else:
                self.__orientation = Orientation.RIGHT
        else:
            if self.__corners[0][0] > self.__corners[2][0]:
                self.__orientation = Orientation.LEFT
            else:
                self.__orientation = Orientation.UP
            
    def get_id(self):
        # TODO: Copy implementation from your previous ARMarker class
        return self.__id
    
    def get_corners(self):
        # TODO: Copy implementation from your previous ARMarker class
        return self.__corners
    
    def get_orientation(self):
        # TODO: Return the orientation
        return self.__orientation
    
    def __str__(self):
        # TODO: Update __str__ to include the ID, corners, and orientation
        return f"ID: {self.__id}\nCorners: {self.__corners}\nOrientation: {self.__orientation}"

サンプルコードの実行結果

Orientation:の後に、「向き」が表示され、「向き」がARMarkerごとに保存されていることが分かります。