def test_get_specific_drawing(): qd = QuickDrawData() # get the first anvil drawing and test the values d = qd.get_drawing("anvil", 0) assert d.name == "anvil" assert d.key_id == 5355190515400704 assert d.recognized == True assert d.countrycode == "PL" assert d.timestamp == 1488368345 # 1 stroke, 2 x,y coords, 33 points assert len(d.image_data) == 1 assert len(d.image_data[0]) == 2 assert len(d.image_data[0][0]) == 33 assert len(d.image_data[0][1]) == 33 assert d.no_of_strokes == 1 assert len(d.strokes) == 1 assert len(d.strokes[0]) == 33 assert len(d.strokes[0][0]) == 2 assert isinstance(d.image, Image) assert isinstance( d.get_image(stroke_color=(10, 10, 10), stroke_width=4, bg_color=(200, 200, 200)), Image)
def pegar_desenho(Escolha="flower"): qd = QuickDrawData() #define todos o dataset disponivel arquivo_str = '' #começa uma string onde as informaçoes serão escritas if Escolha != "random": desenho = qd.get_drawing(Escolha) #desenho especifico else: desenho = qd.get_drawing(random.choice( qd.drawing_names)) #desenho aleatorio desenho.image.save("Desenho.png") data_array = desenho.image_data #data bruto print(data_array) print(len(data_array)) #number of strokes arquivo_str += "{} ".format(len(data_array)) for stroke in desenho.strokes: #tamanho do stroke arquivo_str += "{} ".format(len(stroke)) print(len(stroke)) for x, y in stroke: #stroke arquivo_str += "{} {} ".format(x, y) return arquivo_str #devolve a string construida
def test_load_drawings(): qd = QuickDrawData() qd.load_drawings(["anvil", "ant"]) assert qd.loaded_drawings == ["anvil", "ant"] qd.get_drawing("angel") assert qd.loaded_drawings == ["anvil", "ant", "angel"]
def find(different_object, the_object, closer, K): # closer can be True or False. If True, it means closest. If False, it means farthest. the_point = the_dict.get(the_object) distance = [] coordinates = latent_dictionary.get(different_object) for i in range(len(coordinates[0])): xy = [coordinates[0][i], coordinates[1][i]] dist = dstnc.euclidean(the_point, xy) distance.append(dist) for M in range(K): if closer: the_distance = min(distance) elif not closer: the_distance = max(distance) for i in range(len(distance)): if distance[i] == the_distance: index = i break coordinate = [coordinates[0][index], coordinates[1][index]] for key in id_vector: if id_vector.get(key) == coordinate: the_id = key break qd = QuickDrawData() doodle = qd.get_drawing(different_object) while not doodle.key_id == the_id: doodle = qd.get_drawing(different_object) found = True if found: DEFAULT_SIZE_WHITE_CHANNEL = (1000, 1000, 1) canvas = np.ones(DEFAULT_SIZE_WHITE_CHANNEL, dtype="uint8") * 255 cv2.namedWindow('Window') my_stroke_list = doodle.image_data for N in my_stroke_list: x_list = N[0] y_list = N[1] for point in range((len(x_list) - 1)): cv2.line(canvas, (x_list[point], y_list[point]), (x_list[point + 1], y_list[point + 1]), (0, 0, 0), 2) cv2.imwrite( "./png_sketches/latent_png/" + different_object + "_" + the_object + "_" + str(closer) + "_" + str(M) + ".png", canvas) distance.pop(index) coordinates[0].pop(index) coordinates[1].pop(index) else: print("Image cannot be found.")
def test_anvil(): qd = QuickDrawData() anvil = qd.get_drawing("anvil") # anvil.image.show() trans = transforms.Compose([transforms.Resize(64), transforms.ToTensor()]) anvil_tensor = transforms.ToTensor()(anvil.image) down_sized_anvil = trans(anvil.image) plt.imshow(anvil_tensor.permute(1, 2, 0)) plt.show() plt.imshow(down_sized_anvil.permute(1, 2, 0)); plt.show()
def loadNdjson(tag, scale, pos, index=None, immutable=False): try: if tag not in Status.cache: qd = QuickDrawData(True) anvil = qd.get_drawing(tag, index) Status.cache[tag] = list(anvil.strokes) if not immutable: Status.objects[tag] = [scale, pos[0], pos[1]] if tag in Status.cache and not immutable: Status.objects[tag] = [scale, pos[0], pos[1]] except: pass
def __init__(self, datasize, classname=None, transforms=None): self.datasize = datasize self.qd = QuickDrawData(max_drawings=self.datasize) if classname is None: self.classname = self.qd.drawing_names else: self.classname = classname self.transfroms = transforms self.label_ids = self.getLabelID(self.classname, self.datasize) self.img_ids = self.getImageID(self.classname, self.datasize)
def test_unrecognized_data(): qdg = QuickDrawData(recognized=False).get_drawing_group("anvil") assert qdg.drawing_count == 1000 rec = 0 unrec = 0 for drawing in qdg.drawings: if drawing.recognized: rec += 1 else: unrec += 1 assert rec == 0 assert unrec == qdg.drawing_count
def bad_sketch(keyword: str) -> str: """ Input a noun you want a sketch of, and if Google Quickdraw finds it, it will save a random doodle of it to keyword.gif, and return the filepath. """ qd = QuickDrawData() if keyword is not None: keyword = keyword.lower() if keyword == "person": keyword = "smiley face" try: key = qd.get_drawing(keyword) filepath = "keyword.gif" key.image.save(filepath) return filepath except ValueError: return "blank.png"
def __init__(self, recognized: Optional[bool] = None, transform: Callable[[QuickDrawing], torch.Tensor] = None): self.qd = QuickDrawData() self.qd_class_names = self.qd.drawing_names # dictionary of QuickDrawDataGroups based on all possible names, loads 1000 examples from each class, but can # be changed by specifying max_drawings self.qd_DataGroups = { name: QuickDrawDataGroup(name, recognized=recognized) for name in self.qd_class_names } if transform is None: self.transform = lambda x: x else: self.transform = transform
def find_doodle(): label = request.args.get('label') index = request.args.get('index') # label이 labels.txt에 존재하는지 확인 # label에 맞는 낙서 img를 찾아서 key, img, status 보내기 try: doodle = QuickDrawData().get_drawing(label, int(index)) except: return jsonify({'success': False}) print(TEMP_DIR) filename = '%s_%s.png' % ( label, index, ) doodle.image.save(os.path.join(TEMP_DIR, filename)) return send_from_directory(TEMP_DIR, filename)
def get_array_numpy_images(): """returns labels, ndarry (shape (~, 28, 28))""" # max_drawings -- maximum number of drawings to be loaded into memory, # defaults to 1000 (3 minutes) qd = QuickDrawData(max_drawings=1000) # LIST OBJECT drawing_names = qd.drawing_names # LABELS list_of_labels = [] # just append your arrays to a Python list and convert it at the end; # the result is simpler and faster list_of_np = [] for label in drawing_names: # QuickDrawDataGroup Object qd_data_group = qd.get_drawing_group(label) # QuickDrawing Object for drawing in qd_data_group.drawings: list_of_labels.append(label) # PIL IMAGE PIL_im = drawing.image.convert('L').resize((28, 28), Image.ANTIALIAS) nump_im = np.array(PIL_im) list_of_np.append(nump_im) # convert to ndarray array_of_np = np.asarray(list_of_np) array_of_labels = np.asarray(list_of_labels) print("IMAGES SHAPE ", array_of_np.shape) print("LABELS SHAPE ", array_of_labels.shape) np.save("images-new.npy", array_of_np) np.save("labels-new.npy", array_of_labels)
def get_drawing(self, recognized=True): dirname = os.path.dirname(__file__) cache_dir = os.path.join(dirname, '.quickdrawcache') qd = QuickDrawData(max_drawings=1, cache_dir=cache_dir) group_name = random.choice(qd.drawing_names) qd.load_drawings([group_name]) drawing_data = qd.get_drawing(group_name) while drawing_data.recognized != recognized: group_name = random.choice(qd.drawing_names) qd.load_drawings([group_name]) drawing_data = qd.get_drawing(group_name) drawing_size = drawing_data.get_image().size drawing = Image.new('RGB', drawing_size, 'white') draw = ImageDraw.Draw(drawing) frame = copy.deepcopy(drawing) frames = [] for stroke in drawing_data.strokes: draw.line(stroke, 'black') frame = copy.deepcopy(drawing) frames.append(frame) return frames, drawing_data
def test_search_drawings(): qd = QuickDrawData() # test a search with no criteria returns 1000 results r = qd.search_drawings("anvil") assert len(r) == 1000 # test a recognized search r = qd.search_drawings("anvil", recognized=True) for d in r: assert d.recognized r = qd.search_drawings("anvil", recognized=False) for d in r: assert not d.recognized # test a country search r = qd.search_drawings("anvil", countrycode="US") for d in r: assert d.countrycode == "US" # pull first drawing key_id = r[0].key_id timestamp = r[0].timestamp # test key_id search r = qd.search_drawings("anvil", key_id=key_id) for d in r: assert d.key_id == key_id # test timestamp search r = qd.search_drawings("anvil", timestamp=timestamp) for d in r: assert d.timestamp == timestamp # test a compound search of recognized and country code r = qd.search_drawings("anvil", recognized=True, countrycode="US") for d in r: assert d.recognized assert d.countrycode == "US"
def draw_doodle(self, img, label, d_w0, d_h0, d_w, d_h): idx = random.randrange(0, 999) self.random_Key = idx doodle = QuickDrawData().get_drawing(label, idx) # 낙서 그릴때 dobot_coord.txt도 동시에 만든다. if self.d_strokes is None: self.d_strokes = [] # with open(self.OUTPUT_FILE, 'w') as f: for stroke in doodle.strokes: d_points = [] for i in range(0, len(stroke) - 1): x = int(d_w * stroke[i][0] / 255) + d_w0 y = int(d_h * stroke[i][1] / 255) + d_h0 pre_x = int(d_w * stroke[i + 1][0] / 255) + d_w0 pre_y = int(d_h * stroke[i + 1][1] / 255) + d_h0 cv2.line(img, (pre_x, pre_y), (x, y), (0, 0, 0), 10) d_x = int((x / self.width * 255) / 2 + 180) d_y = int((y / self.height * 255) / 2 - 80) d_points.append((d_x, d_y)) # f.write('%d %d\n' % (d_x, d_y,)) if i == len(stroke) - 2: x = int(d_w * stroke[i + 1][0] / 255) + d_w0 y = int(d_h * stroke[i + 1][1] / 255) + d_h0 d_x = int((x / self.width * 255) / 2 + 180) d_y = int((y / self.height * 255) / 2 - 80) d_points.append((d_x, d_y)) # f.write('%d %d\n' % (d_x, d_y,)) # f.write('\n') self.d_strokes.append(d_points)
def test_get_random_drawing(): qd = QuickDrawData() d = qd.get_drawing("anvil", 0) assert d.name == "anvil" assert isinstance(d.key_id, int) assert isinstance(d.recognized, bool) assert isinstance(d.timestamp, int) assert isinstance(d.countrycode, str) assert isinstance(d.image_data, list) assert len(d.image_data) == d.no_of_strokes assert isinstance(d.strokes, list) assert len(d.strokes) == d.no_of_strokes for stroke in d.strokes: for point in stroke: assert len(point) == 2 assert isinstance(d.image, Image) assert isinstance( d.get_image(stroke_color=(10, 10, 10), stroke_width=4, bg_color=(200, 200, 200)), Image)
def getTree(): qd = QuickDrawData() return qd.get_drawing("tree")
from quickdraw import QuickDrawDataGroup from quickdraw import QuickDrawData import sys import os qd = QuickDrawData() ##for drawing_num, drawing_name in enumerate(qd.drawing_names): ## if drawing_num < 86: ## continue ## print("Saving " + drawing_name + " images") ## qdg = QuickDrawDataGroup(drawing_name, max_drawings=20) ## directory_name = 'images/' + drawing_name ## if not os.path.isdir(os.path.join(os.getcwd(), directory_name)): ## os.mkdir(directory_name) ## for drawing_count, drawing in enumerate(qdg.drawings, 1): ## drawing.image.save(directory_name + "/" + drawing_name + "{:0>4d}.png".format(drawing_count)) drawing_name = "face" print("Saving " + drawing_name + " images") qdg = QuickDrawDataGroup(drawing_name, max_drawings=300) directory_name = 'images/' + drawing_name if not os.path.isdir(os.path.join(os.getcwd(), directory_name)): os.mkdir(directory_name) for drawing_count, drawing in enumerate(qdg.drawings, 1): drawing.image.save(directory_name + "/" + drawing_name + "{:0>4d}.png".format(drawing_count))
from quickdraw import QuickDrawData # open quickdraw data, but set 'just in time' to False, forcing all data to be downloaded d = QuickDrawData(jit_loading=False)
from quickdraw import QuickDrawData if __name__ == '__main__': quickdraw = QuickDrawData() print(quickdraw.drawing_names) n = 10 for i in range(n * 2): draw = quickdraw.get_drawing("bicycle") draw.image.save("datasets/trainA/train_bicycle{}.gif".format(i)) for i in range(n): draw = quickdraw.get_drawing("bicycle") draw.image.save("datasets/testA/test_bicycle{}.gif".format(i)) for i in range(n * 2): draw = quickdraw.get_drawing("campfire") draw.image.save("datasets/trainB/train_campfire{}.gif".format(i)) for i in range(n): draw = quickdraw.get_drawing("campfire") draw.image.save("datasets/testB/test_campfire{}.gif".format(i))
def __init__(self): # Load a model imported from Tensorflow. frozen_ssd_model = os.path.join(os.path.dirname(__file__), '../models', 'ssd_mobilenet_model', 'frozen_inference_graph.pb') ssd_config = os.path.join(os.path.dirname(__file__), '../models', 'ssd_mobilenet_model', 'ssd_mobilenet_v1_coco_2017_11_17.pbtxt') self.tensorflowNet = cv2.dnn.readNetFromTensorflow( frozen_ssd_model, ssd_config) # List of dictionaries containg detected objects information. self.detected_objects = [] # QuckDraw object cache_path = os.path.join(os.path.dirname(__file__), 'quickdrawcache') self.qd = QuickDrawData(recognized=True, max_drawings=1000, cache_dir=cache_path) # Label HashMap self.classNames = { 0: 'background', 1: 'person', 2: 'bicycle', 3: 'car', 4: 'motorcycle', 5: 'airplane', 6: 'bus', 7: 'train', 8: 'truck', 9: 'boat', 10: 'traffic light', 11: 'fire hydrant', 13: 'stop sign', 14: 'parking meter', 15: 'bench', 16: 'bird', 17: 'cat', 18: 'dog', 19: 'horse', 20: 'sheep', 21: 'cow', 22: 'elephant', 23: 'bear', 24: 'zebra', 25: 'giraffe', 27: 'backpack', 28: 'umbrella', 31: 'handbag', 32: 'tie', 33: 'suitcase', 34: 'frisbee', 35: 'skis', 36: 'snowboard', 37: 'sports ball', 38: 'kite', 39: 'baseball bat', 40: 'baseball glove', 41: 'skateboard', 42: 'surfboard', 43: 'tennis racket', 44: 'bottle', 46: 'wine glass', 47: 'cup', 48: 'fork', 49: 'knife', 50: 'spoon', 51: 'bowl', 52: 'banana', 53: 'apple', 54: 'sandwich', 55: 'orange', 56: 'broccoli', 57: 'carrot', 58: 'hot dog', 59: 'pizza', 60: 'donut', 61: 'cake', 62: 'chair', 63: 'couch', 64: 'potted plant', 65: 'bed', 67: 'dining table', 70: 'toilet', 72: 'tv', 73: 'laptop', 74: 'mouse', 75: 'remote', 76: 'keyboard', 77: 'cell phone', 78: 'microwave', 79: 'oven', 80: 'toaster', 81: 'sink', 82: 'refrigerator', 84: 'book', 85: 'clock', 86: 'vase', 87: 'scissors', 88: 'teddy bear', 89: 'hair drier', 90: 'toothbrush' } # Tensorflow to QuickDraw HashMap self.tensorflow_to_quickdraw_hash = { 'background': '', 'person': 'face', 'bicycle': 'bicycle', 'car': 'car', 'motorcycle': 'motorbike', 'airplane': 'airplane', 'bus': 'bus', 'train': 'train', 'truck': 'truck', 'boat': 'sailboat', 'traffic light': 'traffic light', 'fire hydrant': 'fire hydrant', 'stop sign': 'stop sign', 'parking meter': '', 'bench': 'bench', 'bird': 'bird', 'cat': 'cat', 'dog': 'dog', 'horse': 'horse', 'sheep': 'sheep', 'cow': 'cow', 'elephant': 'elephant', 'bear': 'bear', 'zebra': 'zebra', 'giraffe': 'giraffe', 'backpack': 'backpack', 'umbrella': 'umbrella', 'handbag': 'purse', 'tie': 'bowtie', 'suitcase': 'suitcase', 'frisbee': 'circle', 'skis': '', 'snowboard': '', 'sports ball': 'soccer ball', 'kite': 'scissors', 'baseball bat': 'baseball bat', 'baseball glove': '', 'skateboard': 'skateboard', 'surfboard': '', 'tennis racket': 'tennis racquet', 'bottle': 'wine bottle', 'wine glass': 'wine glass', 'cup': 'cup', 'fork': 'fork', 'knife': 'knife', 'spoon': 'spoon', 'bowl': '', 'banana': 'banana', 'apple': 'apple', 'sandwich': 'sandwich', 'orange': '', 'broccoli': 'broccoli', 'carrot': 'carrot', 'hot dog': 'hot dog', 'pizza': 'pizza', 'donut': 'donut', 'cake': 'cake', 'chair': 'chair', 'couch': 'couch', 'potted plant': 'house plant', 'bed': 'bed', 'dining table': 'table', 'toilet': 'toilet', 'tv': 'television', 'laptop': 'laptop', 'mouse': 'mouse', 'remote': 'remote control', 'keyboard': 'keyboard', 'cell phone': 'cell phone', 'microwave': 'microwave', 'oven': 'oven', 'toaster': 'toaster', 'sink': 'sink', 'refrigerator': '', 'book': 'book', 'clock': 'clock', 'vase': 'vase', 'scissors': 'scissors', 'teddy bear': 'teddy-bear', 'hair drier': '', 'toothbrush': 'toothbrush' }
def draw_objects(request): qd = QuickDrawData() objects = request.GET.get('objects') objects = objects.replace("'", "") list = objects.strip("][").split(', ') return render(request, 'polls/drawing.html', {'object': list[0]})
import streamlit as st import pandas as pd from quickdraw import QuickDrawData qd = QuickDrawData(recognized=True, jit_loading=False, max_drawings=1000) qd.load_all_drawings() drawings = qd.loaded_drawings n_strokes = [d.no_of_strokes for d in drawings] anvil = qd.get_drawing(name="dolphin") st.image(anvil.image) st.write(f"Groups loaded: {qd.drawing_names}")
from fastapi import FastAPI, Response, status from fastapi.responses import JSONResponse, RedirectResponse from pyaxidraw.axidraw import AxiDraw from pydantic import BaseModel from quickdraw import QuickDrawData import urllib from game_manager import GameManager app = FastAPI() logging.basicConfig(level=logging.DEBUG) log = logging.getLogger(__name__) axidraw_client = AxiDraw() quickdraw_client = QuickDrawData() game_manager = GameManager(axidraw_client, quickdraw_client) game_thread = None class GuessRequest(BaseModel): guess: str @app.on_event("shutdown") def shutdown_event(): log.info("shutting down") if game_thread is not None: log.debug("Joining game thread") game_thread.join() log.debug("game thread joined")
def __init__(self, root, classes, transform): self.classes = classes self.labels = torch.arange(len(classes)) self.transform = transform self.qdd = QuickDrawData(recognized=True, max_drawings=10000, cache_dir=root) self.qdd.load_drawings(classes)
from flask import Flask, render_template, request, jsonify from flask_sqlalchemy import SQLAlchemy from quickdraw import QuickDrawData from sqlalchemy import func, cast, Float, ForeignKey from sqlalchemy.dialects.postgresql import JSONB config = configparser.ConfigParser() config.read_file(open("config.ini")) z = config["general"].getfloat("confidence_z") # 1.96 => 0.975 confidence app = Flask(__name__) app.config.from_pyfile("app.cfg") app.secret_key = os.urandom(32) db = SQLAlchemy(app) qd = QuickDrawData(cache_dir=config["general"]["dataset_dir"], print_messages=False) def uuid_gen() -> str: return str(uuid.uuid4()).replace("-", "") # https://www.evanmiller.org/how-not-to-sort-by-average-rating.html def ci_lower_bound(pos, neg): n = pos + neg if n == 0: return 0 return ((pos + z**2 / 2) / n - z * ((pos * neg) / n + z**2 / 4)**0.5 / n) / (1 + z**2 / n)
def test_get_drawing_group(): qd = QuickDrawData() assert isinstance(qd.get_drawing_group("anvil"), QuickDrawDataGroup)
def main(): qgd = QuickDrawData() label_names = qgd.drawing_names total_num_labels = len(label_names) im_res = 255 batch_size = 100 label_list = ["ant", "bear", "bee", "bird", "butterfly", "cat", "cow", "crab", "crocodile", "dog"] train_iter, test_iter = load_data(label_list=label_list, batch_size=batch_size) # Training class Reshape(nn.Module): def forward(self, x): return x.view(-1,65025) net = nn.Sequential(nn.Flatten(), nn.Linear(65025, 1000), nn.ReLU(), nn.Linear(1000, 10)) def init_weights(m): if type(m) == nn.Linear: torch.nn.init.normal_(m.weight, std=0.01) net.apply(init_weights) device = torch.device("cuda:0") net.to(device) optimizer = torch.optim.SGD(net.parameters(), lr=0.5) loss = nn.CrossEntropyLoss() num_epochs = 20 for epoch in range(num_epochs): train_loss_sum = train_num_correct_preds = num_examples = 0 for i, (X, y) in enumerate(train_iter): # show_images(X.reshape(batch_size, im_res, im_res), 2, 10, [label_list[int(i.item())] for i in y]) net.train() optimizer.zero_grad() X, y = X.to(device), y.to(device) y_hat = net(X) l = loss(y_hat, y) # print(f"loss={l:.3f}", y_hat, y, X.shape, X.reshape(-1, 65025).shape) # break l.backward() optimizer.step() with torch.no_grad(): train_loss_sum += l * X.shape[0] if len(y_hat.shape) > 1 and y_hat.shape[1] > 1: y_hat = y_hat.argmax(axis=1) cmp = y_hat.type(y.dtype) == y train_num_correct_preds += float(cmp.type(y.dtype).sum()) num_examples += X.shape[0] train_loss = train_loss_sum / num_examples train_acc = train_num_correct_preds / num_examples if (i + 1) % 10 == 0: print(f"epoch {epoch + 1}, iteration {i + 1}: train_loss={train_loss:.3f}, train_acc={train_acc:.3f}") test_acc = eval_test_acc(net, test_iter, device) print(f"epoch {epoch + 1}: test_acc={test_acc:.3f}") print(f"Finished training: train_loss={train_loss:.3f}, train_acc={train_acc:.3f}")
def test_drawing_names(): qd = QuickDrawData() assert len(qd.drawing_names) == 345
def visualize_the_matrix(number_of_categories): for obj in matrix_info: row_source = obj[0] for i in range(3): column_target = (obj[1])[i] the_id = (obj[2])[i] most_similar_source_id = (obj[3])[i] # Find the most similar target sketches. qd = QuickDrawData() doodle = qd.get_drawing(column_target) while not doodle.key_id == the_id: doodle = qd.get_drawing(column_target) found = True if found: DEFAULT_SIZE_WHITE_CHANNEL = (300, 300, 1) canvas = np.ones(DEFAULT_SIZE_WHITE_CHANNEL, dtype="uint8") * 255 cv2.namedWindow('Window') my_stroke_list = doodle.image_data for N in my_stroke_list: x_list = N[0] y_list = N[1] for point in range((len(x_list) - 1)): cv2.line(canvas, (x_list[point], y_list[point]), (x_list[point + 1], y_list[point + 1]), (0, 0, 0), 2) cv2.imwrite( "./png_sketches/trial_pngs" + "source_" + row_source + "_" + str(i) + ".png", canvas) for i in range(3): column_target = (obj[1])[i] the_id = (obj[2])[i] most_similar_source_id = (obj[3])[i] # Find the most similar target sketches. qd = QuickDrawData() doodle = qd.get_drawing(row_source) while not doodle.key_id == most_similar_source_id: doodle = qd.get_drawing(row_source) found = True if found: DEFAULT_SIZE_WHITE_CHANNEL = (300, 300, 1) canvas = np.ones(DEFAULT_SIZE_WHITE_CHANNEL, dtype="uint8") * 255 cv2.namedWindow('Window') my_stroke_list = doodle.image_data for N in my_stroke_list: x_list = N[0] y_list = N[1] for point in range((len(x_list) - 1)): cv2.line(canvas, (x_list[point], y_list[point]), (x_list[point + 1], y_list[point + 1]), (0, 0, 0), 2) cv2.imwrite( "./png_sketches/trial_pngs" + "source_" + row_source + "_" + str(i) + "_sourceimage.png", canvas) excel = xlsxwriter.Workbook("./png_sketches/" + "matrix_six_with_targets" + ".xlsx") worksheet = excel.add_worksheet() worksheet.set_default_row(300) worksheet.set_column('A:ZZ', 50) row_index = -1 column_empty = True for source_categ in reference_dict.keys(): row_index += 1 column_index = -1 for ordered in range(6): column_index += 1 if ordered < 3: pic = "./png_sketches/trial_pngs" + "source_" + source_categ + "_" + str( ordered) + ".png" worksheet.insert_image(row_index + 1, column_index + 1, pic) if column_empty: worksheet.write(0, column_index + 1, ("target_similar" + str(ordered + 1))) else: pic = "./png_sketches/trial_pngs" + "source_" + source_categ + "_" + str( ordered - 3) + "_sourceimage.png" worksheet.insert_image(row_index + 1, column_index + 1, pic) if column_empty: worksheet.write(0, column_index + 1, ("source_similar_to" + str(ordered - 2))) column_empty = False worksheet.write(row_index + 1, 0, source_categ) excel.close()