gpt4 book ai didi

python - 使用 Python 选择第一面 OpenCV detectMultiScale

转载 作者:行者123 更新时间:2023-12-02 17:31:13 31 4
gpt4 key购买 nike

我正在测试 OpenCV 来检测人脸,我想知道如何才能有效地只检测到第一张人脸?

下面的代码适用于多个,但如果我在 faces[0] 上执行 for 循环,应用程序会提示:

for (x,y,w,h) in faces[0]:
TypeError: 'numpy.int32' object is not iterable


if len(faces) == 0:
print('the list is empty', datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
else:
print('the list is NOT empty', 'Detected',len(faces),'Face(s)')
print(faces)

for (x,y,w,h) in faces:
cv.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
roi_color = img[y:y+h, x:x+w]

cv.imshow('Facial Recognition', img)

最佳答案

faces[0] 只是一张脸,所以你不能循环它。

if len(faces) == 0:
print('the list is empty', datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
else:
print('the list is NOT empty', 'Detected',len(faces),'Face(s)')
print(faces)

face = faces[0]
(x,y,w,h) = face
cv.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
roi_color = img[y:y+h, x:x+w]

cv.imshow('Facial Recognition', img)

关于python - 使用 Python 选择第一面 OpenCV detectMultiScale,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55569381/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com