diff --git a/greenhat/PyPy.py b/greenhat/PyPy.py deleted file mode 100644 index a1c597f..0000000 --- a/greenhat/PyPy.py +++ /dev/null @@ -1,48 +0,0 @@ -#coding = utf-8 - -import cv2 -import dlib - -Base = 32 -img = 'ym.jpg' -hat = 'ghat.png' -Model = 'shape_predictor_5_face_landmarks.dat' - -image = cv2.imread(img) -greenhat= cv2.imread(hat,-1) -detector = dlib.get_frontal_face_detector() -predictor = dlib.shape_predictor(Model) -dets = detector(image,1) - - -for face in dets: - left,right,top,bot=face.left(),face.right(),face.top(),face.bottom() - shape = predictor(image,face) - point1 = shape.part(0) - point2 = shape.part(2) - # Midx Midy 眼睛的中间点 - Midx = (point1.x+point2.x)//2 - Midy = (point1.y+point2.y)//2 - # cv2.circle(image,(Midx,Midy),3,(0,255,0)) - width = int((right-left)*2.25) - height = int(width*greenhat.shape[0]/greenhat.shape[1]) - # 将要加上去的绿帽的形状 - greenhat = cv2.resize(greenhat,(width,height),cv2.INTER_CUBIC) - # cv2.imshow("greenhat",greenhat) - # cv2.waitKey(0) - Addx = width//2 - # 有一个值得注意的就是不能数组越界 - r,g,b,alpha = cv2.split(greenhat) - for y in range(Midy-height,Midy): - if y+Base < 0 or y+Base >= image.shape[0]: continue - for x in range(Midx-Addx,Midx-Addx+width): - if x < 0 or x >= image.shape[1] : continue - tmpx,tmpy = x-Midx+Addx,y-Midy+height - if alpha[tmpy][tmpx] >= 100: - image[y+Base][x] = (r[tmpy][tmpx],g[tmpy][tmpx],b[tmpy][tmpx]) - - -cv2.imshow("output",image) -cv2.imwrite("output.jpg",image) -cv2.waitKey(0) -cv2.destroyAllWindows() diff --git a/greenhat/ghat.png b/greenhat/ghat.png deleted file mode 100644 index dd012a4..0000000 Binary files a/greenhat/ghat.png and /dev/null differ diff --git a/greenhat/output.jpg b/greenhat/output.jpg deleted file mode 100644 index 68c91e0..0000000 Binary files a/greenhat/output.jpg and /dev/null differ diff --git a/greenhat/shape_predictor_5_face_landmarks.txt b/greenhat/shape_predictor_5_face_landmarks.txt deleted file mode 100644 index 46bbaca..0000000 --- a/greenhat/shape_predictor_5_face_landmarks.txt +++ /dev/null @@ -1 +0,0 @@ -自行下载 diff --git a/greenhat/ym.jpg b/greenhat/ym.jpg deleted file mode 100644 index 0d728d0..0000000 Binary files a/greenhat/ym.jpg and /dev/null differ