我在django + mysql中创建我的第一个项目,这里的问题是它通知我名称' connection'没有定义。我不知道为什么。任何人都无法解释我吗? 来自django.db导入连接 import cv2
def detect(请求):
faceDetect = cv2.CascadeClassifier(BASE_DIR + '/haarcascade_frontalface_default.xml')
cam = cv2.VideoCapture(0)
# creating recognizer
rec = cv2.face.LBPHFaceRecognizer_create();
# loading the training data
rec.read(BASE_DIR + '/recognizer/trainingData.yml')
getId = 0
font = cv2.FONT_HERSHEY_SIMPLEX
maSv = 0
while(True):
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceDetect.detectMultiScale(gray, 1.3, 5)
for(x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h), (0,255,0), 2)
getId,conf = rec.predict(gray[y:y+h, x:x+w]) #This will predict the id of the face
#print conf;
if conf<35:
maSv = getId
cv2.putText(img, str(maSv),(x,y+h), font, 2, (0,255,0),2)
maSV = str(maSv)
with connection.cursor() as cursor:
cursor.callproc('diemdanh', [maSV, '101B1'])
else:
cv2.putText(img, "Unknown",(x,y+h), font, 2, (0,0,255),2)
# Printing that number below the face
# @Prams cam image, id, location,font style, color, stroke
cv2.imshow("Face",img)
if(cv2.waitKey(1) == ord('q')):
break
elif(maSv != 0):
cv2.waitKey(1000)
cam.release()
cv2.destroyAllWindows()
return redirect('/')
cam.release()
cv2.destroyAllWindows()
return redirect('/')
答案 0 :(得分:0)
您导入了连接吗?
尝试:
from django.db import connection