我想通过在检测到面部时指定id自动递增来将人员添加到数据库。这是创建sql连接并添加详细信息的代码。
def insertOrUpdate(id, gender):
conn=sqlite3.connect("facebase.db")
cmd="SELECT * FROM people WHERE ID="+str(id)
cursor=conn.execute(cmd)
isRecordExist=0
for row in cursor:
isRecordExist=1
if(isRecordExist==1):
cmd="UPDATE people SET id=' "+str(id)+" ' WHERE id="+str(id)
else:
cmd="INSERT INTO people(id,gender) Values("+str(id)+",' "+str(gender)+" ' )"
conn.execute(cmd)
conn.commit()
conn.close()
所以我在这里要求用户输入id和性别。
id=raw_input('enter id')
gender=raw_input('enter your gender')
insertOrUpdate(id,gender)
i=0
while True:
ret, im =cam.read()
gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
faces=detector.detectMultiScale(im, scaleFactor=1.2, minNeighbors=5, minSize=(100, 100), flags=cv2.CASCADE_SCALE_IMAGE)
for(x,y,w,h) in faces:
i=i+1
cv2.imwrite("dataSet/face-"+id +'.'+ str(i) + ".jpg", im[y:y+h+30,x-30:x+w+30])
cv2.rectangle(im,(x-50,y-50),(x+w+50,y+h+50),(225,0,0),2)
cv2.imshow('im',im[y-30:y+h+30,x-30:x+w+30])
如何通过自动增量为每个面部分配ID来自动捕获检测到的面部并添加到数据库的过程?