FaceDetection应用程序
似乎显示功能具有错误部分
> library(saccades)
> data(samples)
> head(samples)
time x y trial
1 0 53.18 375.73 1
2 4 53.20 375.79 1
3 8 53.35 376.14 1
4 12 53.92 376.39 1
5 16 54.14 376.52 1
6 20 54.46 376.74 1
> fixations <- detect.fixations(samples)
> head(fixations[c(1,4,5,10)])
trial x y dur
0 1 53.81296 377.40741 71
1 1 39.68156 379.58711 184
2 1 59.99267 379.92467 79
3 1 18.97898 56.94046 147
4 1 40.28365 39.03599 980
5 1 47.36547 35.39441 1310
> diagnostic.plot(samples, fixations)
错误 显示的文件“ GUI.py”,第16行 gray_img = cv.cvtColor(img,cv.COLOR_BGR2GRAY) UnboundLocalError:赋值之前引用了本地变量'img'
答案 0 :(得分:0)
抱歉,我没有阅读您的问题,您需要在显示功能中使用global img
,但是img allready全局定义的变量您不需要使用global:
...
img = cv.imread(imgTemp)
...
def display():
gray_img = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray_img,1.02,5)
print(type(faces))
print(faces.shape)
print(faces)
for x,y,w,h in faces:
img = cv.rectangle(img,(x,y),(x+w,x+h),(0,255,0),3)
resized = cv.resize(img,(int(img.shape[1]/2),int(img.shape[0]/2)))
cv.imshow("Gray",resized)
cv.waitKey(0)
cv.destroyAllWindows()