예제 #1
0
 def __init__(self,
              cam_pixel_to_point):  # type: (CamPixelToPointServer) -> None
     State.__init__(self,
                    outcomes=['ok', 'match', 'err'],
                    input_keys=['green_shape'])
     self.feature_detector = FeatureDetector()
     self.cam_pixel_to_point = cam_pixel_to_point
예제 #2
0
class SearchForShapeInSquareState(State):
    def __init__(self, square, cam_pixel_to_point
                 ):  # type: (ParkingSquare, CamPixelToPointServer) -> None
        State.__init__(self, outcomes=['ok'], input_keys=['green_shape'])
        self.feature_detector = FeatureDetector()
        self.cam_pixel_to_point = cam_pixel_to_point
        self.square = square

    def execute(self, ud):
        features = self.feature_detector.get_features()
        features = [f for f in features if f.colour == 'red']
        features = filter_by_distance(features, 1., self.cam_pixel_to_point)
        depths = feature_depths(features, self.cam_pixel_to_point)
        feature = next(
            (f for i, f in enumerate(features) if depths[i] == min(depths)),
            None)

        if feature is None:
            return 'ok'

        print(feature.shape)

        if feature.shape == ud.green_shape:
            notify_match()
            self.square.set_contains_shape()
            return 'ok'

        self.square.set_contains_wrong_shape()
        return 'ok'
예제 #3
0
class Location3State(State):
    def __init__(self,
                 cam_pixel_to_point):  # type: (CamPixelToPointServer) -> None
        State.__init__(self,
                       outcomes=['ok', 'match', 'err'],
                       input_keys=['green_shape'])
        self.feature_detector = FeatureDetector()
        self.cam_pixel_to_point = cam_pixel_to_point

    def execute(self, ud):
        try:
            features = self.feature_detector.get_features()
            features = [f for f in features if f.colour == 'red']
            features = filter_by_distance(features, 1.,
                                          self.cam_pixel_to_point)
            depths = feature_depths(features, self.cam_pixel_to_point)
            feature = next(
                (f
                 for i, f in enumerate(features) if depths[i] == min(depths)),
                None)

            if feature is None:
                return 'err'

            print(feature.shape)

            if feature.shape == ud.green_shape:
                notify_location3_match()
                return 'match'

            return 'ok'
        except Exception, e:
            print(e)
            return 'err'
예제 #4
0
class Location2State(State):
    def __init__(self):
        State.__init__(self, outcomes=['ok', 'err'], output_keys=['green_shape'])
        self.feature_detector = FeatureDetector()

    def execute(self, ud):
        try:
            features = self.feature_detector.get_features()
            green_shape = next(f.shape for f in features if f.colour == 'green')
            ud.green_shape = green_shape
            notify_count(len(features))
            print(green_shape)
            return 'ok'
        except Exception, e:
            print(e)
            ud.green_shape = None
            return 'err'
예제 #5
0
class Location1State(State):
    def __init__(self,
                 cam_pixel_to_point):  # type: (CamPixelToPointServer) -> None
        State.__init__(self, outcomes=['ok', 'err'])
        self.feature_detector = FeatureDetector()
        self.cam_pixel_to_point = cam_pixel_to_point

    def execute(self, ud):
        try:
            features = self.feature_detector.get_features()
            features = [f for f in features if f.colour == 'red']
            features = filter_by_distance(
                features,
                max_distance=1.,
                cam_pixel_to_point=self.cam_pixel_to_point)
            notify_count(min(3, len(features)))
            return 'ok'
        except Exception, e:
            print(e)
            return 'err'
예제 #6
0
 def __init__(self, square, cam_pixel_to_point
              ):  # type: (ParkingSquare, CamPixelToPointServer) -> None
     State.__init__(self, outcomes=['ok'], input_keys=['green_shape'])
     self.feature_detector = FeatureDetector()
     self.cam_pixel_to_point = cam_pixel_to_point
     self.square = square
예제 #7
0
 def __init__(self):
     State.__init__(self,
                    outcomes=['ok', 'err'],
                    output_keys=['green_shape'])
     self.feature_detector = FeatureDetector()