Skip to content

erwingforerocastro/mvfy_visual

Repository files navigation

mvfy_visual

Python face recognition library for detection of unknowns in a closed system

Tutorials

Features

Detection of Unknows

detector-unknows

This process consists of detecting multiple faces, creating the encodings for all of them, over time as users become more frequent, they will be detected as knowns, while users whose detections are infrequent or have not been detected before will be detected as unknown.

  • To determine if a user is known, the face identifier will be taken, this would determine the authenticity of the user and in turn said detection will serve to determine the frequency of stay, to determine if one of these users is known, it is calculated as follows:

knowledge

    • Kmin - is a umbral of minimum date to knonwn a user (example: 7 days)

    image

    • typeDate - (days, months, years)
    • nType - number of typedate

    • Freq - is a frequency of all previous detections of that user

    image

    • prevDays - are that previous frequencies saved

    • Fmin - is a umbral of minimum frequency
    • Δf - is the difference between the current date and the user's initial insertion date.

    Δf

    • dateNow - date now
    • dateuser - first detection of that user

Running the Examples

Clone the repository, and do the installation before:

git clone https://github.com/erwingforerocastro/mvfy_visual

Running the Flask Examples

pipenv install
cd /examples/example-flask
python main.py

Installation

Requirements

  • Python 3.7+
  • Windows (linux not officially supported, but might work)

Installation Options:

Installing on Windows

Required for OpenCv

  • For run OpenCv sometimes you need this building tools.

Installing visual studio

Installing Face Recognition

  git clone https://github.com/RvTechiNNovate/face_recog_dlib_file.git
  cd face_recog_dlib_file

dlib is required for face recognition library

  Python 3.7:
  pip install dlib-19.19.0-cp37-cp37m-win_amd64.whl

  Python 3.8:
  pip install dlib-19.19.0-cp38-cp38-win_amd64.whl

Installing on Mac or Linux (Beta)

First, make sure you have dlib already installed with Python bindings:

Then, make sure you have cmake installed:

brew install cmake

Finally, install this module from pypi:

pip install mvfy_visual

Alternatively, you can try this library with Docker, see this section.

If you are having trouble with installation, you can also try out a pre-configured VM.

Installing on an Nvidia Jetson Nano board

  • Jetson Nano installation instructions
    • Please follow the instructions in the article carefully. There is current a bug in the CUDA libraries on the Jetson Nano that will cause this library to fail silently if you don't follow the instructions in the article to comment out a line in dlib and recompile it.

Getting Started

Detection of unknowns

Receiver

The process requires capture images to be processed, for this, the receivers allow connect with multiple sources of videos.

For capture the video of cam only use the class <ReceiverIpCam>, and pass the url:

from mvfy.visual.receiver import ReceiverIpCam

detector = ReceiverIpCam(
  ip_cam="rtsp://user:password@ip:port/h264_ulaw.sdp"
)

Detector

After receive the image send by the Receiver, the process requires one detector, you could use the classes inside the module detector.

For detect all unknown faces in an image you can use the DetectorUnknows class. Returns <DetectorUnknows>:

from mvfy.visual.detector import DetectorFaces

umbral = 0.7
detector_knows = DetectorFaces(tolerance_comparation= 1 - umbral)
detector_unknows = DetectorFaces(tolerance_comparation= 1 - umbral)
  • "tolerance_comparation" is a value to compare faces, less is more strict

Streamer

After process the image, it will be send to the webbrowser trough the streamer.

For this example we used the FlaskStreamer, you need first install the module of Flask to use it. Returns FlaskStreamer:

from mvfy.visual.streamer import FlaskStreamer

streamer = FlaskStreamer()
  • streamer is a generator of images (bytes) post-processed ready to send

Systems

when you have instantiated all of the above sub-instances, you simply pass them through the Systems.

For this example we used the VisualKnowlege, you need first install the module of Flask to use it:

  • for use is require the next:
    • Receiver - for getting the images
    • detector_knowns - for detect the faces of knowns users
    • detector_unknowns - for detect the faces of unknowns users
    • streamer - to send result image
from mvfy.visual.generator import VisualKnowledge

visual = VisualKnowledge(
    detector_knows=detector_knows,
    detector_unknows=detector_unknows,
    receiver=receiver,
    streamer=streamer,
    ...
)

A complete example:

import asyncio
import threading
from time import time

from flask import Flask, Response, render_template_string
from flask_cors import CORS

from mvfy.utils import constants as const, index as utils
from mvfy.visual.detector import DetectorFaces
from mvfy.visual.generator import VisualKnowledge
from mvfy.visual.receiver import ReceiverIpCam
from mvfy.visual.streamer import FlaskStreamer

app = Flask(__name__)
CORS(app, resources={r"*": {"origins": "*"}})

receiver = ReceiverIpCam(ip_cam="rtsp://mvfy:mvfy@192.168.1.4:8080/h264_ulaw.sdp")
detector_knows = DetectorFaces(tolerance_comparation= 1 - 0.7)
detector_unknows = DetectorFaces(tolerance_comparation= 1 - 0.7)
streamer = FlaskStreamer()

visual = VisualKnowledge(
    detector=detector,
    receiver=receiver,
    streamer=streamer,
    type_service=const.TYPE_SERVICE["LOCAL"],
    db_properties="mongodb://localhost:27017/",  # type: ignore
    db_name="mvfy",
    max_descriptor_distance=0.7,
    min_date_knowledge=const.DAYS(7),
    type_system=const.TYPE_SYSTEM["OPTIMIZED"],
    features=features,
    title="mvfy_1",
)


@app.route("/")
def index():
    return streamer.get_template()


@app.route("/stream_video")
def stream_video() -> Response:
    return Response(streamer, mimetype="multipart/x-mixed-replace; boundary=frame")


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8001)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published