def reconstructComponent(): global panelC global predictions # global path # global size # reconstruct(predictions, size) # components = [{'label': 'and', 'confidence': 0.81399184, 'topleft': {'x': 1253, 'y': 204}, 'bottomright': {'x': 1897, 'y': 1295}}, {'label': 'and', 'confidence': 0.7143245, 'topleft': {'x': 2597, 'y': 903}, 'bottomright': {'x': 3453, 'y': 1979}},{'label':'wire', 'dir':'h', 'topleft':{'x': 545, 'y':565}, 'bottomright':{'x':1253, 'y':545}}, # {'label':'wire', 'dir':'h', 'topleft':{'x': 517, 'y':929}, 'bottomright':{'x':1253, 'y':873}},{'label':'wire', 'dir':'h', 'topleft':{'x': 1897, 'y':601}, 'bottomright':{'x':2209, 'y':593}},{'label':'wire', 'dir':'v', 'topleft':{'x': 2209, 'y':593}, 'bottomright':{'x':2317, 'y':1353}},{'label':'wire', 'dir':'h', 'topleft':{'x': 2317, 'y':1353}, 'bottomright':{'x':2597, 'y':1413}},{'label':'wire', 'dir':'h', 'topleft':{'x': 933, 'y':1769}, 'bottomright':{'x':2597, 'y':1661}},{'label':'wire', 'dir':'h', 'topleft':{'x': 3453, 'y':1301}, 'bottomright':{'x':3717, 'y':1301}}] # # components = [{'label': 'and', 'confidence': 0.79810315, 'topleft': {'x': 1485, 'y': 244}, 'bottomright': {'x': 2348, 'y': 1256}}, {'label': 'or', 'confidence': 0.76538694, 'topleft': {'x': 2912, 'y': 849}, 'bottomright': {'x': 3914, 'y': 1664}}, {'label': 'not', 'confidence': 0.73433167, 'topleft': {'x': 3917, 'y': 1143}, 'bottomright': {'x': 4128, 'y': 1360}}, # {'label':'wire', 'topleft':{'x': 521, 'y':673}, 'bottomright':{'x':1485, 'y':625}},{'label':'wire', 'topleft':{'x': 533, 'y':937}, 'bottomright':{'x':1485, 'y':857}},{'label':'wire', 'topleft':{'x': 2348, 'y':697}, 'bottomright':{'x':2529, 'y':677}},{'label':'wire', 'topleft':{'x': 2529, 'y':677}, 'bottomright':{'x':2529, 'y':1189}},{'label':'wire', 'topleft':{'x': 2529, 'y':1189}, 'bottomright':{'x':2912, 'y':1141}},{'label':'wire', 'topleft':{'x': 481, 'y':1529}, 'bottomright':{'x':2912, 'y':1353}},{'label':'wire', 'topleft':{'x': 4128, 'y':1189}, 'bottomright':{'x':4597, 'y':1169}}] # print("REconstruciton step 1") # print(predictions) components = wire_detection(predictions) # components = predictions print("print components") print(components) reconstruct(components, dimensions) # print("completed") # print(size) rimage = cv2.imread("out.jpg") # print("reconstructing") components.clear() if rimage is not None: rimage = cv2.cvtColor(rimage, cv2.COLOR_BGR2RGB) # print('read image') rimage = adjust(rimage) rimage = Image.fromarray(rimage) rimage = ImageTk.PhotoImage(rimage) if panelC is None: panelC = tkinter.Label(image=rimage) panelC.image = rimage panelC.pack(side="bottom", padx=10, pady=10) else: panelC.configure(image=rimage) panelC.image = rimage
def reconstructComponent(): global panelRe global predictions global components global reImgLabel global flag img = cv2.imread('temp.jpg') if img is None: tkinter.messagebox.showinfo( "Information", "Please select image and detect its components") else: res = messagebox.askquestion("Confirm", "Are all gates correctly detected?") print(res) if (res == 'yes'): components = wire_detection(predictions) print(components) if (predictions == [] or components == [] or predictions == None or components == None): tkinter.messagebox.showwarning( "warning", "No components to reconstruct the circuit.") else: components = reconstruct(components, dimensions) rimage = cv2.imread("out.jpg") # components.clear() if rimage is not None: rimage = cv2.cvtColor(rimage, cv2.COLOR_BGR2RGB) rimage = adjust(rimage, True) rimage = Image.fromarray(rimage) rimage = ImageTk.PhotoImage(rimage) if panelRe.image is None: # panelRe_title.pack(side="bottom", fill="both", expand="no", padx="10", pady="10") # panelRe=tkinter.Label(image=rimage, textvariable=reImgLabel, compound=tkinter.BOTTOM, font="Helvetica 12", bg='#e6f2ff') panelRe.configure(image=rimage) panelRe.image = rimage # panelRe.pack(side="bottom", padx=10, pady=10) else: panelRe.configure(image=rimage) panelRe.image = rimage tkinter.messagebox.showinfo( "Information", "Reconstructed file is saved as out.jpg") flag = 1
data_path = os.path.join(img_dir, '*g') files = glob.glob(data_path) for f1 in files: img = cv2.imread(f1) img = cv2.resize(img, (800, 400), interpolation=cv2.INTER_AREA) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) cv2.imwrite('temp.jpg', img) darr = detection(img) print(str(f1)) file_name = os.path.basename( str(f1))[0:os.path.basename(str(f1)).find('.')] cv2.imwrite("result\\app\\output\\" + str(file_name) + ".jpg", darr[0]) comp = wire_detection(darr[1]) comp = reconstruct(comp, (800, 400)) # f = open("result\\app\\components\\"+str(file_name)+".txt", 'w') # for c in comp: # f.write(str(c)+"\n") # f.close() rimage = cv2.imread("out.jpg") # fig, cx = plt.subplots(figsize=(15, 15)) # cx.imshow(rimage) cv2.imwrite("result\\app\\circuit\\" + str(file_name) + ".jpg", rimage) # wimg = cv2.imread("result/app/wires_endpoint/ob.jpg") # cv2.imwrite("result\\app\\wires_endpoints\\" + str(file_name) + ".jpg", wimg) # get_ipython().magic('reset -sf') ''' for processing single file '''