import glob
import os 
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt

# load templates
def load_templates():
	folder = 'shapes'
	my_path = glob.glob(folder)
	for template in my_path:
		templates = []
		for filename in os.listdir(folder):
			# read template
			template = plt.imread(os.path.join(folder,filename))
			if template is not None:
				# convert color to gray
				template = cv.cvtColor(template, cv.COLOR_BGR2GRAY)
				# save template with its name
				template = [template, filename]
				templates.append(template)
	return(templates)
	
templates = load_templates()
for template_values in templates:
	template = template_values[0]
	template_name = template_values[1]
	
	# resize template
	template = cv.resize(template, (50, 50))
	
	h, w = template.shape
	for i in range(0, h):
		for j in range(0, w):
			if template[i][j] > 100:
				template[i][j] = 255
			else:
				template[i][j] = 0
	
	# save created template
	plt.imsave(template_name, template, cmap='gray')
	
	# show template
	plt.imshow(template, cmap='gray')
	plt.show()
	
	
	
