0

I don't speak in English very well, But im trying to create sliders to change the values of HSV (Hue Saturation and Value). I created the 6 sliders and I was able to print their values. I want to create 6 sliders to modify Hue min, Hue max, Sat max, Sat min, Val min, Val max of an image and update it with the same button. I dont know if the problem is in the inRange function. Maybe I must not to create a label to show the image.

Can anybody help me please? Thanks!

I got this error:

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

This is the code:

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()
Jonah Fleming
  • 1,149
  • 2
  • 16
  • 28
Yehadska
  • 59
  • 6
  • Take a look at the example at http://www.tutorialspoint.com/python/tk_scale.htm to see how to get the value of a slider and "print" it-to a label in the example. –  Nov 01 '15 at 04:02
  • Hello, I did that but the problem is how to call the variables in the inRange function :( i dont know if the variable must be int, string.. you know why I got that error? Thanks!! – Yehadska Nov 01 '15 at 18:45
  • I FIXED IT! :) I had to convert the variables to Int hahaha – Yehadska Nov 01 '15 at 22:23
  • If you were able to fix it, please post your solution (incl. the changed code snippet) as an answer to this question, that others are able to find it more easily. – R4PH43L Nov 02 '15 at 16:30

0 Answers0