코드를 실행하는 동안이 오류가 발생합니다. 나는 라즈베리 파이가있는 웹캠에서 그림을 잡으려고하는데, 언젠가는 내가 잡은 첫 번째 그림이 비어 있습니다. 그래서 이것을 확인합니다cv2.error : function setSize에서 (-215) s> = 0
ret, img = cam.read();
if not ret: continue
이 오류를 방지하려면 어떻게해야합니까?
Corrupt JPEG data: 1 extraneous bytes before marker 0xd1 OpenCV Error: Assertion failed (s >= 0) in setSize, file /home/pi/opencv-3.2.0/modules/core/src/matrix.cpp, line 307 Traceback (most recent call last): File "total.py", line 248, in facialReco(directory) File "total.py", line 236, in facialReco id, dist, it = reco(faceDetec) File "total.py", line 188, in reco recognizer.predict_collect(gray[yHMax:yHMax + hMax, xHMax:xHMax + wHMax], collector)
cv2.error: /home/pi/opencv-3.2.0/modules/core/src/matrix.cpp:307: error: (-215) s >= 0 in function setSize
내 전체 코드는 다음과 같습니다
def reco(faceDetec):
recognizer = cv2.face.createLBPHFaceRecognizer()
recognizer.load("recognizer/trainingData_LBPHF.yml")
id = 0
it = 0
dist = 0
cam = cv2.VideoCapture(0)
# prendre les rectangle ayant la plus grde largeur seulement.
while it < 20:
ret, img = cam.read();
if not ret: continue
cv2.imshow("Face", img);
cv2.waitKey(1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceDetec.detectMultiScale(
img,
scaleFactor=1.2,
minNeighbors=7,
minSize=(50, 50)
)
hMax=0
wHMax=0
xHMax=0
yHMax=0
for (x, y, w, h) in faces:
if h>hMax:
hMax=h
wHMax=w
xHMax=x
yHMax=y
collector = cv2.face.StandardCollector_create()
recognizer.predict_collect(gray[yHMax:yHMax + hMax, xHMax:xHMax + wHMax], collector)
if collector.getMinDist()<65:
it += 1
dist = dist + collector.getMinDist()
id = collector.getMinLabel()
numberOfRec(id)
cam.release()
cv2.destroyAllWindows()
req="SELECT studentId FROM Student WHERE numberOfRec=(SELECT MAX(numberOfRec) FROM Student);"
cursor.execute(req)
rows = cursor.fetchall()
for row in rows:
id=row[0]
req="UPDATE Student SET numberOfRec = %(numberOfRec)"
values = {"numberOfRec": 0}
cursor.execute(req, values)
db.commit()
return id, dist, it