Giter VIP home page Giter VIP logo

human-detection-and-tracking's Introduction

Human detection and Tracking

Say Thanks!

Introduction

In this project we have worked on the problem of human detection,face detection, face recognition and tracking an individual. Our project is capable of detecting a human and its face in a given video and storing Local Binary Pattern Histogram (LBPH) features of the detected faces. LBPH features are the key points extracted from an image which is used to recognize and categorize images. Once a human is detected in video, we have tracked that person assigning him a label. We have used the stored LBPH features of individuals to recognize them in any other videos. After scanning through various videos our program gives output like- person labeled as subject1 is seen in video taken by camera1, subject1 is seen in video by camera2. In this way we have tracked an individual by recognizing him/her in the video taken by multiple cameras. Our whole work is based on the application of machine learning and image processing with the help of openCV.This code is built on opencv 3.1.1, python 3.4 and C++, other versions of opencv are NOT SUPPORTED.

Requirements

  • opencv [v3.1.1]

    • Installation in linux: For complete installation of opencv in ubuntu you can refer here.
    • Installation in windows For complete installation of opencv in windows you can refer here
  • python3

    • In Ubuntu python 3.4 can be installed via terminal with the command given below: sudo apt-get install python3
  • python libraries: Here is a list of all the python dependencies

    • Python Image Library (PILLOW)
    • Imutils
    • numpy
  • C++

Approach

  • The code follows the steps given below:
    1. First it reads a video and process each frame one by one.
    2. For each frame it tries to detect a human. If a human is detected it draws a rectangle around it.
    3. after completing step 2 it tries to detect human face.
    4. if a human face is detected it tries to recognize it with a pre-trained model file.
    5. If human face is recognized it puts the label on that human face else it moves to step 2 again for next frame
  • The repository is structured as follows:
    • main.py : This is the main python file that detects and recognizes humans.
    • main.cpp : This is the main C++ file that detects and recognizes humans.
    • create_face_model.py : This python script is used to create model file using the given data in data/ folder
    • model.yaml : This file contains trained model for given data. This trained model contains LBPH features of each and every face for given data.
    • face_cascades/ : This directory contains sample data for testing our codes. This data is prepared by extracting face images of a praticular person from some videos.
    • scripts/ : This directory contains some useful scripts that we used to work on different problems.
    • video/ : This directory contains some of the videos that we used to while testing.

Installation

Python

Don't forget to install the necessary libraries described in the install paragraph above.

First you need to run the create_face_model.py file, which uses the images in /data to create a .yaml file

  • In the project folder run
python create_face_model.py
  • To run the python version of the code you have to put all the input videos in one folder and then provide the path of that folder as command line argument:
python3 main.py -v /path/to/input/videos/  

Example- for our directory structure it is:

 python3 main.py -v /video 

C++

  • To compile the C++ version of the code with openCV the command is:
 g++ -ggdb `pkg-config --cflags opencv` -o `basename name_of_file.cpp .cpp` name_of_file.cpp `pkg-config --libs opencv` 

Example- for our directory structure it is:

 g++ -ggdb `pkg-config --cflags opencv` -o `basename main.cpp .cpp` main.cpp `pkg-config --libs opencv` 
  • To run the C++ version of the code you have to put all the input videos in one folder and then provide the path of that video as command line argument:
./name_of_file /path/to/input/video_file 

Example- for our directory structure it is:

 ./main /video/2.mp4
  • creating your own model file; just follow the steps given below to create your own model file:
    • for each individual rename the images as subjectx.y.jpg for example for person 1 images should be named as subject01.0.jpg , subject01.1.jpg and so on.
    • put all the images of all the persons in a single folder for example you can see data\ folder then run this command given below: python3 create_face_model.py -i /path/to/persons_images/

Performance of code

  • Since this is a computer vision project it requires a lot of computation power and performance of the code is kind of an issue here.
  • The code was tested on two different machines to analyse performace. The input was 30fps 720p video.
    • On a machine with AMD A4 dual-core processor we got an output of 4fps which is quite bad.
    • on a machine with Intel i5 quad-core processor we got an output of 12fps.

Results

alt text alt text alt text alt text

You can find project report here

To do

  • improve the performance of the code
  • improve the accuracy of the code and reducing the false positive rate.
  • improve the face recognition accuracy to over 90 percent

Special Thanks to:

human-detection-and-tracking's People

Contributors

arpit-matelabs avatar arpit1997 avatar cypherix avatar kamalawasthi avatar navneetnandan avatar priyankasin avatar prsntmaurya avatar unni332265 avatar yacobby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

human-detection-and-tracking's Issues

video for test

hello
can you send me a video to test the project,
i used a video found on the net but i got just this result

E:\peopleTracking\pytracking\Human-detection-and-Tracking-master\Human-detection-and-Tracking-master\videos\v1.mp4*.mp4
[]

Labelling Issue

Issues should contain the following details which increases the probability of it get resolved quickly

when the any of the face is detected from camera it shows label dynamically changing. like 4,7,22,34,53
so i m not able to understand what are these labels..

looking forward to this.
thanks..

python3 opencv 3.4.1

I have read your issue #25 , but my problem still persists.

OpenCV(3.4.1) Error: Unspecified error (The node is neither a map nor an empty collection) in cvGetFileNodeByName, file /io/opencv/modules/core/src/persistence_c.cpp, line 753
Traceback (most recent call last):
  File "main.py", line 137, in <module>
    recognizer.read("model.yaml")
cv2.error: OpenCV(3.4.1) /io/opencv/modules/core/src/persistence_c.cpp:753: error: (-2) The node is neither a map nor an empty collection in function cvGetFileNodeByName

This is the error, you mentioned to change line 62,
recognizer.save("cont.yaml") to
recognizer.save("model.yaml")
but this is my line 62
predict_tuple = recognizer.predict(frame_orginal_grayscale)

I am not able to figure out, what's wrong?

Port to python2

Port this repository to python2 from python3

  • code should support python2.7 and opencv3.x
  • other useful scripts in scripts folder should also be converted to python2
  • make a separate branch for python2
  • multiple pull requests are allowed for this.

๐Ÿ˜ƒ

ValueError: not enough values to unpack (expected 3, got 2)

I try to run your project
but it can not be run

So this is an error

$ python3 main.py --videos videos
/Users/teamzoon/Downloads/Human-detection-and-Tracking-master/videos/6.mp4*.mp4
['/Users/teamzoon/Downloads/Human-detection-and-Tracking-master/videos/6.mp4']
(360, 640, 3)
(360, 640, 3)
Traceback (most recent call last):
File "main.py", line 160, in
temp = background_subtraction(previous_frame, frame_resized_grayscale, min_area)
File "main.py", line 118, in background_subtraction
im2, cnts, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)

core dump occurred when running ./humandetect ../GEM_time.mp4

Hi Sir,
core dump occurred when I type the following command
./humandetect ../GEM_time.mp4
opencv_contrib-3.4.1/modules/face/src/facerec.cpp, line 61
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.1) /opencv_contrib-3.4.1/modules/face/src/facerec.cpp:61: error: (-2) File can't be opened for reading! in function read

Aborted (core dumped)

Could you kindly to give a hint about how to solve this issue?

snowuyl

can this project run on windows

Issues should contain the following details which increases the probability of it get resolved quickly

  • Exact error or Issue details
  • OpenCV Version
  • Python Version
  • Operating System
  • Changes done, if any in the original code

python3 opencv 3.4.1

Issues should contain the following details which increases the probability of it get resolved quickly

  • Exact error or Issue details
  • OpenCV Version
  • Python Version
  • Operating System
  • Changes done, if any in the original code

OpenCV Error: Unspecified error (The node is neither a map nor an empty collection)

OpenCV Error: Unspecified error (The node is neither a map nor an empty collection) in cvGetFileNodeByName, file C:\projects\opencv-python\opencv\modules\core\src\persistence.cpp, line 891
Traceback (most recent call last):
File "main.py", line 137, in
recognizer.read("model.yaml")
cv2.error: C:\projects\opencv-python\opencv\modules\core\src\persistence.cpp:891: error: (-2) The node is neither a map nor an empty collection in function cvGetFileNodeByName

Earlier there was ' recognizer.load("model.yaml") ' in the original code but there is no attribute 'load' attribute in new version of current opencv which has been replaced by 'read'.

Suggestions for integrating CUDA

Human detection and face detection is pretty slow with using CPU. opencv provides framework for integrating CUDA but there is no native support by opencv. Suggest a way to use CUDA framework with this code. PR are welcome ๐Ÿ›ฉ๏ธ ๐Ÿ˜„

Port to C++

Port this repo to C++

  • code should be written in C++.
  • make a separate branch for this.
  • functionality should be same and performance should be better.
  • useful scripts in scripts folder should also be ported.
  • multiple pull requests are allowed for this but make sure that you are on correct path
    ๐Ÿ˜„ ๐Ÿ˜„

imutils import error

Traceback (most recent call last):
File "main.py", line 5, in
import imutils
ModuleNotFoundError: No module named 'imutils'

Incompatibility in Opencv3 and opencv_contrib

Hi, ITCoders,
I want to run this proj to watch the demo, but i found some incompatibilities in opencv3
As I have searched in google, I change two line of your code.
But I still have an error with no idea.

At line 16, I changed it to recognizer = cv2.face.LBPHFaceRecognizer_create()
At line 137, I changed it to recognizer.read("model.yaml")

but still have an error:

Traceback (most recent call last):
File "main.py", line 137, in
recognizer.read("model.yaml")

cv2.error: /home/ssss/opencv/opencv/modules/core/src/persistence.cpp:891: error: (-2) The node is neither a map nor an empty collection in function cvGetFileNodeByName

Can you give me some help ? Thanks !

this code with python3.6 and opencv3.4

I have a problem and I can not run my code. I have python 3.6 with opencv 3.4. It seems coding is not compatible with this version so I changed it a little.
At first I had problem with line 16: recognizer = cv2.face.createLBPHFaceRecognizer()
so I changed it into recognizer = cv2.face.LBPHFaceRecognizer_create()

then I had problem with line 137: recognizer.load("model.yaml")
And I changed it again to: recognizer.read("model.yaml")

But now I found the error saying : error: (-2) The node is neither a map nor
an empty collection in function cvGetFileNodeByName

And I have no idea what to do with this.

make code looks good.

In main.py convert the code to a class and write main function again ๐Ÿš€ ๐ŸŽง :octocat:

neural network

hi, i want to ask what kind of neural network you used in order to detect human or face in your project and how did you train it?

Can I able to find coordinate values of bounding boxes.

Issues should contain the following details which increases the probability of it get resolved quickly

  • Exact error or Issue details
  • OpenCV Version
  • Python Version
  • Operating System
  • Changes done, if any in the original code

run error

i do this steps to run the code:

cd to Human-detection-and-Tracking-master
2)python3 main.py /video
i get that error again.
usage: main.py [-h] -v VIDEOS
main.py: error: the following arguments are required: -v/--videos

error in reading 'model.yaml'

Hi,
I run 'python3 main.py -v video/' and the below error occured:

Traceback (most recent call last):
File "main.py", line 140, in
recognizer.read("model.yaml")
cv2.error: OpenCV(4.1.0) /io/opencv/modules/core/src/persistence.cpp:2046: error: (-215:Assertion failed) isMap() in function 'operator[]'

I wana run the code on ubuntu 16.04 and opencv(4.1) and python 3.5.
what's wrong?

thanks

main.py returns assertion failed

Issues should contain the following details which increases the probability of it get resolved quickly

  • Exact error or Issue details
D:\python\Human-detection-and-Tracking-master>python main.py -v D:\python\Human-detection-and-Tracking-master\videos
D:\python\Human-detection-and-Tracking-master\videos\VID-20181220-WA0006.mp4*.mp4
['D:\\python\\Human-detection-and-Tracking-master\\videos\\VID-20181220-WA0006.mp4']
Traceback (most recent call last):
  File "main.py", line 140, in <module>
    recognizer.read("model.yaml")
cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\core\src\persistence.cpp:2047: error: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'
  • OpenCV Version - 4.0
  • Python 3.x
    ** Windows 10*
  • Changes done, if any in the original code - nope !

['C:\\Users\\jatin\\Downloads\\Human-detection-and-Tracking-master\\Human-detection-and-Tracking-master\\video\\1.mp4'] (720, 1280, 3) (450, 800, 3) Traceback (most recent call last): File "main.py", line 160, in <module> temp = background_subtraction(previous_frame, frame_resized_grayscale, min_area) File "main.py", line 118, in background_subtraction im2, cnts, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) ValueError: not enough values to unpack (expected 3, got 2)

Issues should contain the following details which increases the probability of it get resolved quickly

  • Exact error or Issue details
  • OpenCV Version
  • Python Version
  • Operating System
  • Changes done, if any in the original code

openCV Problem

I am getting this error . please anyone help me on this
File "main.py", line 17, in
recognizer = cv2.face.LBPHFaceRecognizer_create()
AttributeError: module 'cv2.cv2' has no attribute 'face'

how to apply usb-camera to this codes?

Issues should contain the following details which increases the probability of it get resolved quickly

i am sorry to bother you .I wanna know how to use usbcamera to run your demo?
i am using opencv3.4.0 python3.4.0
ubantu in jetsontx2

Installation Issues

The given link for linux installation of opencv is meant to install opencv for python 2.7 not python3. As a result upon following those instructions import cv2 works in python command line but not for python 3.
screenshot from 2017-03-05 01-20-16

Also upon trying to run code using python 2.7, the output is empty -

screenshot from 2017-03-05 00-17-08

It would be very helpful if you could add the sample input video for checking the code.

The node is neither a map nor an empty collection in function 'cvGetFileNodeByName'

Hello everybody,

When I run main.py, I get the following error :

Traceback (most recent call last):
  File "/home/mounir/PycharmProjects/Human-detection-and-Tracking-master/main.py", line 137, in <module>
    recognizer.read("model.yaml")
cv2.error: OpenCV(4.0.0-pre) /home/mounir/opencv/modules/core/src/persistence_c.cpp:757: error: (-2:Unspecified error) The node is neither a map nor an empty collection in function 'cvGetFileNodeByName'

I have the latest OpenCV version installed

Details

  • Exact error or Issue details
  • **OpenCV Version ** : 4.0.0-pre (I know you told us to opt for 3.1.1
  • Python Version : 3.6
  • Operating System : Ubuntu 18.04
  • Changes done, if any in the original code : Yes, some changes have been done.

recognizer = cv2.face.LBPHFaceRecognizer_create()
instead of
recognizer = cv2.face.createLBPHFaceRecognizer()

and

recognizer.read("model.yaml")
instead of
recognizer.load("model.yaml")

Thanks for your help !

error in runing code

  • Exact error or Issue details
    when i run the code with this command python3 main.py in terminal i got this following error :
    usage: main.py [-h] -v VIDEOS
    main.py: error: the following arguments are required: -v/--videos
    OpenCV Version = 3.2.0
    Python Version = 3.6.5
    Operating System = ubuntu 18.04

Running the code

I am trying to recognize faces from a .mp4 file. I already have some sample images of faces in my database. When I run the program, I want it to recognize the faces from the video. The location of video file is passed as a command line argument sys.argv[1].

code :

import cv2
import numpy as np
import os
import sqlite3
import pickle
from PIL import Image
import sys


faceDetect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml');



rec = cv2.createLBPHFaceRecognizer();

rec.load("recognizer\\trainningData.yml")
path ='dataSet'

font=cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX,1,1,0,2,2)
font2=cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX,1,1,0,1,1)
def getProfile(id):
    conn=sqlite3.connect("FaceBase.db")
    cmd="SELECT * FROM People WHERE ID="+str(id)
    cursor = conn.execute(cmd)
    profile=None
    for row in cursor:
        profile=row
    conn.close()
    return profile


cam = cv2.VideoCapture(sys.argv[1])


while cam.isOpened():

    ret,img = cam.read()

    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    faces = faceDetect.detectMultiScale(gray,1.3,5);
    for(x,y,w,h) in faces :
        cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
        id,conf=rec.predict(gray[y:y+h,x:x+w])

        if conf<60   :
                        profile=getProfile(id)
            if(profile!=None):
                cv2.cv.PutText(cv2.cv.fromarray(img),str(profile[1]),(x,y+h+30),font,255);
                cv2.cv.PutText(cv2.cv.fromarray(img),str(profile[2]),(x,y+h+60),font,255);
                cv2.cv.PutText(cv2.cv.fromarray(img),str(profile[3]),(x,y+h+90),font,255);
                print("{} is Correctly Recognized with confidence {}".format(id,conf))

        else :
             cv2.cv.PutText(cv2.cv.fromarray(img),'unkown',(x,y+h+30),font,255);


    cv2.imshow("Face",img);
    if (cv2.waitKey(1) == ord('q')):
        break;
cam.release()
cv2.destroyAllWindows()

The command in command prompt is

C:\FaceRocogProject\Face Recog sqlite\python Recognize_video.py 'C:\FaceRocogProject\Face Recog sqlite\test.mp4'

This node is not a map nor an empty collection

Hello,

I have tried to follow your instructions from Issue#25, but could not manage to make it work. When I am trying to run the command py create_face_model.py -i data/ I am getting the following error:
ImportError: No module named cv2

Also, if I erase the first line on create_face_model.py, #!/usr/bin/python, I am getting this error:
C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:636: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If yo
u are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage

Thank you in advance.
I am using python 3.6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.