opencv-python: TypeError: can only join an iterable
#==================Errors====================
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Joy\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "c:\Users\Joy\Desktop\Student Attendance System\Student Attendance System\face_recognition.py", line 119, in face_recog
img=recognize(img,clf,faceCascade)
File "c:\Users\Joy\Desktop\Student Attendance System\Student Attendance System\face_recognition.py", line 108, in recognize
coord=draw_boundray(img,faceCascade,1.1,10,(255,25,255),"Face",clf)
File "c:\Users\Joy\Desktop\Student Attendance System\Student Attendance System\face_recognition.py", line 79, in draw_boundray
n="+".join(n)
TypeError: can only join an iterable
[ WARN:0] global C:\New folder\opencv-master\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
#===================================code============================
def face_recog(self):
def draw_boundray(img,classifier,scaleFactor,minNeighbors,color,text,clf):
gray_image=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
features=classifier.detectMultiScale(gray_image,scaleFactor,minNeighbors)
coord=[]
for (x,y,w,h) in features:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3)
id,predict=clf.predict(gray_image[y:y+h,x:x+w])
confidence=int((100*(1-predict/300)))
conn=mysql.connector.connect(host="localhost",username="root",password="**********",database="face_recognizer")
my_cursor=conn.cursor()
my_cursor.execute("select Name from student where Student_Id="+str(id))
n=my_cursor.fetchone()
n="+".join(n)
my_cursor.execute("select Roll from student where Student_Id="+str(id))
r=my_cursor.fetchone()
r="+".join(r)
my_cursor.execute("select Department from student where Student_Id="+str(id))
d=my_cursor.fetchone()
d="+".join(d)
my_cursor.execute("select Student_Id from student where Student_Id="+str(id))
i=my_cursor.fetchone()
i="+".join(i)
if confidence>77:
cv2.putText(img, f"ID:{i}",(x,y-75),cv2.FONT_HERSHEY_COMPLEX,0.8,(255,255,255),3)
cv2.putText(img, f"Roll:{r}",(x,y-55),cv2.FONT_HERSHEY_COMPLEX,0.8,(255,255,255),3)
cv2.putText(img, f"Name:{n}",(x,y-30),cv2.FONT_HERSHEY_COMPLEX,0.8,(255,255,255),3)
cv2.putText(img, f"Department:{d}",(x,y-5),cv2.FONT_HERSHEY_COMPLEX,0.8,(255,255,255),3)
self.mark_attendance(i,r,n,d)
else:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),3)
cv2.putText(img,"Unknown Face",(x,y-55),cv2.FONT_HERSHEY_COMPLEX,0.8,(255,255,255),3)
coord=[x,y,w,h]
return coord
def recognize(img,clf,faceCascade):
coord=draw_boundray(img,faceCascade,1.1,10,(255,25,255),"Face",clf)
return img
faceCascade=cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
clf=cv2.face.LBPHFaceRecognizer_create()
clf.read("classifier.xml")
video_cap=cv2.VideoCapture(0)
while True:
ret,img=video_cap.read()
img=recognize(img,clf,faceCascade)
cv2.imshow("Welcome To Face Recognition",img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_cap.release()
cv2.destroyAllWindows()
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 31
You can remove the line n="+"join(n) Then the error is solve 2nd method is write n=str(n) Below the fetchone() line and above the join line