-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9174d3f
commit e5d682f
Showing
30 changed files
with
1,194 additions
and
17 deletions.
There are no files selected for viewing
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import sys,os | ||
import cv2 | ||
import numpy as np | ||
import pandas as pd | ||
from genLabel import loadImg,getImgHW,getFileName,getLabelFileLabels,pathsFiles | ||
|
||
def distanceAB(a,b): | ||
return np.sqrt(np.sum((a-b)**2)) | ||
|
||
def calculateRatio(pts,id1,id2,id3,id4): | ||
assert(id1<len(pts)) | ||
assert(id2<len(pts)) | ||
assert(id3<len(pts)) | ||
assert(id4<len(pts)) | ||
return distanceAB(pts[id1], pts[id2])/distanceAB(pts[id3],pts[id4]) | ||
|
||
def calculateFeature(pts,H,W): | ||
for i in range(len(pts)): | ||
#print(pts[i][0],pts[i][1]) | ||
pts[i][0] = pts[i][0]*W | ||
pts[i][1] = pts[i][1]*H | ||
#print(pts) | ||
pts = np.array(pts) | ||
#print(pts.shape) | ||
|
||
# print('pts24=',pts[24]) | ||
# print('pts18=',pts[18]) | ||
# print(pts[24][0],pts[18][0]) | ||
|
||
x = np.min([pts[24][0],pts[18][0]]) | ||
y = np.min([pts[24][1],pts[18][1]]) | ||
eyebrowCenter = np.array([x,y]) + np.abs(pts[24]-pts[18])/2 | ||
#print('eyebrowCenter=',eyebrowCenter) | ||
|
||
#print(distanceAB(3,4)) | ||
#print(distanceAB(np.array([1,2]),np.array([4,6]))) | ||
#print(distanceAB(np.array([4,6]),np.array([1,2]))) | ||
F_Facial_Index = distanceAB(eyebrowCenter, pts[7])/distanceAB(pts[14],pts[0]) | ||
F_Mandibular_Index = calculateRatio(pts,66,7,4,10) | ||
|
||
F_Intercanthal = calculateRatio(pts,37,45,32,27) | ||
F_OrbitalWidth = calculateRatio(pts,27,29,37,45) | ||
F_EyeFissure = calculateRatio(pts,28,30,27,29) | ||
F_VermilionHeight = calculateRatio(pts,51,66,66,57) | ||
F_MouthFaceWidth = calculateRatio(pts,48,54,0,14) | ||
F_Noise1 = calculateRatio(pts,39,46,39,41) | ||
F_Noise2 = calculateRatio(pts,39,40,39,41) | ||
F_Noise3 = calculateRatio(pts,39,38,39,41) | ||
F_Noise4 = calculateRatio(pts,39,38,67,41) | ||
F_Noise5 = calculateRatio(pts,39,41,67,41) | ||
#print('name:',name,'Features=',F_Facial_Index,F_Mandibular_Index,F_Intercanthal,F_OrbitalWidth,F_EyeFissure,F_VermilionHeight,F_MouthFaceWidth,F_Noise1,F_Noise2,F_Noise3,F_Noise4,F_Noise5) | ||
|
||
return [F_Facial_Index,F_Mandibular_Index,F_Intercanthal,F_OrbitalWidth,F_EyeFissure,F_VermilionHeight,F_MouthFaceWidth,F_Noise1,F_Noise2,F_Noise3,F_Noise4,F_Noise5] | ||
|
||
data = {'F_Facial_Index':F_Facial_Index, 'F_Mandibular_Index':F_Mandibular_Index, | ||
'F_Intercanthal':F_Intercanthal,'F_OrbitalWidth':F_OrbitalWidth,'F_EyeFissure':F_EyeFissure, | ||
'F_VermilionHeight':F_VermilionHeight,'F_MouthFaceWidth':F_MouthFaceWidth,'F_Noise1':F_Noise1, | ||
'F_Noise2':F_Noise2,'F_Noise3':F_Noise3,'F_Noise4':F_Noise4,'F_Noise5':F_Noise5} | ||
#df = pd.DataFrame(data=data,index=[0]) | ||
#print(df) | ||
return data | ||
|
||
dbFile = r'.\db\facial.csv' | ||
def makeDb(): | ||
base = r'.\db\train\\' | ||
base = os.path.abspath(base) | ||
imgPath = base + r'\images' | ||
LabelPath = base + r'\labels' | ||
|
||
df = pd.DataFrame() | ||
columns = ['F_Facial_Index', 'F_Mandibular_Index', 'F_Intercanthal', | ||
'F_OrbitalWidth', 'F_EyeFissure', 'F_VermilionHeight', | ||
'F_MouthFaceWidth', 'F_Noise1', 'F_Noise2', 'F_Noise3', 'F_Noise4', | ||
'F_Noise5'] | ||
|
||
for i in pathsFiles(imgPath,'jpg'): | ||
#print(i) | ||
img = loadImg(i) | ||
H,W = getImgHW(img) | ||
fileName = getFileName(i) | ||
fileName = fileName[:fileName.rfind('.')] | ||
|
||
label = LabelPath + '\\' + fileName + '.pts' | ||
pts = getLabelFileLabels(label) | ||
|
||
print(fileName,'label=', label,'pts=', len(pts)) | ||
data = calculateFeature(pts,H,W) | ||
data = np.array(data).reshape(-1,len(data)) | ||
line = pd.DataFrame(data,columns=columns) | ||
line.insert(0, "Id", fileName, True) | ||
|
||
df = df.append(line) | ||
|
||
df.set_index(["Id"], inplace=True) | ||
print(df.head()) | ||
print(df.columns) | ||
df.to_csv(dbFile) | ||
|
||
def getDb(): | ||
return pd.read_csv(dbFile) | ||
|
||
def main(): | ||
makeDb() | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os,sys | ||
from commonModule.ImageBase import * | ||
from predictKeyPoints import * | ||
from makeDB import calculateFeature,getDb,distanceAB | ||
from testLabel import testFaceLabelPredict,showimage | ||
|
||
def argCmdParse(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-s', '--source', help = 'source image') | ||
#parser.add_argument('-d', '--dst', help = 'save iamge') | ||
return parser.parse_args() | ||
|
||
def predictPerson(feature): | ||
df = getDb() | ||
print(df.head()) | ||
#allFeatures = df.iloc[:,1:].values | ||
#print('allFeatures.shape=',allFeatures.shape) | ||
allDistance=[] | ||
allIds = [] | ||
for i in range(df.shape[0]): | ||
id = df.iloc[i,0] | ||
i = df.iloc[i,1:].values | ||
#print(id,i) | ||
allIds.append(id) | ||
|
||
dis = distanceAB(i,feature) | ||
#print('dis=',dis) | ||
allDistance.append(dis) | ||
|
||
#print('allDistance=',allDistance) | ||
disMin = min(allDistance) | ||
minIndex = allDistance.index(disMin) | ||
print('disMin=',disMin,'minIndex=',minIndex,'id=',allIds[minIndex]) | ||
|
||
|
||
def main(): | ||
arg = argCmdParse() | ||
file = r'./res/001A29.jpg' #arg.source # | ||
|
||
img = loadImg(file) | ||
H,W = getImgHW(img) | ||
pts = preditImg(img) | ||
#print('pts=',len(pts),pts.shape,pts) | ||
|
||
showimage(testFaceLabelPredict(file)) | ||
|
||
feature = calculateFeature(pts,H,W) | ||
print('feature=',len(feature),feature) | ||
predictPerson(feature) | ||
|
||
if __name__=='__main__': | ||
main() |
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.