How to detect and capture an image automatically when person is in front of the camera
I am learning about face recognition.I do this using opencv, c++ language,visual studio 2015. I want to do when a person come in front of the camera,it capture the face automatically and save in database.how I done it. How it done. Please help me.
this is the code that I use to open the camera
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <stdio.h>
using namespace std;
using namespace cv;
int main(int, char**)
{
Mat img;
VideoCapture cam(0);
namedWindow("camera");
while (1) {
cam >> img;
imshow("camera", img);
if (waitKey(1) == 27)
{
break;
}
}
cam.release();
return 0;
}
import numpy as np import cv2 face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') img = cv2.imread('image.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x,y,w,h) in faces: crp_face = img[y-50:y+h+20, x-50:x+50+w] # adjust the resolution according to you. cv2.imwrite('img'+str(i)+'.jpg',crp_face) cv2.imshow('detected',crp_face) i+=1
cv2.waitKey(0) cv2.destroyAllWindows()
in the similar way you can apply for any video and for detection. if you want save in particular folder just mention the folder_name along with image.jpg by seperating with '\'. now this code can save any number of images while detecting with cam.
thank you for your support