def __init__(self):
        """ Initialize the street sign reocgnizer """
        rospy.init_node('street_sign_recognizer')
        self.cv_image = None                        # the latest image from the camera
        # self.grid_cell = None
        self.binary_image = None
        self.image_info_window = None
        self.bridge = CvBridge()                    # used to convert ROS messages to OpenCV
        # self.hsv_lb = np.array([23, 175, 133])           # hsv lower bound
        # self.hsv_ub = np.array([40, 255, 255])     # hsv upper bound
        self.hsv_lb = np.array([0, 0, 0])           # hsv lower bound
        self.hsv_ub = np.array([255, 255, 255])     # hsv upper bound
        # self.grid_cell_w = 64*3
        # self.grid_cell_h = 48*3
        self.TM = TemplateMatcher() 
        self.grid = GridImage()

        cv2.namedWindow('video_window')
        cv2.setMouseCallback('video_window', self.process_mouse_event)
        cv2.namedWindow('threshold_image')
        
        cv2.createTrackbar('H lb', 'threshold_image', 0, 255, self.set_h_lb)
        cv2.createTrackbar('S lb', 'threshold_image', 0, 255, self.set_s_lb)
        cv2.createTrackbar('V lb', 'threshold_image', 0, 255, self.set_v_lb)
        
        cv2.createTrackbar('H ub', 'threshold_image', 0, 255, self.set_h_ub)
        cv2.createTrackbar('S ub', 'threshold_image', 0, 255, self.set_s_ub)
        cv2.createTrackbar('V ub', 'threshold_image', 0, 255, self.set_v_ub)
        
        rospy.Subscriber("/camera/image_raw", Image, self.process_image)
    def __init__(self):
        """ Initialize the street sign reocgnizer """
        rospy.init_node('street_sign_recognizer')
        self.cv_image = None  # the latest image from the camera
        self.cv_image_res = None
        self.grayscale_sign = None
        self.bridge = CvBridge()  # used to convert ROS messages to OpenCV
        cv2.namedWindow('video_window')
        cv2.namedWindow('grayscale_sign_window')
        rospy.Subscriber("/camera/image_raw", Image, self.process_image)

        cv2.namedWindow('threshold_image')
        self.hsv_lb = np.array([30, 75, 75])  # hsv lower bound
        cv2.createTrackbar('H lb', 'threshold_image', 0, 360, self.set_h_lb)
        cv2.createTrackbar('S lb', 'threshold_image', 0, 100, self.set_s_lb)
        cv2.createTrackbar('V lb', 'threshold_image', 0, 100, self.set_v_lb)
        self.hsv_ub = np.array([90, 100, 100])  # hsv upper bound
        cv2.createTrackbar('H ub', 'threshold_image', 0, 360, self.set_h_ub)
        cv2.createTrackbar('S ub', 'threshold_image', 0, 100, self.set_s_ub)
        cv2.createTrackbar('V ub', 'threshold_image', 0, 100, self.set_v_ub)

        self.tm = TemplateMatcher({
            "left":
            '/home/hdavidzhu/catkin_ws/src/sign_follower/images/leftturn_box_small.png',
            "right":
            '/home/hdavidzhu/catkin_ws/src/sign_follower/images/rightturn_box_small.png',
            "uturn":
            '/home/hdavidzhu/catkin_ws/src/sign_follower/images/uturn_box_small.png'
        })
    def __init__(self):
        """Initialize the street sign recognizer """
        rospy.init_node('street_sign_recognizer')
        rospy.Subscriber("sign_follower/cropped_sign", Image, self.recognize_sign)

        images = {
            "left": '../images/leftturn_box_small.png',
            "right": '../images/rightturn_box_small.png',
            "uturn": '../images/uturn_box_small.png'
            }
        self.tm = TemplateMatcher(images)
Exemple #4
0
    def __init__(self):
        #init ROS node
        rospy.init_node('street_sign_recognizer')

        self.bridge = CvBridge()  # used to convert ROS messages to OpenCV

        self.image = None  # the latest image from the camera
        self.cv_image = None  # gaussian blurred image
        self.hsv_image = None  # HSV form of image
        self.binary_image = None  # Binary form of image
        self.grid_cell = None  # portion of an image

        self.density = 0  # amount of white in a grid cell
        self.threshold = .001  # amount of white needed in a grid cell to be part of sign

        #the thresholds to find the yellow color of the sign
        self.hsv_lb = np.array([17, 161, 160])  # hsv lower bound
        self.hsv_ub = np.array([75, 255, 255])  # hsv upper bound

        # the various windows for visualization
        cv2.namedWindow('HSV_window')
        cv2.namedWindow('Binary_window')
        cv2.namedWindow('RGB_window')

        #set of template images for the Template Matcher
        images = {
            "left": '../images/leftturn_box_small.png',
            "right": '../images/rightturn_box_small.png',
            "uturn": '../images/uturn_box_small.png'
        }

        #variables for Template Matcher
        self.matcher = TemplateMatcher(
            images)  # initialize Template Matcher class
        self.matched_threshold = 40  # threshold to determine which sign the input is
        self.total_confidence = {
            'uturn': 0.0,
            'left': 0.0,
            'right': 0.0
        }  # dictionary that holds cumulative confidence of each sign
        self.recognized = False  #boolean to ensure only one run of the recognition

        #init ROS Subscriber to camera image
        rospy.Subscriber("/camera/image_raw", Image, self.process_image)
    def __init__(self):
        """ Initialize the street sign reocgnizer """
        rospy.init_node('street_sign_recognizer')
        self.cv_image = None  # the latest image from the camera
        self.hsv_image = None
        self.res_image = None
        self.mask = None
        self.cropped_sign = None
        self.bridge = CvBridge()  # used to convert ROS messages to OpenCV
        cv2.namedWindow('video_window')
        rospy.Subscriber("/camera/image_raw", Image, self.process_image)
        self.signpub = rospy.Publisher('/predicted_sign',
                                       String,
                                       queue_size=10)
        self.prediction = ""

        #sets up slider bars for hue isolation
        #cv2.namedWindow('threshold_image')
        # current values work well for uturn and right, but poorly for left
        # values for left (20, 166, 139) increase error for uturn and right
        self.hsv_lb = np.array(
            [25, 202, 186]
        )  # hsv lower bound 20, 166, 139 25, 202, 186 26, 214, 167 [15, 225, 139
        # cv2.createTrackbar('H lb', 'threshold_image', 0, 255, self.set_h_lb)
        # cv2.createTrackbar('S lb', 'threshold_image', 0, 255, self.set_s_lb)
        # cv2.createTrackbar('V lb', 'threshold_image', 0, 255, self.set_v_lb)
        self.hsv_ub = np.array(
            [204, 255, 255])  # hsv upper bound 204, 255, 255 204, 255, 230
        # cv2.createTrackbar('H ub', 'threshold_image', 0, 255, self.set_h_ub)
        # cv2.createTrackbar('S ub', 'threshold_image', 0, 255, self.set_s_ub)
        # cv2.createTrackbar('V ub', 'threshold_image', 0, 255, self.set_v_ub)

        # initialize template_matcher
        images = {
            "left": '../images/leftturn_box_small.png',
            "right": '../images/rightturn_box_small.png',
            "uturn": '../images/uturn_box_small.png'
        }

        self.tm = TemplateMatcher(images)
Exemple #6
0
                cv2.waitKey(5)

                # cv2.imshow('image_info', self.image_info_window)
                # cv2.waitKey(5)

            r.sleep()


if __name__ == '__main__':
    images = {
        "left": '../images/leftturn_box_small.png',
        "right": '../images/rightturn_box_small.png',
        "uturn": '../images/uturn_box_small.png'
    }

    scenes = [
        "../images/uturn_scene.jpg", "../images/leftturn_scene.jpg",
        "../images/rightturn_scene.jpg"
    ]

    node = StreetSignRecognizer()
    node.run()

    tm = TemplateMatcher(images)

    for filename in scenes:
        scene_img = cv2.imread(filename, 0)
        pred = tm.predict(scene_img)
        print filename.split('/')[-1]
        print pred
Exemple #7
0
    def __init__(self, image_topic, sleep_topic):
        """ Initialize the street sign reocgnizer """
        rospy.init_node('street_sign_recognizer')
        self.cv_image = None                        # the latest image from the camera
        self.bridge = CvBridge()                    # used to convert ROS messages to OpenCV
        self.saveCounter = 0                        # how many images we've saved to disk


        print "Loading TemplateMatcher"
        self.template_matcher = TemplateMatcher(self.template_images)

        self.pub = rospy.Publisher('predicted_sign', String, queue_size=1)
        cv2.namedWindow('video_window')

        self.sleeping = False

        self.running_predictions = {"lturn": 0, "rturn": 0, "uturn": 0}

        self.sign_pub_mappings = {
            "uturn": 1,
            "lturn": 2,
            "rturn": 3
        }

        # 'use' parameters for quick changes in node functionality
        self.use_slider = False
        self.use_mouse_hover = False
        self.use_saver = False
        self.use_predict = True

        # threshold by which the running confidence summation must achieve to publish a predicted_sign
        # hand tuned
        self.decision_threshold = 35

        # # # # # # # # # # # # #
        # color params, in HSV  #
        # # # # # # # # # # # # #

        self.COLOR = "yellow"                       # which default color we binarize based on
        self.color_bounds = {}

        # tuned from the green hand ball
        self.color_bounds["green"] = (
              np.array([60,76,2])                   # min
            , np.array([80,255,255])                # max
        )
        # tuned from yellow lturn sign
        self.color_bounds["yellow"] = (
              np.array([23,175,130])                # min
            , np.array([32,255,255])                # max
        )

        if self.use_mouse_hover:
            # when mouse hovers over video window
            cv2.setMouseCallback('video_window', self.process_mouse_event)

        if self.use_slider:
            cv2.namedWindow('threshold_image')
            self.hsv_lb = np.array([0, 0, 0])
            cv2.createTrackbar('H lb', 'threshold_image', 0, 255, self.set_h_lb)
            cv2.createTrackbar('S lb', 'threshold_image', 0, 255, self.set_s_lb)
            cv2.createTrackbar('V lb', 'threshold_image', 0, 255, self.set_v_lb)
            self.hsv_ub = np.array([255, 255, 255])
            cv2.createTrackbar('H ub', 'threshold_image', 0, 255, self.set_h_ub)
            cv2.createTrackbar('S ub', 'threshold_image', 0, 255, self.set_s_ub)
            cv2.createTrackbar('V ub', 'threshold_image', 0, 255, self.set_v_ub)

        rospy.Subscriber(image_topic, Image, self.process_image)
        rospy.Subscriber(sleep_topic, Bool, self.process_sleep)
    def __init__(self):
        """ Initialize the street sign reocgnizer """
        rospy.init_node('street_sign_recognizer')

        # Create TemplateMatcher object with template images
        self.template_matcher = TemplateMatcher({
            "left":
            '../images/leftturn_box_small.png',
            "right":
            '../images/rightturn_box_small.png',
            "uturn":
            '../images/uturn_box_small.png'
        })

        self.bgr_image = None  # the latest image from the camera
        self.hsv_image = None
        self.filt_image = None
        self.cropped_sign_grayscale = None

        self.bridge = CvBridge()  # used to convert ROS messages to OpenCV

        # Create windows to view video streams
        cv2.namedWindow('video_window')
        cv2.namedWindow('filt_window')
        cv2.namedWindow('cropped_grayscale_window')
        cv2.namedWindow('img_T_window')

        # Create sliders to control image color filtering
        cv2.namedWindow('threshold_image')
        self.h_lower_bound = 25
        self.h_upper_bound = 38
        self.s_lower_bound = 199
        self.s_upper_bound = 255
        self.v_lower_bound = 203
        self.v_upper_bound = 237
        self.blur_amount = 3
        cv2.createTrackbar('H lower bound', 'threshold_image', 0, 255,
                           self.set_h_lower_bound)
        cv2.createTrackbar('H upper bound', 'threshold_image', 0, 255,
                           self.set_h_upper_bound)
        cv2.createTrackbar('S lower bound', 'threshold_image', 0, 255,
                           self.set_s_lower_bound)
        cv2.createTrackbar('S upper bound', 'threshold_image', 0, 255,
                           self.set_s_upper_bound)
        cv2.createTrackbar('V lower bound', 'threshold_image', 0, 255,
                           self.set_v_lower_bound)
        cv2.createTrackbar('V upper bound', 'threshold_image', 0, 255,
                           self.set_v_upper_bound)
        cv2.createTrackbar('Blur amount', 'threshold_image', 0, 20,
                           self.set_blur_amount)
        cv2.setTrackbarPos('H lower bound', 'threshold_image',
                           self.h_lower_bound)
        cv2.setTrackbarPos('H upper bound', 'threshold_image',
                           self.h_upper_bound)
        cv2.setTrackbarPos('S lower bound', 'threshold_image',
                           self.s_lower_bound)
        cv2.setTrackbarPos('S upper bound', 'threshold_image',
                           self.s_upper_bound)
        cv2.setTrackbarPos('V lower bound', 'threshold_image',
                           self.v_lower_bound)
        cv2.setTrackbarPos('V upper bound', 'threshold_image',
                           self.v_upper_bound)
        cv2.setTrackbarPos('Blur amount', 'threshold_image', self.blur_amount)

        # Subscribe to ROS image stream
        rospy.Subscriber("/camera/image_raw", Image, self.process_image)