Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python cv2.错误:(-215)s>;=函数setSize中的0_Python_Opencv_Raspberry Pi_Raspberry Pi3 - Fatal编程技术网

Python cv2.错误:(-215)s>;=函数setSize中的0

Python cv2.错误:(-215)s>;=函数setSize中的0,python,opencv,raspberry-pi,raspberry-pi3,Python,Opencv,Raspberry Pi,Raspberry Pi3,我在运行代码时遇到此错误。我试图用覆盆子圆周率从网络摄像头捕捉一张照片,但有时我捕捉到的第一张照片是空的。所以我像这样验证它 ret, img = cam.read(); if not ret: continue 如何避免此错误 损坏的JPEG数据:标记0xd1 OpenCV之前有1个额外字节 错误:setSize文件中的断言失败(s>=0) /home/pi/opencv-3.2.0/modules/core/src/matrix.cpp,第307行回溯 (最后一次调用):文

我在运行代码时遇到此错误。我试图用覆盆子圆周率从网络摄像头捕捉一张照片,但有时我捕捉到的第一张照片是空的。所以我像这样验证它

ret, img = cam.read();
        if not ret: continue
如何避免此错误

损坏的JPEG数据:标记0xd1 OpenCV之前有1个额外字节 错误:setSize文件中的断言失败(s>=0) /home/pi/opencv-3.2.0/modules/core/src/matrix.cpp,第307行回溯 (最后一次调用):文件“total.py”,第248行,在 facialReco(目录)文件“total.py”,facialReco中第236行 id,dist,it=reco(faceDetec)文件“total.py”,第188行,在reco中 识别器.predict_collect(灰色[yHMax:yHMax+hMax,xHMax:xHMax+wHMax],收集器)

cv2.error:/home/pi/opencv-3.2.0/modules/core/src/matrix.cpp:307: 错误:(-215)s>=0在函数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
def记录(faceDetec): recognizer=cv2.face.createLBPHFaceRecognizer() 识别器加载(“识别器/培训数据”LBPHF.yml) id=0 它=0 距离=0 cam=cv2.视频捕获(0) #这是一个长方形的房间,还有一个大房间。 当它小于20时: ret,img=cam.read(); 如果不是ret:继续 cv2.imshow(“脸”,img); cv2.等待键(1) 灰色=cv2.CVT颜色(img,cv2.COLOR\U BGR2GRAY) 面=面检测。检测多尺度( img, scaleFactor=1.2, minNeighbors=7, minSize=(50,50) ) hMax=0 wHMax=0 xHMax=0 yHMax=0 对于面中的(x,y,w,h): 如果h>hMax: hMax=h wHMax=w xHMax=x yHMax=y 收集器=cv2.face.StandardCollector_create() 识别器.predict_collect(灰色[yHMax:yHMax+hMax,xHMax:xHMax+wHMax],收集器)
if collector.getMinDist()我通过添加:“if not img is None:”来纠正错误

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 img is None: 
            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
def记录(faceDetec): recognizer=cv2.face.createLBPHFaceRecognizer() 识别器加载(“识别器/培训数据”LBPHF.yml) id=0 它=0 距离=0 cam=cv2.视频捕获(0) #这是一个长方形的房间,还有一个大房间。 当它小于20时: ret,img=cam.read(); 如果没有,img为无: 如果不是ret:继续 cv2.imshow(“脸”,img); cv2.等待键(1) 灰色=cv2.CVT颜色(img,cv2.COLOR\U BGR2GRAY) 面=面检测。检测多尺度( img, scaleFactor=1.2, minNeighbors=7, minSize=(50,50) ) hMax=0 wHMax=0 xHMax=0 yHMax=0 对于面中的(x,y,w,h): 如果h>hMax: hMax=h wHMax=w xHMax=x yHMax=y 收集器=cv2.face.StandardCollector_create() 识别器.predict_collect(灰色[yHMax:yHMax+hMax,xHMax:xHMax+wHMax],收集器) if collector.getMinDist()