1000人脸关键点大pk

Face++:

Face⁺⁺

1000个全脸关键点,api,整体效果最好,

请求代码:

import base64
import io
import os
import traceback
from json import JSONDecoder

import PIL.Image as Image
import cv2
import numpy as np
import requests
import base64

from misc import is_url, download_image

API_KEY = "zYVNURhMvDx47H-f5au2YKKQKNoLRKOO"
API_SECRET = "Sme_EoOr1oOl2w1ZLFnloP206mKZrEV8"


def image_to_base64(img, ext='.png'):
    retval, buf = cv2.imencode(ext, img)
    return base64.b64encode(buf).decode()


def image_from_base64(img_b64):
    return cv2.imdecode(np.fromstring(base64.b64decode(img_b64.encode()), np.uint8), cv2.IMREAD_UNCHANGED)


class FacePPAPI(object):

    def __init__(self):
        pass

    def thousandlandmark(self, img):
        http_url = 'https://api-cn.faceplusplus.com/facepp/v1/face/thousandlandmark'
        data = {"api_key": API_KEY,
                "api_secret": API_SECRET,
                "return_landmark": "all",
                }

        files = {"image_file": self.__get_image_data(img)}
        resp = requests.post(http_url, data=data, files=files, timeout=5)
        req_con = resp.content.decode('utf-8')
        data_dict = JSONDecoder().decode(req_con)
        return data_dict

    @staticmethod
    def __get_image_data(img):
        image_data = None
        if isinstance(img, bytes):
            image_data = img
        elif isinstance(img, str):
            if os.path.exists(img):
                img_path = img
                with open(img_path, "rb") as image_file:
                    image_data = image_file.read()
                return image_data
            elif is_url(img):
                img_url = img
                return download_image(img_url, timeout=5)

            try:
                image_data = base64.b64decode(img.encode())
            except:
                raise RuntimeError("不是base64格式字符串")
            return image_data
        elif type(img).__module__ == np.__name__:
            retval, image_data = cv2.imencode('.jpg', img)
            return image_data
        elif isinstance(img, Image.Image):
            img_byte_arr = io.BytesIO()
            img.save(img_byte_arr, format='jpg')
            image_data = img_byte_arr.getvalue()
            return image_data
        return image_data


facepp_api = FacePPAPI()


if __name__=="__main__":
    data_dir = "./images/"
    out_dir= "./out/"
    radius_lists = ["right_eye_pupil_radius", "left_eye_pupil_radius"]
    for name in os.listdir(data_dir):
        print(name)
        fullname = os.path.join(data_dir, name)
        image = cv2.imread(fullname)
        data_dict = facepp_api.thousandlandmark(image)
        for key, key_value in data_dict["face"]["landmark"].items():
            for kkey, value in key_value.items():
                if kkey not in radius_lists:
                    cv2.circle(image, (value["x"], value["y"]), 1, (255,255,255),4)
        cv2.imwrite(os.path.join(out_dir,name), image)
import re
import traceback

import requests
import requests.compat

CAPITALS = re.compile('([A-Z])')


def is_url(url):
    try:
        res = requests.compat.urlparse(url)
        if not res.scheme or not res.netloc or not "." in res.netloc:
            return False
        res = requests.compat.urlparse(requests.compat.urljoin(url, "/"))
        if not res.scheme or not res.netloc or not "." in res.netloc:
            return False
    except:
        return False
    return True


def download_image(url, timeout=10):
    image_file = None
    try:
        response = requests.get(url, timeout=timeout)
        if response.status_code == 200:
            image_file = response.content
    except:
        traceback.print_exc()

    return image_file

TengineKit:

GitHub - OAID/TengineKit: TengineKit - Free, Fast, Easy, Real-Time Face Detection & Face Landmarks & Face Attributes & Hand Detection & Hand Landmarks & Body Detection & Body Landmarks & Iris Landmarks & Yolov5 SDK On Mobile.https://github.com/OAID/TengineKit

424个全脸关键点,c++ so,居然依赖libcurl的库,慎重使用,整体效果中等

FaceLandmark1000:

https://github.com/Single430/FaceLandmark1000

1000个全脸关键点,python,onnx,整体效果最差

最终效果对比:

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值