簡體   English   中英

如何通過實現自己的 CNN 並從頭開始訓練來構建人臉檢測應用程序?

[英]How can I build a face detection aplication by implementing my own CNN and train it from scratch?

該應用程序僅獲取一些圖像並在存在的面部周圍繪制一些矩形。 我使用 Python 和 keras 制作的一些 CNN 進行圖像分類 Face 和 NonFace 這里是我使用的圖像類型link 我唯一的問題是我不太了解如何使用 CNN 從圖像中檢測多個人臉,我試圖驗證圖像的每一幀,但這需要很長時間,而且一點都不好。 我可以訓練 model 以實際返回我的臉的位置,還是我必須制定一個搜索人臉的算法? 謝謝,任何幫助都會非常感謝。

看看 YOLO 算法,它在圖像上使用網格並輸出邊界框,為您提供 object 的位置。

您可以使用 mtcnn 檢測圖像中的所有人臉。 代碼如下所示

from mtcnn import MTCNN
import os
import cv2
detector = MTCNN()
dest_dir=r'C:\Temp\people\storage\cropped' # specify where to save the images
filename=r'C:\Temp\people\storage\34.png' # specify the file name full path
try:
    img=cv2.imread(filename) # filename must be full path to the image
    shape=img.shape # will cause an exception if image was not read properly
    data=detector.detect_faces(img)                
    if data ==[]:
        print ('no faces were detected for file ', filename)
    else:
        for i, faces  in enumerate(data):
            box= faces['box']
            if box != []:
                box[0]= 0 if box[0]<0 else box[0]
                box[1]= 0 if box[1]<0 else box[1]            
                cropped_img=img[box[1]: box[1]+box[3],box[0]: box[0]+ box[2]]               
                fname=os.path.split(filename)[1]
                index=fname.rfind('.')
                fileid=fname[:index]
                fext=fname[index:]
                fname=fileid + '-' +str(i) + fext                
                save_path=os.path.join(dest_dir,fname )                
                cv2.imwrite(save_path, cropped_img)
except:
    print(' an error occurred')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM