小编Tyl*_*uth的帖子

OpenCV 4 TypeError:参数“标签”的预期 cv::UMat

我正在编写面部识别程序,但在尝试训练识别器时不断收到此错误

TypeError: Expected cv::UMat for argument 'labels'
Run Code Online (Sandbox Code Playgroud)

我的代码是

def detect_face(img):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5);
    if (len(faces)==0):
        return None, None
    (x, y, w, h) = faces[0]
    return gray[y:y+w, x:x+h], faces[0]

def prepare_training_data():
    faces = []
    labels = []
    for img in photo_name_list: #a collection of file locations as strings
        image = cv2.imread(img)
        face, rect = detect_face(image)
        if face is not None:
            faces.append(face)
            labels.append("me")
    return faces, labels

def test_photos():
    face_recognizer = cv2.face.LBPHFaceRecognizer_create() …
Run Code Online (Sandbox Code Playgroud)

python opencv numpy python-3.x facial-identification

5
推荐指数
1
解决办法
4万
查看次数

OpenCV 4.0.0 SystemError:<class'cv2.CascadeClassifier'>返回的结果带有错误集

您好,我正在尝试创建一个面部识别程序,但是出现一个奇怪的错误:这是我的代码:

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face_cascade = cv2.CascadeClassifier("lbpcascade_frontalface.xml")
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5);
Run Code Online (Sandbox Code Playgroud)

这个错误是输出

SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set
Run Code Online (Sandbox Code Playgroud)

我的工作目录中有“ lbpcascade_frontalface.xml”,所以这不应该成为问题

如果我输入时有帮助

cv2.__version__
Run Code Online (Sandbox Code Playgroud)

我懂了

'4.0.0'
Run Code Online (Sandbox Code Playgroud)

python opencv cv2 facial-identification

4
推荐指数
1
解决办法
5592
查看次数

request.get() 被卡住了

您好,我正在尝试从网站上抓取一些数据,但 request.get() 遇到了一些问题。这是我的代码:

page_url = front_end+str(i)+'/'
page = requests.get(page_url)
Run Code Online (Sandbox Code Playgroud)

所以我希望它是一个字符串,因为我只是输入一个网址,如果我停止代码或者它运行太长时间,我会得到类似的内容:

File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", 
line 377, in _make_request
    httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 24, in <module>
    page = requests.get(page_url)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping python-requests

2
推荐指数
1
解决办法
4754
查看次数

Python 类型错误:UMat() 缺少必需的参数“范围”(位置 2)

我正在编写一个面部识别程序,但我一直收到这个错误,我很困惑我在网上没有看到人们在转换为 UMat 时包含范围的其他示例

    Traceback (most recent call last):
  File "test.py", line 48, in <module>
    test_photos()
  File "test.py", line 40, in test_photos
    face, rect = detect_face(test_photo)
  File "test.py", line 15, in detect_face
    imgUMat = cv2.UMat(img)
TypeError: UMat() missing required argument 'ranges' (pos 2)
Run Code Online (Sandbox Code Playgroud)

我的代码是

def detect_face(img):   
    imgUMat = cv2.UMat(img)
    gray = cv2.cvtColor(imgUMat, cv2.COLOR_BGR2GRAY)
    face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5)
    if (len(faces)==0):
        return None, None
    (x, y, w, h) = faces[0]
    gray = gray.get()
    return gray[y:y+h,x:x+w], faces[0]

def …
Run Code Online (Sandbox Code Playgroud)

python opencv numpy python-3.x facial-identification

2
推荐指数
1
解决办法
1万
查看次数