def main():
    orig_imgs = glob.glob('photoset/cleaned/*/*.JPG')
    
    for filename in orig_imgs:
        # Find all cards in each image
        image = cv2.imread(filename)
        cards = get_white_rectangles(image)
        for card in cards:
            image, corners = card
            # For each card, detect the shape
            shape = detect_shape(image)
            print shape
actual_list = []
error_list = []

for location in all_locations:
	
	shapes = []
	distances = []

	start = time.time()
	for shape in all_locations[location]:

		image_name = all_locations[location][shape]
		image = cv2.imread(image_name)

		# start2 = time.time()
		cleaned_image, rectangle_coordinates = white_rect_finder.get_white_rectangles(image)[0]
		# elapsed2 = time.time() - start2

		# start3 = time.time()
		estimated_shape = identify_shapes.detect_shape(cleaned_image)
		# elapsed3 = time.time() - start3

		print shape, estimated_shape #, elapsed2, elapsed3

		shapes.append(shape)

		# find y-coordinates of rectangle
		low_y = (rectangle_coordinates[0][1] + rectangle_coordinates[1][1]) / 2.
		high_y = (rectangle_coordinates[2][1] + rectangle_coordinates[3][1]) / 2.

		# find pixel height
	# then find distance from present location to the shape landmark
	for shape in shape_name_to_coordinates:
		
		if shape in image_path:
		
			shape_coordinates = shape_name_to_coordinates[shape]
			present_coordinates_string = image_path[2].split(',')
			present_coordinates = np.array([float(present_coordinates_string[0]),
											float(present_coordinates_string[1])])
			distance = np.linalg.norm(shape_coordinates - present_coordinates)
			y = np.append(y,distance)
			break

	image = cv2.imread(image_name)

	rectangle_coordinates = white_rect_finder.get_white_rectangles(image, DEBUG=False)[0][1]

	# find y-coordinates of rectangle
	low_y = (rectangle_coordinates[0][1] + rectangle_coordinates[1][1]) / 2.
	high_y = (rectangle_coordinates[2][1] + rectangle_coordinates[3][1]) / 2.

	# find pixel height
	pixels = high_y - low_y
	x = np.append(x, pixels)

	# print pixels, distance, shape, image_path[-1]
	image_dict["pixels"], image_dict["distance"], image_dict["shape"], image_dict["filename"] = \
			pixels, distance, shape, image_path[-1]

	pixels_to_distance.append(image_dict)
# A short test to verify the shapes are correctly identified

import os
import cv2

from white_rect_finder import get_white_rectangles
from identify_shapes import detect_shape

base_dir = "photoset_labeled/cleaned"
correctly_classified = 0
incorrectly_classified = 0

for dir in os.listdir(base_dir):
    shape_dir = base_dir + "/" + dir
    for shape_folder in os.listdir(shape_dir):
        photo_dir = shape_dir + "/" + shape_folder
        for photo in os.listdir(photo_dir):
            image = cv2.imread(photo_dir + "/" + photo)
            cards = get_white_rectangles(image)
            for card in cards:
                image, corners = card
                shape = detect_shape(image)
                if shape == shape_folder:
                    correctly_classified += 1
                else:
                    shape = detect_shape(image, show_shape=True)
                    incorrectly_classified +=1
                    print "Incorrect:",shape,shape_folder,photo_dir,photo

print "Correct: ", correctly_classified
print "Incorrect: ", incorrectly_classified