0

i have this code

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)

Which is used to detect faces and make a rectangle around them using my cam. i want to take the detected face as an image and save it in a folder /test/1.jpg with the same size of rectangle .. in order to compare it with saved photos .. and get the persons name how can ths happen ?

1 Answers1

0

Here is the way to save the image

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)
VICTOR
  • 1,894
  • 5
  • 25
  • 54