0

I use Python 3 and OpenCV 3. I want to get face image dataset from webcam same size image.

This is my code.

import cv2
import numpy as np

faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
cam=cv2.VideoCapture(0);

id=input('enter user id')
sampleNum=0;

while(True):
    ret,img=cam.read();
    resize_image = cv2.resize(img, (200,200), interpolation=cv2.INTER_CUBIC)  # Resize to same size

    gray=cv2.cvtColor(resize_image,cv2.COLOR_BGR2GRAY)   
    faces=faceDetect.detectMultiScale(gray,1.3,5);

    for(x,y,w,h) in faces:
        sampleNum=sampleNum+1
        cv2.imwrite("dataSet/User."+str(id)+"."+str(sampleNum) + ".jpg", gray[y:y+h,x:x+w])
        cv2.rectangle(resize_image,(x,y),(x+w, y+h), (0,255,0) , 2)
        cv2.waitKey(100)

    cv2.imshow("Face", resize_image);
    cv2.waitKey(1)
    if(sampleNum>20):
        break;

cam.release()
cv2.destroyAllWindows()

I try to resize image to 200,200 but image file in folder dataSet still different size width * height pixels. How to get face image dataset from webcam same size image ?

user572575
  • 1,009
  • 3
  • 25
  • 45

0 Answers0