gpt4 book ai didi

python - Haar-级联人脸检测OpenCv

转载 作者:行者123 更新时间:2023-12-02 16:55:40 25 4
gpt4 key购买 nike

我使用以下代码使用OpenCv Python提供的Haar级联分类器检测人脸。但是未检测到脸部,并且未绘制脸部周围的正方形。如何解决呢?

import cv2

index=raw_input("Enter the index No. : ")

cascPath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)

cap = cv2.VideoCapture(0)

cont=0

while(True):
# Capture frame-by-frame
ret, frame = cap.read()

# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=10,
minSize=(30, 30),
flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)

for (x, y, w, h) in faces:
#cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)


# Display the resulting frame
cv2.imshow('frame',frame)
inpt=cv2.waitKey(1)

if inpt & 0xFF == ord('q'):
break

elif inpt & 0xFF == ord('s') :

#name='G:\XCODRA\Integrated_v_01\EigenFaceRecognizer\img2'+index+"."+(str(cont))+".png"
name='IC_image\\'+index+"."+(str(cont))+".png"
resized = cv2.resize(gray,None,fx=200, fy=200, interpolation = cv2.INTER_AREA)
img=cv2.equalizeHist(resized)

cv2.imwrite(name,img)
print cont
cont+=1

最佳答案

使用分类器的完整路径。

关于python - Haar-级联人脸检测OpenCv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38006870/

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