问题描述
我目前正在从事眼睛本地化项目。为了训练 CNN,我必须将训练坐标调整为适当的图像大小。这些列包含 9 个面部特征点及其 x 和 y 分量。随着图像的大小调整,这些 x 和 y 分量应该调整大小。
def resize(target_Width,target_Height):
df = pd.read_csv('original_data.csv')
for i in range(0,df.shape[0]):
if i%1000 == 0: print(i)
row = df.iloc[i,:]
row_string = row['ImageNameIndex']
row_data = row.loc[df.columns != 'ImageNameIndex']
if img==None: continue
height = img.height
width = img.width
y_Column = ['LTY','LBY','RBY','RTY','TLLY','TLRY','BottomY','TRLY','TRRY']
x_Column = ['LTX','LBX','RBX','RTX','TLLX','TLRX','BottomX','TRLX','TRRX']
for col in y_Column:
value = df.loc[i,col]
targetValue = value * (target_Height/height)
df.loc[i,col] = targetValue
for col in x_Column:
value = df.loc[i,col]
targetValue = value * (target_Width/width)
df.loc[i,col] = targetValue
to_save = df.loc[:,constants.allColumns]
to_save.to_csv('all_csv_files/'+ 'resized_train_data.csv')
但是当我尝试在调整大小的图像上绘制面部特征时,面部特征不正确。
def plotimage():
indexes_to_test = [0,1]
for index in indexes_to_test:
#get name of Image
imageName = df.loc[index,'ImageNameIndex']
#get Image from direcotry
img = Image.open('./allImages/' + imageName)
#plot Original
plt.imshow( img,cmap='gray' )
face_feature_original = original_df.loc[index,constants.columns]
x,y = getCoordinates(face_feature_original)
plt.scatter( x,y,c='yellow' )
plt.title('original')
plt.show()
#resize Image
img = img.resize((target_width,target_height),Image.ANTIALIAS)
#plot resized
plt.imshow( img,cmap='gray' )
face_feature_resized = df.loc[index,y = getCoordinates(face_feature_resized)
plt.scatter( x,c='blue' )
plt.title('resized')
plt.show()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)