Ask Your Question
0

How to detect and capture an image automatically when person is in front of the camera

asked 2018-02-26 23:08:05 -0600

anushkawellawaya@gmail.com gravatar image

updated 2018-02-26 23:49:04 -0600

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;
}
edit retag flag offensive close merge delete

Comments

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.

saideepthik gravatar imagesaideepthik ( 2018-02-27 07:27:19 -0600 )edit

thank you for your support

anushkawellawaya@gmail.com gravatar image[email protected] ( 2018-02-27 10:33:04 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-02-26 23:52:32 -0600

updated 2018-02-27 04:54:50 -0600

Please try to read some useful tutorials here.

  1. https://docs.opencv.org/3.4.0/d9/df8/...
  2. https://docs.opencv.org/2.4/modules/c...

Edit by @StevenPuttemans: It seems you are not looking for face recognition but face detection and then storage. In that case you simply need a face detection tutorial, which can be found here using a cascade classifier or here with a more advanced neural network approach.

edit flag offensive delete link more

Comments

Try to avoid posting multiple questions!

Balaji R gravatar imageBalaji R ( 2018-02-26 23:54:57 -0600 )edit
1

Please read this too http://answers.opencv.org/faq/

Balaji R gravatar imageBalaji R ( 2018-02-26 23:55:28 -0600 )edit

thank you for your advice and guidance

anushkawellawaya@gmail.com gravatar image[email protected] ( 2018-02-27 00:51:35 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-26 23:08:05 -0600

Seen: 1,893 times

Last updated: Feb 27 '18