Skip to content

Commit

Permalink
Merge pull request #7 from kookmin-sw/feature/face-shape
Browse files Browse the repository at this point in the history
Feature/face shape 얼굴형 검출 전용 디렉토리
  • Loading branch information
Topadonijah authored Mar 15, 2024
2 parents e9888cc + b3e3447 commit c89b080
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 44 deletions.
Binary file added __pycache__/controller.cpython-312.pyc
Binary file not shown.
36 changes: 0 additions & 36 deletions controller.py

This file was deleted.

6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
import controller
from shape_detect import shape_detect

train_path = "./train"
test_path = "./test"

shape_detect.run_label(test_path)
Binary file not shown.
Binary file not shown.
44 changes: 44 additions & 0 deletions shape_detect/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from shape_detect.utils import landmark, line, norm, ratio, vector
import cv2
import pandas as pd
import os

def get_vector(img_path):

display_img, pos = landmark.get_landmark(img_path)#사진 랜드마크 처리

distances = line.get_line(display_img, pos)#랜드마크간 특징 거리 추출

norm_distances = norm.get_norm(distances) #거리정보 정규화

vectors = vector.get_vector(pos)#각도 산출을 위한 벡터 추출

angles = vector.get_angles(vectors) #각도 추출

rations = ratio.get_ratio(distances) #길이 간 비율 정보


# print("norm: ", norm_distances, "\n\n")
# print("angle: ", angles, "\n\n")
# print("ratio: ", rations, "\n\n")

# cv2.imshow("Face Landmark", display_img)
# cv2.waitKey(0)

return norm_distances, angles, rations

def list_files(directory):
file_names = []
print(directory)
for root, _, files in os.walk(directory):
print(files)
for file in files:
file_names.append(os.path.join(root, file))
return file_names

def make_label(data):
row = ["D1","D2","D3","D4","D5","D6","D7","R1","R2","R3","R4","R5","R6","R7","R8","R9","R10","A1","A2","A3"]
df = pd.DataFrame(data, columns = row)
df.to_csv("./test.csv")
print(df)

10 changes: 10 additions & 0 deletions shape_detect/shape_detect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import shape_detect.controller as controller

def run_label(path):
data_set_directory = controller.list_files(path)
vectors = []
for path in data_set_directory:
norm_distances, angles, rations = controller.get_vector(path)
vectors.append(norm_distances + rations + angles)

controller.make_label(vectors)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions utils/line.py → shape_detect/utils/line.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cv2
from utils import distance
import shape_detect.utils.distance as distance

def get_line(display_image, pos):
D_LIST = [(2,14),(76,79),(71,8),(8, 12),(4,12),(6,10),(7,9)] #선분을 만들 주요 점 관계
Expand All @@ -11,7 +11,6 @@ def get_line(display_image, pos):
cv2.putText(display_image, "D{}".format(i + 1), (pos[start][0], pos[start][1] - 2), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 0, 255), 1)

dist = distance.get_distance( (pos[start][0], pos[start][1]), (pos[end][0], pos[end][1]))
print("D{}".format(i + 1),"'s distances is {}".format(dist), "\n" )

distances.append(dist)

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions utils/ratio.py → shape_detect/utils/ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ def get_ratio(distances):
rations.append(distances[4] / distances[1])
rations.append(distances[3] / distances[4])
rations.append(distances[6] / distances[5])
print("distances: ", distances, "\n")
print("Ratio: ", rations, "\n")

return rations
4 changes: 1 addition & 3 deletions utils/vector.py → shape_detect/utils/vector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from utils import angle
import shape_detect.utils.angle as angle

def get_vector(pos):
#각도를 구하기위한 벡터
Expand All @@ -7,7 +7,6 @@ def get_vector(pos):
V.append( (pos[12][0] - pos[8][0], pos[12][1] - pos[8][1]) ) #D4
V.append( (pos[12][0] - pos[4][0], pos[12][1] - pos[4][1]) ) #D5
V.append( (pos[10][0] - pos[8][0], pos[10][1] - pos[8][1]) ) #8-10
print("Vector: ", V, "\n")
return V

def get_angles(V):
Expand All @@ -16,6 +15,5 @@ def get_angles(V):
A.append(angle.get_angle(V[0], V[1]))
A.append(angle.get_angle(V[0], V[3]))
A.append(angle.get_angle(V[1], V[2]))
print("A:", A, "\n")

return A
4 changes: 4 additions & 0 deletions test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
,D1,D2,D3,D4,D5,D6,D7,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,A1,A2,A3
0,0.18925852735638332,0.15909147190070777,0.25902758173236456,0.09989648802183161,0.15701627961111192,0.08964434472955639,0.04606530664804442,0.8406039829377437,0.7306500956022944,0.614187380497132,1.2053433429013027,0.5709238873292749,1.1143646408839778,0.47366079606416667,0.9869559803250108,0.636217392675772,0.5138674033149172,55.00117175299869,68.94829220934821,34.385443504740294
1,0.19009156487794346,0.15493472929296562,0.2548705679181133,0.09787308040559582,0.16071524941984924,0.09234440866598308,0.049170399419549427,0.815053152897385,0.7458356860530773,0.6078957274609448,1.182784866800985,0.5745839862696814,1.0598701298701299,0.4857890918267563,1.0373093892716154,0.6089844041489442,0.5324675324675324,53.16379875419142,67.65019622075658,35.386029506161094
2,0.19424137033619607,0.1585515887098682,0.2496037097499231,0.09794875434736318,0.1621714339792273,0.09003477890552913,0.04744836397189296,0.8162606577344702,0.7781990521327014,0.6352132701421801,1.1977533007513312,0.5551827266759063,1.0878990934174222,0.46352009744214373,1.0228307095426397,0.603982785031731,0.5270003941663381,53.124855247662765,64.32924645581284,35.05652754431111
Binary file removed utils/__pycache__/line.cpython-312.pyc
Binary file not shown.
Binary file removed utils/__pycache__/ratio.cpython-312.pyc
Binary file not shown.
Binary file removed utils/__pycache__/vector.cpython-312.pyc
Binary file not shown.

0 comments on commit c89b080

Please sign in to comment.