我不会用英语说话,但我试图创建滑块以改变HSV(色调饱和度和值)的值。我创建了6个滑块,我能够打印它们的值。 我想创建6个滑块来修改图像的Hue min,Hue max,Sat max,Sat min,Val min,Val max并使用相同的按钮更新它。 我不知道问题是否在inRange函数中。也许我不能创建一个标签来显示图像。
是的,有人可以帮帮我吗? 谢谢!我收到了这个错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Python27\hsv_trackbar.py", line 109, in makeSomething
imgthresh1=cv2.inRange(imghsv,lw_range,up_range)
TypeError: lowerb data type = 18 is not supported
这是代码:
from Tkinter import *
import cv2
import numpy as np
import Tkinter
import tkMessageBox
from tkFileDialog import *
import ttk
from PIL import Image, ImageTk
from Tkinter import Tk, Label, SOLID
img = cv2.imread('C:\python27\Archivos\image02.jpg')
imghsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
#SE CREA LA VENTANA
ventana = Tk()
ventana.title("Agricultura de Precision")
ventana.geometry("1200x1200")
#SLIDER H MINIMO
Hmin = StringVar()
w1 = Scale(ventana, from_=0, to=255, orient=HORIZONTAL,variable = Hmin)
w1.pack()
w1.place(x=5,y=5)
w1.configure(width=15)
#SLIDER H MAXIMO
Hmax= StringVar()
w2 = Scale(ventana, from_=0, to=255, orient=HORIZONTAL,variable = Hmax)
w2.pack()
w2.place(x=5,y=45)
w2.configure(width=15)
#SLIDER S MINIMO
Smin= StringVar()
w3 = Scale(ventana, from_=0, to=255, orient=HORIZONTAL,variable = Smin)
w3.pack()
w3.place(x=5,y=85)
w3.configure(width=15)
#SLIDER S MAXIMO
Smax= StringVar()
w4 = Scale(ventana, from_=0, to=255, orient=HORIZONTAL, variable = Smax)
w4.pack()
w4.place(x=5,y=125)
w4.configure(width=15)
#SLIDER V MINIMO
Vmin = StringVar()
w5 = Scale(ventana, from_=0, to=255, orient=HORIZONTAL, variable = Vmin)
w5.pack()
w5.place(x=5,y=165)
w5.configure(width=15)
#SLIDER V MAXIMO
Vmax = StringVar()
w6= Scale(ventana, from_=0, to=255, orient=HORIZONTAL,variable = Vmax)
w6.pack()
w6.place(x=5,y=205)
w6.configure(width=15)
a=Hmin.get()
b=Hmax.get()
c= Smin.get()
d=Smax.get()
e= Vmin.get()
f= Vmax.get()
def makeSomething():
global a
global b
global c
global d
global e
global f
#lw_range= np.array([Hmin.get(),Smin.get(),Vmin.get()]) #oscuros
#up_range= np.array([Hmax.get(),Smax.get(),Vmax.get()]) #claros
lw_range = np.array([a,b,c]) #oscuros
up_range = np.array([d,e,f]) #claros
imgthresh1=cv2.inRange(imghsv,lw_range,up_range)
re_hsv=Image.fromarray(imgthresh1).resize((360,360),Image.ANTIALIAS)
imhsv1=ImageTk.PhotoImage(re_hsv)
lb_hsv = Label(ventana, image = imhsv1,relief=SOLID)
lb_hsv.image=imhsv1
lb_hsv.pack()
lb_hsv.place(x=230,y=180)
#BOTON1
Boton2 = Tkinter.Button(ventana, text = "Calculate HSV's Values",command=makeSomething)
Boton2.pack()
Boton2.place(x=5,y=300)
Boton2.configure(width=15)
ventana.mainloop()