【发布时间】:2020-06-26 12:46:30
【问题描述】:
我一直在使用 numpy、PIL 和 OpenCV 创建人脸检测和处理系统。我正在尝试做的是围绕边界框进行裁剪(用于我尚未编写的进一步处理),所以我写了以下内容:
import cv2
import numpy as np
from PIL import Image
def main():
#Creates a camera object
vidCapture = cv2.VideoCapture(0)
while 1:
faceDetector = FaceDetector()
#stores the current frame into the frame variable
ret, frame = vidCapture.read()
#detects any faces and draws bounding boxes around them
img = faceDetector.find_any_faces(frame)
processing = Processing()
#crops everything around the bounding boxes for the faces
processing.mask(frame, faceDetector.getPoint1(), faceDetector.getPoint2())
class Processing():
#masks around the bounding boxes for the face
def mask(self, image, p1, p2):
#creates a numpy array from the image
arrimg = np.array(image)
#creates a PIL Image from the np array
img = Image.fromarray(arrimg)
#crops around each bounding box
cropped_image = img.crop(p1, p2)
return cropped_image
这会引发 TypeError 并显示以下消息:“crop() 采用 1 到 2 个位置参数,但给出了 3 个”。据我所知,这些通常来自不包括self 作为方法的参数,但我在代码中包含了我的参数。如果有人可以提供帮助,那就太好了!
【问题讨论】:
-
请提供完整的错误信息,以及minimal reproducible example。
标签: python numpy opencv python-imaging-library cv2