Ich erstelle ein Programm zum Erkennen von Objekten mit Tkinter-OpenCV-Python. ich habe bereits die Schnittstelle mit dem Trackbar und ich das Bild hochgeladen, aber im Moment des den Wert des trackbar ändert dies wird nicht aktualisiert, in dem BildTrackbar HSV OpenCv Tkinter Python
from Tkinter import * # Para Interfaz Grafica
import Tkinter
import gtk # Para Obtener Ancho/Alto
import tkFileDialog # Para Buscar Archivo
import cv2 # Libreria OpenCV
from PIL import Image, ImageTk
import numpy as np
#*******************************************************************
#Se crea la Pantalla Principal, tomando el Ancho/Alto de la Pantalla
#Se captura el ancho y alto
width = gtk.gdk.screen_width()
height = gtk.gdk.screen_height()
app = Tk()
#app.config(bg="red") # Le da color al fondo
app.geometry(str(width)+"x"+str(height)) # Cambia el tamaño de la ventana
app.title("TEST")
#*******************************************************************
#Buscar Imagen
def select_image():
# open a file chooser dialog and allow the user to select an input
# image
path = tkFileDialog.askopenfilename()
if len(path) > 0: # Si se ha cargado la imagen
# cargar imagen del disco
image = cv2.imread(path,1)
data = image.shape
# OpenCV representa imagenes en BGR ; sin embargo PIL representa
# imagenes en RGB , es necesario intercambiar los canales
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lw_range = np.array([0, 0, 0])
up_range = np.array([255, 255, 255])
mask = cv2.inRange(hsv, lw_range, up_range)
res = cv2.bitwise_and(image,image, mask= mask)
# convertir la imagen a formato PIL
image = Image.fromarray(res).resize((570,570),Image.ANTIALIAS)
# ...Luego a formato ImageTk
image=ImageTk.PhotoImage(image)
label_img = Label(app, image = image,relief=SOLID)
label_img.image=image
label_img.pack()
label_img.place(x=790,y=5)
label1 = Label(app, text="Informacion Imagen\nAlto:{}\nAncho:{}\nCanales:{}".format(data[0],data[1],data[2]))
label1.pack()
label1.place(x=790,y=577)
btn = Button(app, text="Abrir Imagen", command=select_image)
btn.pack(side="bottom", fill="both", expand="yes", padx="10", pady="10")
btn.place(x=5,y=5)
btn.configure(width=12)
#********************************************
#LABEL H
label2=Label(app,text = 'Filtro HSV')
label2.place(x=0,y=50)
label2.configure(width=7)
label2.configure(height=2)
#LABEL H
label10=Label(app,text = 'Hue')
label10.place(x=0,y=70)
label10.configure(width=7)
label10.configure(height=2)
#SLIDER H MINIMO
Hmin = StringVar()
w1 = Scale(app, from_=0, to=255, orient=HORIZONTAL,variable = Hmin)
w1.pack()
w1.place(x=70,y=70)
w1.configure(width=15)
#SLIDER H MAXIMO
Hmax= StringVar()
w2 = Scale(app, from_=0, to=255, orient=HORIZONTAL,variable = Hmax)
w2.pack()
w2.place(x=190,y=70)
w2.configure(width=15)
#LABEL S
label11=Label(app,text = 'Saturation')
label11.place(x=0,y=120)
label11.configure(width=7)
label11.configure(height=2)
#SLIDER S MINIMO
Smin= StringVar()
w3 = Scale(app, from_=0, to=255, orient=HORIZONTAL,variable = Smin)
w3.pack()
w3.place(x=70,y=120)
w3.configure(width=15)
#SLIDER S MAXIMO
Smax= StringVar()
w4 = Scale(app, from_=0, to=255, orient=HORIZONTAL, variable = Smax)
w4.pack()
w4.place(x=190,y=120)
w4.configure(width=15)
#LABEL V
label11=Label(app,text = 'Value')
label11.place(x=0,y=170)
label11.configure(width=7)
label11.configure(height=2)
#SLIDER V MINIMO
Vmin = StringVar()
w5 = Scale(app, from_=0, to=255, orient=HORIZONTAL, variable = Vmin)
w5.pack()
w5.place(x=70,y=170)
w5.configure(width=15)
#SLIDER V MAXIMO
Vmax = StringVar()
w6= Scale(app, from_=0, to=255, orient=HORIZONTAL,variable = Vmax)
w6.pack()
w6.place(x=190,y=170)
w6.configure(width=15)
#********************************************
app.mainloop()
test Das Bild unterzieht keine Änderungen
nicht verwenden 'Platz()' und 'pack()' (und 'Gitter () ') zur gleichen Zeit - sie sind verschiedene Layout-Manager und sie verwenden unterschiedliche Regeln, um Widgets in Fenster zu setzen. Wenn Sie zwei davon verwenden, können Sie eine Fehlermeldung mit einem Konflikt erhalten, oder nur einer von ihnen wird verwendet. – furas
tkinter hat eine eigene Methode, um die Bildschirmgröße zu erhalten, und Sie brauchen nicht gtk - http://StackOverflow.com/Questions/3949844/How-to-get-the-Screen-Size-in-Tkinter – furas
zuerst benötigen Sie Funktion, die aktualisiert das Bild und ersetzt es im Fenster. Ich sehe keine Funktion zum Aktualisieren des Bildes. Später müssen Sie diese Funktion Slidern oder Button zuweisen. – furas