【问题标题】:Recognition faces on a video using python使用python识别视频中的人脸
【发布时间】:2016-10-14 22:57:51
【问题描述】:

我有这个代码

import cv2
import sys

# Get user supplied values
imagePath = sys.argv[1]
cascPath = sys.argv[2]

# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)

# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect faces in the image
faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(30, 30),
    flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)

print "Found {0} faces!".format(len(faces))

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)

cv2.imshow("Faces found", image)
cv2.waitKey(0)

它用于检测面部并使用我的摄像头在它们周围制作一个矩形。 我想将检测到的人脸作为图像并将其保存在具有相同矩形大小的文件夹 /test/1.jpg 中。 为了将其与保存的照片进行比较..并获取人名 怎么会这样?

【问题讨论】:

    标签: python opencv image-processing face-recognition


    【解决方案1】:

    这是保存图片的方法

    for (x, y, w, h) in faces:
        if(x<0 and y<0):
            face= frame[ 0:h, 0:h,:]
        elif(y<0):
            face= frame[ 0:0+h, x:w,:]
        elif(x<0):
            face= frame[ y:h, 0:0+w,:]
        else:
            face= frame[ y:h, x:w,:]
     cv2.imwrite("folder /test/1.jpg", face)
    

    【讨论】:

      猜你喜欢
      • 2014-11-15
      • 2016-08-09
      • 1970-01-01
      • 1970-01-01
      • 2017-08-28
      • 2023-03-06
      • 2018-06-14
      • 2019-08-10
      • 2019-01-21
      相关资源
      最近更新 更多