pyFaceTrace


NamepyFaceTrace JSON
Version 5.0.7 PyPI version JSON
download
home_pagehttps://pypi.org/project/pyFaceTrace
Summaryeasy Face Recognition for python
upload_time2023-11-14 15:31:37
maintainer
docs_urlNone
authorKuoYuan Li
requires_python
license
keywords face recognition face trace
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Author:KuoYuan Li
[![N|Solid](https://images2.imgbox.com/8f/03/gv0QnOdH_o.png)](https://sites.google.com/ms2.ccsh.tn.edu.tw/pclearn0915)  
本程式簡單地結合dlib,opencv  測試過在windows作業系統底下可正常運行且另外提供colab版本  
讓不懂機器學習的朋友可以軟簡單地操作人臉辨識,  
程式需另外安裝 dlib  
搜尋關鍵字:whl dlib cp***  ***代表python版本 ex:cp310代表 python 3.10  
dlib whl 安裝包下載網站: (https://github.com/Murtaza-Saeed/dlib/tree/master)
  - 本套工具主要針對windows使用者設計,相依之 package 及相容性問題需自行排除  
  - dlib whl 安裝包下載後必需由檔案離線安裝 pip install ...
  - opencv whl  下載點:請下載合適的opencv版本<br>
    (https://pypi.tuna.tsinghua.edu.cn/simple/opencv-contrib-python/)  
  - Note: opencv 安裝的路徑上如果有中文會導致運作不正常,建議使用者名稱不要使用中文,或是先確認python有裝在沒有中文的路徑底下  
  - 安裝 mediapipe 會順便自動安裝 opencv ,可以直接先安裝 mediapipe  
  ```
  pip install mediapipe
  ```
※PS:  
2022/11/24 使用 python3.10 搭配  
  dlib-19.22.99-cp310-cp310-win_amd64.whl  試用成功  
  
2023/4/2  
  調整函式,適配 colab  
    (https://colab.research.google.com/drive/1ou7nWLQGl8uYLR_jUDyush9-D8ToTe8P?usp=sharing)  
  移除不常用之影像檔處理函式  
  新增直接和 opencv 協作模式  
2023/11/4  
  發現的某些 windows 作業系統如果灌  
  python3.10 搭配  
  dlib-19.22.99-cp310-cp310-win_amd64.whl  
  會產生下列錯誤:  
  from _dlib_pybin11 import * ImportError: DLL load failed: 找不到指定的程序  
    
    
  ※解決方案:
  新安裝一組 python3.11(64bit) 
  (https://www.python.org/ftp/python/3.11.6/python-3.11.6-amd64.exe)  
  搭配dlib-19.24.1-cp311-cp311-win_amd64.whl  
  ```
  pip install https://github.com/Murtaza-Saeed/dlib/raw/master/dlib-19.24.1-cp311-cp311-win_amd64.whl
  ```
  Thonny的使用者可至 工具>>選項>>直譯器>... 修改python.exe之位置,變成合適的python版本  
  vscode的使用者可按ctrl+shift+p 於上方輸入 >python:Select Interpreter 選擇合適的python版本  
  
	
	
##### Download the samples to 'train' folder(下載各種照片樣本至train資料夾)
```
import pyFaceTrace as ft  
ft.downloadImageSamples()  
```
##### work with opencv webcam process (detail)  
```
import pyFaceTrace as ft
import cv2
from PIL import ImageFont
#至train資料夾載入樣本,欲辨識之目標圖片可放入 train資料夾
ft.loadDB()
#設定文字物件
FONT = ImageFont.truetype("kaiu.ttf",50,index=0)
#webcamd 影像處理迴圈
cap = cv2.VideoCapture(0,cv2.CAP_DSHOW)
while True:
    ret, img = cap.read()
    if not ret : continue
    #取得 img 中所有人臉之矩型區域,放入rects
    rects=ft.detector(img,1)
    for rect in rects:
        #取得webcam img 中人臉之特徵向量
        fv=ft.getFeatureVector(img,rect)
        #將特徵向量和 ft.DB 中之人特徵向量做比對,找到距離最短的(dist)當作辨識結果(tag)
        tag,dist = ft.predictFromDB(fv)
        #將辨識結果顯示在 img 上
        cv2.rectangle(img,(rect.left(),rect.top()),(rect.right(),rect.bottom()),(0,0,255),3)
        img=ft.addText2Img_cv2(img,tag,FONT,position=(rect.left(),rect.top()-FONT.size-1))
    if cv2.waitKey(10) == 27: break
    # 將 img show在視窗中
    cv2.imshow('press esc to exit...', img)
cap.release()
cv2.destroyAllWindows()
```
##### work with opencv webcam process (esay)
```
import pyFaceTrace as ft
import cv2
ft.loadDB()
cap = cv2.VideoCapture(0,cv2.CAP_DSHOW)
while(True):    
    ret, img = cap.read()
    if not ret:continue
    #img=cv2.flip(img,1)
    tags,dists,rects,img = ft.predictImage(img)            
    cv2.imshow('press esc to exit...', img)
    if cv2.waitKey(10) == 27: break
    
cap.release()
cv2.destroyAllWindows()
```
### Demo with webcam
```
import pyFaceTrace as ft
ft.loadDB(folder='train')
ft.predictCam()
```
##### 比對目前webcam擷取到的人臉和指定影像檔案並計算它們之間的距離
```
import pyFaceTrace as ft  
im = ft.captureImageFromCam()
VTest = ft.getFeatureVector(im)
Vtrain = ft.loadFeatureFromPic('train\\李國源.jpg')
D=ft.dist(VTest,Vtrain)
print('距離=',D)
```
##### 載入train資料夾中所有jpg檔之特徵及tag並直接預測目前webcam擷取到的人臉對應的TAG 
```
import pyFaceTrace as ft
ft.loadDB(folder='train')
im = ft.captureImageFromCam()
VTest = ft.getFeatureVector(im)
result = ft.predictFromDB(VTest)
print(result)
```



License
----

MIT
            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/pyFaceTrace",
    "name": "pyFaceTrace",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Face recognition,Face Trace",
    "author": "KuoYuan Li",
    "author_email": "funny4875@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/82/4a/4b7a5afd2a9705e140d8737879b3f266ef8fa440ba653b2884efcf3315a8/pyFaceTrace-5.0.7.tar.gz",
    "platform": null,
    "description": "# Author:KuoYuan Li\n[![N|Solid](https://images2.imgbox.com/8f/03/gv0QnOdH_o.png)](https://sites.google.com/ms2.ccsh.tn.edu.tw/pclearn0915)  \n\u672c\u7a0b\u5f0f\u7c21\u55ae\u5730\u7d50\u5408dlib,opencv  \u6e2c\u8a66\u904e\u5728windows\u4f5c\u696d\u7cfb\u7d71\u5e95\u4e0b\u53ef\u6b63\u5e38\u904b\u884c\u4e14\u53e6\u5916\u63d0\u4f9bcolab\u7248\u672c  \n\u8b93\u4e0d\u61c2\u6a5f\u5668\u5b78\u7fd2\u7684\u670b\u53cb\u53ef\u4ee5\u8edf\u7c21\u55ae\u5730\u64cd\u4f5c\u4eba\u81c9\u8fa8\u8b58,  \n\u7a0b\u5f0f\u9700\u53e6\u5916\u5b89\u88dd dlib  \n\u641c\u5c0b\u95dc\u9375\u5b57\uff1awhl dlib cp***  ***\u4ee3\u8868python\u7248\u672c ex:cp310\u4ee3\u8868 python 3.10  \ndlib whl \u5b89\u88dd\u5305\u4e0b\u8f09\u7db2\u7ad9: (https://github.com/Murtaza-Saeed/dlib/tree/master)\n  - \u672c\u5957\u5de5\u5177\u4e3b\u8981\u91dd\u5c0dwindows\u4f7f\u7528\u8005\u8a2d\u8a08\uff0c\u76f8\u4f9d\u4e4b package \u53ca\u76f8\u5bb9\u6027\u554f\u984c\u9700\u81ea\u884c\u6392\u9664  \n  - dlib whl \u5b89\u88dd\u5305\u4e0b\u8f09\u5f8c\u5fc5\u9700\u7531\u6a94\u6848\u96e2\u7dda\u5b89\u88dd pip install ...\n  - opencv whl  \u4e0b\u8f09\u9ede:\u8acb\u4e0b\u8f09\u5408\u9069\u7684opencv\u7248\u672c<br>\n    (https://pypi.tuna.tsinghua.edu.cn/simple/opencv-contrib-python/)  \n  - Note: opencv \u5b89\u88dd\u7684\u8def\u5f91\u4e0a\u5982\u679c\u6709\u4e2d\u6587\u6703\u5c0e\u81f4\u904b\u4f5c\u4e0d\u6b63\u5e38\uff0c\u5efa\u8b70\u4f7f\u7528\u8005\u540d\u7a31\u4e0d\u8981\u4f7f\u7528\u4e2d\u6587\uff0c\u6216\u662f\u5148\u78ba\u8a8dpython\u6709\u88dd\u5728\u6c92\u6709\u4e2d\u6587\u7684\u8def\u5f91\u5e95\u4e0b  \n  - \u5b89\u88dd mediapipe \u6703\u9806\u4fbf\u81ea\u52d5\u5b89\u88dd opencv \uff0c\u53ef\u4ee5\u76f4\u63a5\u5148\u5b89\u88dd mediapipe  \n  ```\n  pip install mediapipe\n  ```\n\u203bPS:  \n2022/11/24 \u4f7f\u7528 python3.10 \u642d\u914d  \n  dlib-19.22.99-cp310-cp310-win_amd64.whl  \u8a66\u7528\u6210\u529f  \n  \n2023/4/2  \n  \u8abf\u6574\u51fd\u5f0f\uff0c\u9069\u914d colab  \n    (https://colab.research.google.com/drive/1ou7nWLQGl8uYLR_jUDyush9-D8ToTe8P?usp=sharing)  \n  \u79fb\u9664\u4e0d\u5e38\u7528\u4e4b\u5f71\u50cf\u6a94\u8655\u7406\u51fd\u5f0f  \n  \u65b0\u589e\u76f4\u63a5\u548c opencv \u5354\u4f5c\u6a21\u5f0f  \n2023/11/4  \n  \u767c\u73fe\u7684\u67d0\u4e9b windows \u4f5c\u696d\u7cfb\u7d71\u5982\u679c\u704c  \n  python3.10 \u642d\u914d  \n  dlib-19.22.99-cp310-cp310-win_amd64.whl  \n  \u6703\u7522\u751f\u4e0b\u5217\u932f\u8aa4\uff1a  \n  from _dlib_pybin11 import * ImportError: DLL load failed: \u627e\u4e0d\u5230\u6307\u5b9a\u7684\u7a0b\u5e8f  \n    \n    \n  \u203b\u89e3\u6c7a\u65b9\u6848\uff1a\n  \u65b0\u5b89\u88dd\u4e00\u7d44 python3.11(64bit) \n  (https://www.python.org/ftp/python/3.11.6/python-3.11.6-amd64.exe)  \n  \u642d\u914ddlib-19.24.1-cp311-cp311-win_amd64.whl  \n  ```\n  pip install https://github.com/Murtaza-Saeed/dlib/raw/master/dlib-19.24.1-cp311-cp311-win_amd64.whl\n  ```\n  Thonny\u7684\u4f7f\u7528\u8005\u53ef\u81f3 \u5de5\u5177>>\u9078\u9805>>\u76f4\u8b6f\u5668>... \u4fee\u6539python.exe\u4e4b\u4f4d\u7f6e\uff0c\u8b8a\u6210\u5408\u9069\u7684python\u7248\u672c  \n  vscode\u7684\u4f7f\u7528\u8005\u53ef\u6309ctrl+shift+p \u65bc\u4e0a\u65b9\u8f38\u5165 >python:Select Interpreter \u9078\u64c7\u5408\u9069\u7684python\u7248\u672c  \n  \n\t\n\t\n##### Download the samples to 'train' folder(\u4e0b\u8f09\u5404\u7a2e\u7167\u7247\u6a23\u672c\u81f3train\u8cc7\u6599\u593e)\n```\nimport pyFaceTrace as ft  \nft.downloadImageSamples()  \n```\n##### work with opencv webcam process (detail)  \n```\nimport pyFaceTrace as ft\nimport cv2\nfrom PIL import ImageFont\n#\u81f3train\u8cc7\u6599\u593e\u8f09\u5165\u6a23\u672c,\u6b32\u8fa8\u8b58\u4e4b\u76ee\u6a19\u5716\u7247\u53ef\u653e\u5165 train\u8cc7\u6599\u593e\nft.loadDB()\n#\u8a2d\u5b9a\u6587\u5b57\u7269\u4ef6\nFONT = ImageFont.truetype(\"kaiu.ttf\",50,index=0)\n#webcamd \u5f71\u50cf\u8655\u7406\u8ff4\u5708\ncap = cv2.VideoCapture(0,cv2.CAP_DSHOW)\nwhile True:\n    ret, img = cap.read()\n    if not ret : continue\n    #\u53d6\u5f97 img \u4e2d\u6240\u6709\u4eba\u81c9\u4e4b\u77e9\u578b\u5340\u57df\uff0c\u653e\u5165rects\n    rects=ft.detector(img,1)\n    for rect in rects:\n        #\u53d6\u5f97webcam img \u4e2d\u4eba\u81c9\u4e4b\u7279\u5fb5\u5411\u91cf\n        fv=ft.getFeatureVector(img,rect)\n        #\u5c07\u7279\u5fb5\u5411\u91cf\u548c ft.DB \u4e2d\u4e4b\u4eba\u7279\u5fb5\u5411\u91cf\u505a\u6bd4\u5c0d\uff0c\u627e\u5230\u8ddd\u96e2\u6700\u77ed\u7684(dist)\u7576\u4f5c\u8fa8\u8b58\u7d50\u679c(tag)\n        tag,dist = ft.predictFromDB(fv)\n        #\u5c07\u8fa8\u8b58\u7d50\u679c\u986f\u793a\u5728 img \u4e0a\n        cv2.rectangle(img,(rect.left(),rect.top()),(rect.right(),rect.bottom()),(0,0,255),3)\n        img=ft.addText2Img_cv2(img,tag,FONT,position=(rect.left(),rect.top()-FONT.size-1))\n    if cv2.waitKey(10) == 27: break\n    # \u5c07 img show\u5728\u8996\u7a97\u4e2d\n    cv2.imshow('press esc to exit...', img)\ncap.release()\ncv2.destroyAllWindows()\n```\n##### work with opencv webcam process (esay)\n```\nimport pyFaceTrace as ft\nimport cv2\nft.loadDB()\ncap = cv2.VideoCapture(0,cv2.CAP_DSHOW)\nwhile(True):    \n    ret, img = cap.read()\n    if not ret:continue\n    #img=cv2.flip(img,1)\n    tags,dists,rects,img = ft.predictImage(img)            \n    cv2.imshow('press esc to exit...', img)\n    if cv2.waitKey(10) == 27: break\n    \ncap.release()\ncv2.destroyAllWindows()\n```\n### Demo with webcam\n```\nimport pyFaceTrace as ft\nft.loadDB(folder='train')\nft.predictCam()\n```\n##### \u6bd4\u5c0d\u76ee\u524dwebcam\u64f7\u53d6\u5230\u7684\u4eba\u81c9\u548c\u6307\u5b9a\u5f71\u50cf\u6a94\u6848\u4e26\u8a08\u7b97\u5b83\u5011\u4e4b\u9593\u7684\u8ddd\u96e2\n```\nimport pyFaceTrace as ft  \nim = ft.captureImageFromCam()\nVTest = ft.getFeatureVector(im)\nVtrain = ft.loadFeatureFromPic('train\\\\\u674e\u570b\u6e90.jpg')\nD=ft.dist(VTest,Vtrain)\nprint('\u8ddd\u96e2=',D)\n```\n##### \u8f09\u5165train\u8cc7\u6599\u593e\u4e2d\u6240\u6709jpg\u6a94\u4e4b\u7279\u5fb5\u53catag\u4e26\u76f4\u63a5\u9810\u6e2c\u76ee\u524dwebcam\u64f7\u53d6\u5230\u7684\u4eba\u81c9\u5c0d\u61c9\u7684TAG \n```\nimport pyFaceTrace as ft\nft.loadDB(folder='train')\nim = ft.captureImageFromCam()\nVTest = ft.getFeatureVector(im)\nresult = ft.predictFromDB(VTest)\nprint(result)\n```\n\n\n\nLicense\n----\n\nMIT",
    "bugtrack_url": null,
    "license": "",
    "summary": "easy Face Recognition for python",
    "version": "5.0.7",
    "project_urls": {
        "Homepage": "https://pypi.org/project/pyFaceTrace"
    },
    "split_keywords": [
        "face recognition",
        "face trace"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "824a4b7a5afd2a9705e140d8737879b3f266ef8fa440ba653b2884efcf3315a8",
                "md5": "dbb842c78b6ab019f1b64fd78fbaa122",
                "sha256": "d62e5d4e21a9e83e972e29b19332e49fc174ce1242faf2e3298bb7f1598ddf16"
            },
            "downloads": -1,
            "filename": "pyFaceTrace-5.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "dbb842c78b6ab019f1b64fd78fbaa122",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12345,
            "upload_time": "2023-11-14T15:31:37",
            "upload_time_iso_8601": "2023-11-14T15:31:37.629689Z",
            "url": "https://files.pythonhosted.org/packages/82/4a/4b7a5afd2a9705e140d8737879b3f266ef8fa440ba653b2884efcf3315a8/pyFaceTrace-5.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-14 15:31:37",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pyfacetrace"
}
        
Elapsed time: 0.15395s