def test_scene_tl(self): tl_images = { "scene_tl_test": { "x": 338, "y": 200, "state": "red" }, "tl_green_299_287_background": { "x": 287, "y": 299, "state": "green" }, "tl_red_199_137_background": { "x": 137, "y": 199, "state": "red" }, "tl_yellow_199_237_background": { "x": 237, "y": 199, "state": "yellow" } } radii_range = range(10, 30, 1) for tl in tl_images: tl_data = tl_images[tl] test_image = cv2.imread("input_images/test_images/" "{}.png".format(tl)) coords, state = ps2.traffic_light_detection( test_image, radii_range) check_result(tl, coords, (tl_data["x"], tl_data["y"]), 5) self.assertEqual(state, tl_data["state"], "Wrong state value.")
def part_1_scenes_test(): input_images = [ 'scene_tl_test', 'tl_green_299_287_background', 'tl_red_199_137_background', 'tl_yellow_199_237_background', ] output_labels = [ 'scene_tl_test_out', 'tl_green_299_287_background_out', 'tl_red_199_137_background_out', 'tl_yellow_199_237_background_out' ] # Define a radii range, you may define a smaller range based on your # observations. radii_range = range(10, 30, 1) for img_in, label in zip(input_images, output_labels): tl = cv2.imread("input_images/test_images/{}.png".format(img_in)) coords, state = ps2.traffic_light_detection(tl, radii_range) print 'Cords for image name: {}.png are {} , state is: {}'.format( img_in, coords, state) img_out = draw_tl_center(tl, coords, state) cv2.imwrite("output/{}.png".format(label), img_out)
def test_traffic_light(self): image_name = "scene_all_signs.png" test_image = cv2.imread("input_images/test_images/" + image_name) radii_range = range(10, 30, 1) coords, color = ps2.traffic_light_detection(test_image, radii_range) cv2.circle(test_image, coords, 5, (0, 255, 0), 2) cv2.imshow('All_signs', test_image) cv2.waitKey(0) check_result(image_name, coords, (116, 340), 5)
def part_1(): input_images = ['simple_tl', 'scene_tl_1', 'scene_tl_2', 'scene_tl_3'] output_labels = ['ps2-1-a-1', 'ps2-1-a-2', 'ps2-1-a-3', 'ps2-1-a-4'] # input_images = ['scene_tl_3'] # output_labels = ['ps2-1-a-4'] # Define a radii range, you may define a smaller range based on your # observations. radii_range = range(10, 30, 1) for img_in, label in zip(input_images, output_labels): tl = cv2.imread("input_images/{}.png".format(img_in)) ps2.traffic_light_detection(tl, radii_range) coords, state = ps2.traffic_light_detection(tl, radii_range) img_out = draw_tl_center(tl, coords, state) cv2.imwrite("output/{}.png".format(label), img_out)
def test_output(self): test_image = cv2.imread("input_images/test_images/simple_tl_test.png") radii_range = range(10, 30, 1) result = ps2.traffic_light_detection(test_image, radii_range) self.assertTrue(result is not None, "Output is NoneType.") self.assertEqual(2, len(result), "Output should be a tuple of 2 " "elements.") coords = result[0] state = result[1] is_tuple = isinstance(coords, (tuple)) self.assertTrue(is_tuple, "Coordinates output is not a tuple.") is_string = isinstance(state, str) self.assertTrue(is_string, "Traffic light state is not a string.") if state not in ["red", "yellow", "green"]: raise (ValueError, "Traffic light state is not valid.")
def part_1(): input_images = ['simple_tl', 'scene_tl_1', 'scene_tl_2', 'scene_tl_3'] #input_images = ['tl_green_299_287_background', 'tl_green_299_287_blank', 'tl_red_199_137_blank', 'tl_red_199_137_background', 'tl_yellow_199_237_background', 'tl_yellow_199_237_blank'] output_labels = ['ps2-1-a-1', 'ps2-1-a-2', 'ps2-1-a-3', 'ps2-1-a-4'] # Define a radii range, you may define a smaller range based on your # observations. radii_range = range(10, 35, 1) #gree, green, yellow, red for img_in, label in zip(input_images, output_labels): tl = cv2.imread("input_images/{}.png".format(img_in)) coords, state = ps2.traffic_light_detection(tl, radii_range) print coords, state img_out = draw_tl_center(tl, coords, state) cv2.imwrite("output/{}.png".format(label), img_out)