我正在尝试运行此代码但是我收到以下错误... 实际上,我正在尝试使用OpenCV进行人脸识别..
import sqlite3
import cv2
import numpy as np
import urllib.request as ur
faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
def insert(ID,Name):
conn=sqlite3.connect("FaceBase.db")
cmd="SELECT * FROM People Where id=?"+str(id)
cursor=conn.execute(cmd)
doesRecordExist=0
for row in cursor:
doesRecordExist=1
if(doesRecordExist==1):
cmd="UPDATE People SET Name="+str(Name)+"WHERE Id="+str(ID)
else:
cmd="INSERT INTO People(ID,Name) Values("+str(ID)+","+str(Name)+")"
conn.execute(cmd)
conn.commit()
conn.close()
但我得到了这个错误:
File "C:/Users/Sandesh R Patil/Desktop/Project/Face Recog
sqlite/datasetCreator.py", line 10, in insert
cursor=conn.execute(cmd)
OperationalError: near "in": syntax error
答案 0 :(得分:1)
第9行的ID不正确请尝试:
import sqlite3
import cv2
import numpy as np
import urllib.request as ur
faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
def insert(ID,Name):
conn=sqlite3.connect("FaceBase.db")
cmd="SELECT * FROM People WHERE id=?"+str(ID)
cursor=conn.execute(cmd)
doesRecordExist=0
for row in cursor:
doesRecordExist=1
if(doesRecordExist==1):
cmd="UPDATE People SET Name="+str(Name)+" WHERE Id="+str(ID)
else:
cmd="INSERT INTO People(ID,Name) Values("+str(ID)+","+str(Name)+")"
conn.execute(cmd)
conn.commit()
conn.close()