def picture_colors(original_list, p_holds_original, mode_lecture): label = 0 last_category = 0 liste = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v"] csv_write() for i in original_list: #open picture = str(p_holds_original) + str(i) img = open_picture(picture) img = cv2.resize(img, (100, 100)) #label category = int(i[4:-6]) print(category) if category != last_category: label += 1 liste[label] else: label = label liste[label] last_category = category gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) _, thresh = cv2.threshold(gray, 0, 255, 0) thresh = reshape_thresh(thresh) data = to_list(thresh) print(data) write_data_into_csv(data, liste[label]) ## #display ## if mode_lecture == "0": ## show_picture("image", img, 0, "") ## elif mode_lecture == "1": ## show_picture("image", img, 1, "") ## elif mode_lecture == "2": ## pass print(liste[label])
def first_operation_picture(path_picture): #Resize picture to 500x500. img = cv2.resize(open_picture(path_picture), (500, 500)) #show_picture("img", img, 0, "") #We delete the ground and the roof. height, width, channel = img.shape img = img[70:height - 50, 0:width] #show_picture("picture_crop", img, 0, "") return img
def main_recognition(): #Create list of folder contains original_list = os.listdir(p_holds_original) for i in original_list: print("category :", i[4:-6], "name:", i) picture = str(p_holds_original) + str(i) img = open_picture(picture) img = cv2.resize(img, (100, 100)) take_features(img) show_picture("image", img, 0, "")
MG = cv2.ADAPTIVE_THRESH_GAUSSIAN_C T = cv2.THRESH_BINARY R = cv2.RETR_TREE P = cv2.CHAIN_APPROX_NONE for i in liste: if i[:4] == "crop" and i != "crop_section.py": print(i) img = open_picture(i) img = cv2.resize(img, (100, 100)) show_picture("img", img, 0, "") height, width, channel = img.shape img = background(img, width, height) color, dico = main_color_background(img) print(color)
##cv2.namedWindow("Tracking") ##cv2.createTrackbar("LH", "Tracking", 0, 255, nothing) ##cv2.createTrackbar("LS", "Tracking", 0, 255, nothing) ##cv2.createTrackbar("LV", "Tracking", 0, 255, nothing) ##cv2.createTrackbar("UH", "Tracking", 255, 255, nothing) ##cv2.createTrackbar("US", "Tracking", 255, 255, nothing) ##cv2.createTrackbar("UV", "Tracking", 255, 255, nothing) liste = os.listdir(wp) R = cv2.RETR_TREE P = cv2.CHAIN_APPROX_NONE position = [] for i in liste: img = open_picture(wp + i) img = cv2.resize(img, (500, 500)) height, width, channel = img.shape img = img[70:height - 50, 0:width] copy = img.copy() show_picture("img", img, 0, "") hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) #haut l_b = np.array([0, 0, 0]) u_b = np.array([75, 255, 255]) mask = cv2.inRange(hsv, l_b, u_b) blanck = blanck_picture(img)