GithubHelp home page GithubHelp logo

sqoshi / landmark-predictor Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 2.83 MB

Python wrapper for the dlib model with automated model download and predict functionalities.

License: MIT License

Python 100.00%
dlib python machine-learning landmark-detection

landmark-predictor's Introduction

landmark-predictor

Project is a part of series related with my Bachelor of Science Thesis research.

Table Of Contents

General

Python wrapper for the dlib model with automated model download and predict functionalities.

Package has been created to allow automatic dlib's predictor handling ( download, get, find , store)

Installation

pip install git+https://github.com/sqoshi/landmark-predictor.git

Usage

from landmarks_predictor import LandmarksPredictor

landmarks_predictor = LandmarksPredictor(
        predictor_fp=None, show_samples=True,
        face_detection=True, auto_download=True
)

images = os.listdir(path/to/images) # absolute paths

landmarks_predictor.detect(images)

Automatic download

[22:48:43][INFO] - Looking for shape predictor in '/home/Documents/bsc-thesis/mask-imposer/venv/lib/python3.8/site-packages'
[22:48:43][INFO] - Looking for shape predictor in '/home/Documents/bsc-thesis/mask-imposer'
[22:48:43][WARNING] - Shape predictor not found.
Would you like to download 64 [MB] model ?
y
[22:48:45][WARNING] - Downloading shape `shape_predictor_68_face_landmarks.bz2` ...
100% |#############################################################################################################################################|
[22:53:45][INFO] - Predictor downloaded.

Code Example

    def detect(self, images_list: List[Union[str, tuple]], create_map: bool) -> None:
        """Creates landmark collection.

        During creation may optionally display samples with drawn landmarks.
        May detect face boxes, but it is preferred to pass images as stated in readme.
        """
        for img_path in images_list:
            image = Image(img_path)
            try:
                rect = self._detect_face_rect(image)  # detect rectangles with faces

                shape = self._predictor(image.get_gray_img(), rect)  # detect landmarks

                self._landmarks_collection[str(image)] = _shape_to_dict(shape)

                if create_map:
                    self.fake_map[str(image)] = image.img

                if self._should_display_samples:
                    self._display_sample(image, rect, shape)

            except NotImplementedError:  # must be changed
                logger.warning(f"Landmarks not detected on {image}.")
                continue
        self._check_fails(images_list)
        logger.info("Detection finished.")

landmark-predictor's People

Contributors

sqoshi avatar

Watchers

James Cloos avatar  avatar

Forkers

raghuraj0

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.