Skip to main content

Heimarobot Python Library

Project description

Heimarobot Python Library

License

The code of heimarobot Python Library is released under the MIT License. There is no limitation for both academic and commercial usage.

本项目具备如下推理功能:

  • 人脸检测
  • 人脸识别
  • 人脸年龄与性别识别
  • 人脸106个特征点
  • 换脸

B站演示地址: https://space.bilibili.com/485304569

安装

pip安装

pip install heimarobot==0.0.1

若安装失败,请指定安装路径

pip install heimarobot==0.0.1 -i https://pypi.org/project

导入权重文件

在用户目录下新建.heimarobot文件夹

C:\Users\KAI\.heimarobot

从百度网盘中下载权重文件,并解压释放进去

功能演示

人脸检测

from heimarobot import FaceDetection
from heimarobot import draw_faces
import cv2 as cv
import numpy as np

if __name__ == '__main__':
    face_detection = FaceDetection()
    img = cv.imread('images/trump1.jpg')
    faces = face_detection.predict(img)
   
    dst = draw_faces(img,faces)
    
    cv.imshow('img',dst)
    cv.waitKey(0)

人脸识别

from heimarobot import FaceRecognition
import cv2 as cv
import numpy as np

if __name__ == '__main__':
    face_recognition = FaceRecognition()
    trump1 = cv.imread('images/trump1.jpg')
    trump2 = cv.imread('images/trump2.jpg')
    
    # 获取人脸特征
    feats1 = face_recognition.predict(trump1)
    feats2 = face_recognition.predict(trump2)
    
    sim = face_recognition.compute_sim(feats1,feats2)

    # 根据相似度,输出结果
    if sim<0.2:
        conclu = 'they are not the same'
    elif sim>=0.2 and sim<0.28:
        conclu = 'they are looks like the same people'
    else:
        conclu = 'they are the same people'

    print(sim,conclu)

    cv.imshow('trump1',trump1)
    cv.imshow('trump2',trump2)
    cv.waitKey(0)

人脸年龄与性别识别

from heimarobot import FaceAttribute
from heimarobot import draw_faces
import cv2 as cv
import numpy as np

if __name__ == '__main__':
    face_attr = FaceAttribute()
    img = cv.imread('images/trump1.jpg')
    
    # 获取人脸特征
    faces = face_attr.predict(img)
    # 1 表示男性, 0,表示女性
    print(faces[0])
    dst = draw_faces(img,faces)
    cv.imshow("images/1.jpg",dst)
    cv.waitKey(0)

人脸106个特征点

from heimarobot import FaceLandmark
import cv2 as cv
import numpy as np
from heimarobot import draw_faces,draw_landmarks

if __name__ == '__main__':
    face_attr = FaceLandmark()
    trump1 = cv.imread('images/trump1.jpg')

    # 获取人脸特征106个特征点
    faces = face_attr.predict(trump1)

    retimg = draw_landmarks(trump1,faces)
    cv.imshow('trump1_landmark',retimg)
    cv.waitKey(0)

换脸

from heimarobot import FaceSwapper

import cv2 as cv
import numpy as np

if __name__ == '__main__':
    face_swapper = FaceSwapper()
    trump1 = cv.imread('images/trump1.jpg')
    target = cv.imread('images/1.jpg')

    sourceFace = face_swapper.get_source_face(trump1)

    dst = face_swapper.predict(sourceFace, target)
   
    cv.imshow("trump1",trump1)
    cv.imshow("1",target)
    cv.imshow("dst", dst)
    cv.waitKey()

若运行代码出现一下错误,则是 opencv-python-headlessopencv-python版本不匹配的原因

cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

卸载 opencv-python-headless,重新安装

pip install opencv-python-headless==4.6.0.66
pip install opencv-python==4.6.0.66
pip install opencv-contrib-python==4.6.0.66

Project details


Download files

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

Source Distribution

heimarobot-0.0.3.tar.gz (479.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

heimarobot-0.0.3-cp39-cp39-win_amd64.whl (884.6 kB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file heimarobot-0.0.3.tar.gz.

File metadata

  • Download URL: heimarobot-0.0.3.tar.gz
  • Upload date:
  • Size: 479.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.65.0 CPython/3.9.13

File hashes

Hashes for heimarobot-0.0.3.tar.gz
Algorithm Hash digest
SHA256 b6f412a2caf3b64b0f077c4a132eb0da93f88fb7ea49875499326b235b81385f
MD5 69453b51f33be35212eb45d35f2ba4eb
BLAKE2b-256 82592b1607121db976b0ed2d16764af667c568805d2b72376e52f08e6d48deeb

See more details on using hashes here.

File details

Details for the file heimarobot-0.0.3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: heimarobot-0.0.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 884.6 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.65.0 CPython/3.9.13

File hashes

Hashes for heimarobot-0.0.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c3d6d6701400d68d3f05e2f9f327ed068950d61dd517df033f0120d04f834d65
MD5 44ff69fb86f34de51c3f4bbfd7914493
BLAKE2b-256 a67e0b557df5245ed18e1362489204d2c2b602137e72830dec718943e670b865

See more details on using hashes here.

Supported by

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