def generate_data(self, hair_color=True): self.tbl_dataset.clear() dm = DataMatrix('example/anno.dat', 'example/out2020/', 'example/Pictures2020/', 'example/', 'example/age.txt', 20) # filenames self.quantity, self.image_list = dm.load_dataset() print(self.quantity) self.attr = [] # id self.id = [] for row in range(self.quantity): self.id.append(row + 1) # aesthetic score - attractiveness self.attr = read_file('example/scores.txt') # ethnicity self.ethnic = read_file('example/ethnicity.txt') # age self.age = read_file('example/age.txt') # haircolor if True: self.haircolor = read_file('example/haircolor.txt', dtype='string') else: self.haircolor = [] for row in range(self.quantity): img = Image.open('example/Pictures2020/' + self.image_list[row]) img = img.crop((110, 10, 156, 46)) img.save('example/tmp/tmp_' + str(row) + '.jpg') img2 = img.resize((1, 1)) img2.save('example/tmp/tmp2_' + str(row) + '.jpg') color = img2.getpixel((0, 0)) h, s, v = rgb_to_hsv(color[0], color[1], color[2]) item = f"{h*100:.0f} {s*100:.0f} {v:.0f}" if v <= 20: self.haircolor.append("black " + item) elif v > 50 and s > 0.5 and h < 0.1: self.haircolor.append("red " + item) elif 20 < v <= 60: self.haircolor.append("dark brown " + item) elif 60 < v <= 95: self.haircolor.append("light brown " + item) elif v > 95 and s > 0.20: self.haircolor.append("blond " + item) elif v > 95 and s <= 0.2: self.haircolor.append("grey " + item) # Skin color # try: # _, item = self.image_list[row].split('_TEINT_') # except: # item = self.image_list[row][-15:] # item, _ = item.split('.jpg') self.skincolor = [] for row in range(self.quantity): self.skincolor.append("1") # show the table self.show_table()