I'm trying to do the following, but I can not find the right code.
GUI1:
- 2 buttons, button 1 = load terrain, button 2 = find craters
- if you press button 1 it will open file explorer and you can choose an image
- the image you choose will show up into the GUI
OpenCV:
- it will read the image you chose
- it will find all the circles in that image
- it will show into the python console
GUI2:
- if you press button 2 it will open the (OpenCV) image into the GUI
Right now I can't figure out how to open the (OpenCV) image into the GUI. It only opens into the python Console.
My code is down below
import cv2
import numpy as np
from matplotlib import pyplot as plt
from tkinter import *
from PIL import ImageTk,Image
from tkinter import filedialog
from tkinter import ttk
import tkinter as tk
root = Tk()
root.title("Armstrong Autonomous Moon Landing System")
root.geometry("1100x600")
root.iconbitmap('C:/Users/brett/')
mb = Menubutton(root, text="Armstrong Autonomouse Moon Lander System")
mb.menu = Menu(mb)
mb["menu"] = mb.menu
########## ALL OTHER CODE NEEDS TO GO HERE
def openfile():
return filedialog.askopenfilename()
def open():
global my_image
root.filename = filedialog.askopenfilename(initialdir="/test3/images", title="Select A File", filetypes=(("png files", "*.png"),("all files", "*.*")))
my_label = Label(root, text=root.filename).pack()
my_image = ImageTk.PhotoImage(Image.open(root.filename))
my_image_label = Label(image=my_image).pack()
def find_craters():
circles_image = cv2.imread(root.filename)
if circles_image.shape[-1] == 3: # color image
b,g,r = cv2.split(circles_image) # get b,g,r
rgb_img = cv2.merge([r,g,b]) # switch it to rgb
gray_img = cv2.cvtColor(circles_image, cv2.COLOR_BGR2GRAY)
else:
gray_img = circles_image
img = cv2.medianBlur(gray_img, 5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=0,maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
plt.subplot(122),plt.imshow(cimg)
plt.show()
### HOW RETURN CIRCLES_IMAGE TO TKINTER
# circles_label = Label(root, text=root.filename).pack()
# circles_image = ImageTk.PhotoImage(Image.open(cimg))
# circles_image_label = Label(image=circles_image).pack()
#circles_img = Label(root, image= cimg).pack()
# plt.subplot(122),plt.imshow(cimg)
# plt.show()
my_btn = Button(root, text="Load Terrain", command=open).pack()
my_btn2 = Button(root, text="Find Craters", command=find_craters).pack()
#my_btn3 = Button(root, text=" About Me ").pack()
mb.pack()
root.mainloop()
I would like some help
Jackson