当前位置:   article > 正文

python多张照片拼成一张人脸_用python提取一张照片中人脸的代码

python 用多张照片合成一个人轮廓

from future import print_function

from facedetector import FaceDetector

import argparse

import cv2

import os

i = 0

ap = argparse.ArgumentParser()

“”“ap.add_argument(”-f", “–face”, required=True,

help=“path to where the face cascade resides”)"""

“”“ap.add_argument(”-i","–image",required=True,

help=“path to where the image file resides”)"""

args =vars(ap.parse_args())

“”“image =cv2.imread(args[“image”])”""

#fd = FaceDetector(args[“face”])

path = ‘D:/Big semester/project/Computer vision/face_and_car/jpg’

path1 = ‘D:/Big semester/project/Computer vision/face_and_car/model’

for lists1 in os.listdir(path1):

for lists in os.listdir(path):

if lists1 == “oneface.xml” :

su_path1 = os.path.join(path1, lists1)

fd = FaceDetector(su_path1)

su_path = os.path.join(path,lists)

image = cv2.imread(su_path, cv2.IMREAD_COLOR)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

faceRects = fd.detect(gray,scaleFactor=1.2, minNeighbors=5,minSize=(30,30))

print(“I found {} face(s)”.format(len(faceRects)))

i = i+1

for(x,y,w,h) in faceRects:

cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)

#cv2.imshow(“first”,image)

cv2.imwrite(‘photo_1/’+str(i)+’.jpg’,image,)

for j in range(0,len(faceRects)+1):

for (x,y,w,h) in faceRects[j-1:j]:

#print(faceRects[j-1:j])

#cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)

image_cut = image[y:y + h, x:x + w];

#cv2.imshow(“123”, image_cut)

cv2.imwrite(‘photo_2/’+str(i)+‘cut_’ + str(j) + ‘.jpg’, image_cut)

else:

break

cv2.waitKey(1)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/906776
推荐阅读
相关标签
  

闽ICP备14008679号