import cv2
from tkinter import *
window = Tk()
label= Label(window, text ="Enter The Image direction followed by two front slashes and the image name followed by its file type",fg ="black",bg = "green")
label.pack()
topframe=Frame(window)
topframe.pack()
bottomframe=Frame(window)
bottomframe.pack(side = BOTTOM)
imgpath=StringVar()
input=Entry(topframe,textvariable = imgpath,bg="lightgreen")
input.pack()
location=StringVar
def do():
location=('"'+str(imgpath.get())+'"')
print(location)
button1=Button(topframe,text="Detect face and eyes",bg = "black",fg="green",command = do)
button1.pack( )
window.mainloop()
face_cascade= cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_eye.xml")
img =cv2.imread(location)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face=face_cascade.detectMultiScale(gray,scaleFactor=1.3,minNeighbors=5)
for (x,y,w,h) in face:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
resized = cv2.resize(img,(700,600))
cv2.imshow("img",resized)
cv2.waitKey(0)
“ am在第30行收到错误,因为我将参数设置为 一个从输入字段“ Entry”中读取的变量,我认为当我按下按钮时变量发送是一个问题,因为变量位置的分配发生在按下按钮的过程中,而命令名为do >