Skip to main content

MTCNN face detection using OpenCV

Project description

MTCNN-OpenCV

MTCNN Face Detector using OpenCV, no reqiurement for tensorflow/pytorch.

INSTALLATION

  • pip3 install opencv-python or pip3 install opencv-python-headless
  • pip3 install mtcnn-opencv

USAGE

import cv2
from mtcnn_cv2 import MTCNN

detector = MTCNN()
test_pic = "t.jpg"

image = cv2.cvtColor(cv2.imread(test_pic), cv2.COLOR_BGR2RGB)
result = detector.detect_faces(image)

# Result is an array with all the bounding boxes detected. Show the first.
print(result)

if len(result) > 0:
    keypoints = result[0]['keypoints']

    cv2.rectangle(image,
                  (bounding_box[0], bounding_box[1]),
                  (bounding_box[0]+bounding_box[2], bounding_box[1] + bounding_box[3]),
                  (0,155,255),
                  2)

    cv2.circle(image,(keypoints['left_eye']), 2, (0,155,255), 2)
    cv2.circle(image,(keypoints['right_eye']), 2, (0,155,255), 2)
    cv2.circle(image,(keypoints['nose']), 2, (0,155,255), 2)
    cv2.circle(image,(keypoints['mouth_left']), 2, (0,155,255), 2)
    cv2.circle(image,(keypoints['mouth_right']), 2, (0,155,255), 2)

    cv2.imwrite("result.jpg", cv2.cvtColor(image, cv2.COLOR_RGB2BGR))

# 生成标记了的人脸的图片
with open(test_pic, "rb") as fp:
    marked_data = detector.mark_faces(fp.read())
with open("marked.jpg", "wb") as fp:
    fp.write(marked_data)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

mtcnn_opencv-1.0.2-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

Details for the file mtcnn_opencv-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: mtcnn_opencv-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3

File hashes

Hashes for mtcnn_opencv-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 219e9beb241739166c006c427f9f05cb4fe9fad7fb386ed91216af1b945fb3d2
MD5 b3dff7a1825d7ea02089f51b3fff433d
BLAKE2b-256 dd21d85a618d1ad84ce7703660c83d9e5536641e2907250feafe5c62c52ec530

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page