SHARE
TWEET

Untitled

a guest May 19th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # import the necessary packages
  2. from tkinter import *
  3. import tkinter as tk
  4. from PIL import Image
  5. from PIL import ImageTk
  6. from tkinter import filedialog
  7. import cv2
  8.  
  9. def select_image1():
  10.     # grab a reference to the image panels
  11.     global panelA
  12.  
  13.     # open a file chooser dialog and allow the user to select an input
  14.     # image
  15.     path = filedialog.askopenfilename()
  16.  
  17.     # ensure a file path was selected
  18.     if len(path) > 0:
  19.         # load the image from disk, convert it to grayscale, and detect
  20.         # edges in it
  21.         image = cv2.imread(path)
  22.  
  23.         # OpenCV represents images in BGR order; however PIL represents
  24.         # images in RGB order, so we need to swap the channels
  25.         image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  26.        
  27.         # convert the images to PIL format...
  28.         image = Image.fromarray(image)
  29.  
  30.  
  31.         # ...and then to ImageTk format
  32.         image = ImageTk.PhotoImage(image)
  33.  
  34.         # if the panels are None, initialize them
  35.         if panelA is None or panelB is None:
  36.             # the first panel will store our original image
  37.             panelA = tk.Label(image=image)
  38.             panelA.image = image
  39.             panelA.pack(side="left", padx=10, pady=10)
  40.  
  41.         # otherwise, update the image panels
  42.         else:
  43.             # update the pannels
  44.             panelA.configure(image=image)
  45.             panelA.image = image
  46.  
  47. def select_image2():
  48.     # grab a reference to the image panels
  49.     global panelB
  50.  
  51.     # open a file chooser dialog and allow the user to select an input
  52.     # image
  53.     path = filedialog.askopenfilename()
  54.  
  55.     # ensure a file path was selected
  56.     if len(path) > 0:
  57.         # load the image from disk, convert it to grayscale, and detect
  58.         # edges in it
  59.         image = cv2.imread(path)
  60.  
  61.         # OpenCV represents images in BGR order; however PIL represents
  62.         # images in RGB order, so we need to swap the channels
  63.         image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  64.  
  65.         # convert the images to PIL format...
  66.         image = Image.fromarray(image)
  67.  
  68.         # ...and then to ImageTk format
  69.         image = ImageTk.PhotoImage(image)
  70.  
  71.         # if the panels are None, initialize them
  72.         if panelA is None or panelB is None:
  73.             # the first panel will store our original image
  74.             panelB = tk.Label(image=image)
  75.             panelB.image = image
  76.             panelB.pack(side="right", padx=10, pady=10)
  77.  
  78.         # otherwise, update the image panels
  79.         else:
  80.             # update the pannels
  81.             panelB.configure(image=image)
  82.             panelB.image = image
  83.  
  84.  
  85. def refactor():
  86.     if(panelA is not None and panelB is not None):
  87.         #open new window with img: red channel from panelA and blue channel from panelB, green channel: 0
  88.  
  89.     else:
  90.         1
  91.         #popup to choose images
  92.  
  93. def depth_map():
  94.     if (panelA is not None and panelB is not None):
  95.         #open new window with emgu depth map
  96.     else:
  97.         # popup to choose images
  98.  
  99. # initialize the window toolkit along with the two image panels
  100. root = tk.Tk()
  101. root.title("Marciniak")
  102. root.geometry("1000x500")  # You want the size of the app to be 500x500
  103. # root.resizable(0, 0) #Don't allow resizing in the x or y direction
  104.  
  105. panelA = None
  106. panelB = None
  107.  
  108. # create a button, then when pressed, will trigger a file chooser
  109. # dialog and allow the user to select an input image; then add the
  110. # button the GUI
  111. btn4 = tk.Button(root, text="Depth Map", command=depth_map, height=3, width=15)
  112. btn4.pack(side="bottom", fill="none", expand="0", padx="10", pady="10")
  113.  
  114. btn3 = tk.Button(root, text="3D refactor", command=refactor, height=3, width=15)
  115. btn3.pack(side="bottom", fill="none", expand="0", padx="10", pady="10")
  116.  
  117. btn2 = tk.Button(root, text="Select Left Image", command=select_image1, height=3, width=15)
  118. btn2.pack(side="top", fill="none", expand="0", padx="10", pady="10")
  119.  
  120. btn = tk.Button(root, text="Select Right Image", command=select_image2, height=3, width=15)
  121. btn.pack(side="top", fill="none", expand="0", padx="4", pady="10")
  122.  
  123. # kick off the GUI
  124. slide = tk.Scale(root, from_=0, to=150, orient=tk.HORIZONTAL)
  125. slide.pack(side="bottom")
  126. root.mainloop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top