Ask Your Question
0

error in facerec.cpp

asked 2017-12-28 09:57:46 -0600

updated 2017-12-28 10:45:02 -0600

berak gravatar image

facerecc.cpp is causing an error.cv2.error: C:\projects\opencv-python\opencv_contrib\modules\face\src\facerec.cpp:61: error: (-2) File can't be opened for reading! in function cv::face::FaceRecognizer::read

import cv2
import numpy as np
face_cascade= cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cam=cv2.VideoCapture(0)
rec=cv2.face.LBPHFaceRecognizer_create()
rec.read("recognizer\\trainning.yml")
id=0
font=cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHY_COMPLEX_SMALL,1,1,0,1)
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,0,255),2)
        id,conf=rec.predict(gray[y:y+h,x:x+w])
        cv2.cv.PutText(cv2.cv.fromarray(img),str(id),(x,y+h),font,255)
    cv2.imshow("face",img)
    if(cv2.waitKey(1)==ord('q')):
        break
cam.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

Comments

what do you think is unclear about the error message ?

berak gravatar imageberak ( 2017-12-28 10:45:28 -0600 )edit

also:

font=cv2.FONT_HERSHY_COMPLEX_SMALL

and

cv2.putText(img,str(id),(x,y+h),font,255)

(cv2.cv does no more exist)

berak gravatar imageberak ( 2017-12-28 11:06:14 -0600 )edit

thank you sir for responding. but i am facing problem with a error on facerec.cpp

sumanth alapati gravatar imagesumanth alapati ( 2017-12-30 09:09:01 -0600 )edit

"File can't be opened for reading!" -- you mistyped the name (trainning, really ?) or the path is wrong

berak gravatar imageberak ( 2017-12-30 09:19:30 -0600 )edit

sorry sir i was mistaken there was another error

sumanth alapati gravatar imagesumanth alapati ( 2017-12-30 09:32:14 -0600 )edit

@mike123 , please do not post answers here, if you have a question or comment, thank you !

berak gravatar imageberak ( 2018-03-13 05:42:09 -0600 )edit

0 answers

Sort by ยป oldest newest most voted
0

answered 2018-03-13 04:56:23 -0600

hello sir I have the same issue. Did you solve the problem. C:\projects\opencv-python\opencv_contrib\modules\face\src\facerec.cpp, line 61

I will be helpful if you help me with this problem.

thanks in advance

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-12-28 09:57:46 -0600

Seen: 2,064 times

Last updated: Dec 28 '17