人臉檢測——生成矯正人臉——cascade cnn的思想, 但是mtcnn的效果貌似更贊
簡單粗暴,不多說,直接程式碼吧:(這個程式碼實在上篇部落格的基礎上:人臉檢測——AFLW準備人臉)
先要生成AFLW_ann.txt。
import os
from PIL import Image
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
import cv2
import numpy as np
def crop_for_cal(sn, xn, yn, n):
with open('AFLW_ann.txt','r') as f:
lines = f.readlines()
save_dir1 = 'data_prepare/cal_positive_'+str(n)+'_12'
save_dir2 = 'data_prepare/cal_positive_'+str(n)+'_24'
save_dir3 = 'data_prepare/cal_positive_'+str(n)+'_48'
if os.path.exists(save_dir1)==False:
os.makedirs(save_dir1)
if os.path.exists(save_dir2)==False:
os.makedirs(save_dir2)
if os.path.exists(save_dir3)==False:
os.makedirs(save_dir3)
for idx, line in enumerate(lines):
spl1 = line.strip().split(' ')
image_path = spl1[0]
x = int(spl1[1])
y = int(spl1[2])
w = int(spl1[3])
h = int(spl1[4])
x = int(x-xn*w/sn)
y = int(y-yn*h/sn)
w = int(w/sn)
h = int(h/sn)
# image = Image.open(image_path)
image = cv2.imread(image_path)
if image is None:
continue
if x<=0 and y<=0 and w<=0 and h<=0:
continue
box = (x, y, x+w, y+h)
# patch = image.crop(box)
patch = image[box[1]:box[3], box[0]:box[2], :]
if patch is None:
continue
if patch.shape[0]<10 and patch.shape[1]<10:
continue
#patch1 = patch.resize((12, 12))
#patch2 = patch.resize((24, 24))
#patch3 = patch.resize((48, 48))
patch1 = cv2.resize(patch, (12, 12))
patch2 = cv2.resize(patch, (24, 24))
patch3 = cv2.resize(patch, (48, 48))
spl2 = image_path.split('/')
image_name = spl2[-1]
save_path1 = save_dir1+'/'+str(idx)+image_name + '.jpg'
save_path2 = save_dir2+'/'+str(idx)+image_name + '.jpg'
save_path3 = save_dir3+'/'+str(idx)+image_name + '.jpg'
#patch1.save(save_path1, 'jpeg')
#patch2.save(save_path2, 'jpeg')
#patch3.save(save_path3, 'jpeg')
cv2.imwrite(save_path1, np.array(patch1))
cv2.imwrite(save_path2, np.array(patch2))
cv2.imwrite(save_path3, np.array(patch3))
if __name__ == '__main__':
s_set = (0.83, 0.91, 1.0, 1.10, 1.21)
x_set = (-0.17, 0, 0.17)
y_set = (-0.17, 0, 0.17)
n = 0
for x in x_set:
for y in y_set:
for s in s_set:
n = n + 1
crop_for_cal(s, x, y, n)
如果幫到你了,請讚賞支援:
相關文章
- MTCNN人臉檢測與校準(5特徵點)CNN特徵
- 人臉檢測識別,人臉檢測,人臉識別,離線檢測,C#原始碼C#原始碼
- 人臉檢測 二
- 人臉識別之人臉檢測的重要性
- 人臉檢測的harr檢測函式函式
- 人臉檢測(detection)與人臉校準(alignment)
- 人臉活體檢測
- 前端人臉檢測指南前端
- [計算機視覺]人臉應用:人臉檢測、人臉對比、五官檢測、眨眼檢測、活體檢測、疲勞檢測計算機視覺
- 人臉活體檢測人臉識別:眨眼+張口
- JavaScript人臉檢測的實現方法JavaScript
- opencv視訊人臉檢測OpenCV
- OpenCV 人臉檢測自學(3)OpenCV
- APISpace的 人臉檢測API 它來啦~API
- IOS人臉識別開發入門教程--人臉檢測篇iOS
- iOS 人臉關鍵點檢測iOS
- Android人臉檢測介紹Android
- FaceDetector 人臉檢測追蹤demo
- 人臉檢測中的AdaBoost演算法演算法
- 從零玩轉人臉識別之RGB人臉活體檢測
- OpenCv人臉檢測技術-(實現抖音特效-給人臉戴上墨鏡)OpenCV特效
- Python人臉識別微笑檢測Python
- 視訊人臉檢測——OpenCV版(三)OpenCV
- 圖片人臉檢測——OpenCV版(二)OpenCV
- Android API 人臉檢測(Face Detect)AndroidAPI
- 如何評價美顏api中人臉識別和人臉檢測的準確度?API
- 黑人人臉檢測
- canvas+face-api人臉實時檢測CanvasAPI
- 3分鐘內實現人臉檢測
- 人臉識別檢測專案實戰
- 圖片人臉檢測——Dlib版(四)
- 視訊人臉檢測——Dlib版(六)
- 人臉檢測之身份識別你需要的那些事
- TensorFlow2.0 + CNN + keras + 人臉識別CNNKeras
- 強大人臉檢測系統MTCNN可攻破?華為提出一種可複製、可靠的攻擊方法CNN
- 基於opencv實現簡單人臉檢測OpenCV
- OpenCV檢測篇(一)——貓臉檢測OpenCV
- faced:基於深度學習的CPU實時人臉檢測深度學習