Demo entry 6700444

ssss

   

Submitted by dd on Jan 26, 2018 at 21:51
Language: Python. Code size: 4.2 kB.

import cv2 as cv
from Tkinter import *
import Tkinter as tk
import tkFileDialog as tkDF
from PIL import ImageTk, Image
import numpy as np
from cv2 import cvtColor

 

 
root = Tk()
root.title("Ejemplo de GUI")
panelO = None
panelA = None

root.minsize(1300,800)
#root.geometry("320x100")
file = 0

def donothing():
    print "Test"

def load_file():
    fileimage=tkDF.Open().show()       
    global pathF
    pathF = fileimage
    return fileimage
        

def open_img():
    file = load_file() 
    img = Image.open(file)
    img = img.resize((500, 500), Image.ANTIALIAS)
    img = ImageTk.PhotoImage(img)
    panelO = Label(root, image=img)
    panelO.image = img
    panelO.pack()
    panelO.place(x = 220, y = 70)

    #imgCV = cv.imread(file,0)
    #imgA = Image.fromarray(imgCV)
    imgA = Image.open(file)
    imgA = imgA.resize((500, 500), Image.ANTIALIAS)
    imgA = ImageTk.PhotoImage(imgA)
    panelA = Label(root, image=imgA)
    panelA.image = imgA
    panelA.pack()
    panelA.place(x = 720, y = 70)
    return imgA

    
def grises_img():
    global pathF
    file = pathF
    
    imgCV = cv.imread(file,0)
    imgA = Image.fromarray(imgCV)
    imgA = imgA.resize((500, 500), Image.ANTIALIAS)
    imgA = ImageTk.PhotoImage(imgA)
    panelA = Label(root, image=imgA)
    panelA.image = imgA
    panelA.pack()
    panelA.place(x = 720, y = 70)
    
def espacio_img():
    global pathF
    file = pathF
 
    imgCV = cv.imread(file)
    imgCV = cv.cvtColor(imgCV, cv.COLOR_BGR2HLS)
    imgA = Image.fromarray(imgCV)
    imgA = imgA.resize((500, 500), Image.ANTIALIAS)
    imgA = ImageTk.PhotoImage(imgA)
    panelA = Label(root, image=imgA)
    panelA.image = imgA
    panelA.pack()
    panelA.place(x = 720, y = 70)
    
def circulos_img():
    global pathF
    file = pathF
 
    imgCVR = cv.imread(file)
    imgCVR = cv.cvtColor(imgCVR,cv.COLOR_BGR2RGB )
    imgCV = cv.imread(file,0)
    img = cv.medianBlur(imgCV,5)
    
    circles = cv.HoughCircles(imgCV,cv.cv.CV_HOUGH_GRADIENT,1,20,
                               param1=1300,param2=50,minRadius=0,maxRadius=0)
    cir_cen = []
    #if circles != False:
        # circles = np.uint16(np.around(circles))
    for i in circles[0,:]:
        # drawing on detected circle and its center
        cv.circle(imgCVR,(i[0],i[1]),i[2],(0,255,0),2)
        cv.circle(imgCVR,(i[0],i[1]),2,(0,0,255),3)
        cir_cen.append((i[0],i[1]))
   
    imgA = Image.fromarray(imgCVR)
        
    imgA = imgA.resize((500, 500), Image.ANTIALIAS)
    imgA = ImageTk.PhotoImage(imgA)
    panelA = Label(root, image=imgA)
    panelA.image = imgA
    panelA.pack()
    panelA.place(x = 720, y = 70)    
        

abrir= ImageTk.PhotoImage(file="abrirN.png")
bAbrir = Button(root, image=abrir, command=open_img, height=50, width=150, compound=CENTER)
bAbrir.place(x = 20, y = 20)
#b.pack()        
        
grises= ImageTk.PhotoImage(file="escalagrises.png")
bGrises = Button(root, image=grises, command=grises_img, height=90, width=150,compound=CENTER)
bGrises.place(x = 20, y = 90)
     
especios= ImageTk.PhotoImage(file="RGB-HSV.png")
bEspecios = Button(root, image=especios, command=espacio_img, height=90, width=150, compound=CENTER)
bEspecios.place(x = 20, y = 200)  

circulos= ImageTk.PhotoImage(file="identificacioncircunferencias.png")
bCirculos = Button(root, image=circulos, command=circulos_img, height=90, width=150, compound=CENTER)
bCirculos.place(x = 20, y = 310)  


salir= ImageTk.PhotoImage(file="cerrar.png")
bSalir = Button(root, image=salir, command=root.quit, height=50, width=150, compound=CENTER)
bSalir.place(x = 20, y = 700)  
   
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Abrir", command=load_file)
filemenu.add_command(label="Save", command=donothing)
filemenu.add_separator()
filemenu.add_command(label="Salir", command=root.quit)
menubar.add_cascade(label="Archivo", menu=filemenu)
 
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Acerca de...", command=donothing)
menubar.add_cascade(label="Ayuda", menu=helpmenu)
 
root.config(menu=menubar)
root.mainloop()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).