赞
踩
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)
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。