HCIILAB / SCUT-FBP5500-Database-Release

A diverse benchmark database for multi-paradigm facial beauty prediction
737 stars 146 forks source link

the landmark files of 5500 faces with "pts" format in folder "facial landmark" #1

Open ayantian opened 6 years ago

ayantian commented 6 years ago

Hi, Thank you very much for sharing your database. This database is very useful for research on facial aesthetics. One thing that puzzles me is that I got messy code when I try to read the landmark files with "pts" format in folder "facial landmark". I don't know where the problem is. Could you provide the code to read the facial landmarks? I am very looking forward to your help. Best wishes! Chen

iqbalnaved commented 6 years ago

These are binary files, I was able to read the files in MATLAB using following lines:

fid = fopen('facial landmark/ftw1-100/ftw1.pts'); pts = fread(fid);

But there are a total of 692 numbers, instead of 86x2 = 172. What is the format of the landmark points?

ayantian commented 6 years ago

The code provided by the auther:

import os import re import struct import shutil

def get_files(dname, suffix): pts_list = [] for fname in os.listdir(dname): if fname.endswith(suffix): pts_list += [fname] return pts_list

def pts2txt(din, dout, src): src_p = os.path.join(din, src) data = open(src_p, 'rb').read() points = struct.unpack('i172f', data)

print points

dst = src.lower()
dst = dst.replace('pts', 'txt')
dst_p = os.path.join(dout, dst)
# print dst_p

fout = open(dst_p, 'w')
pnum = len(points[1:])
for i in range(1, pnum, 2):
    fout.write('%f ' % points[i])
    fout.write('%f\n' % points[i + 1])

fout.close()

def main(): src = 'cc2' dst = 'cc_86'

if not os.path.exists(dst):
    os.mkdir(dst)

pts_list = get_files(src, 'pts')
for pts in pts_list:
    pts2txt(src, dst, pts)

jpg_list = get_files(src, 'jpg')
for img in jpg_list:
    src_img = os.path.join(src, img)
    img_lower = img.lower()
    dst_img = os.path.join(dst, img_lower)

    shutil.copy(src_img, dst_img)

if name == 'main': main()

iqbalnaved commented 6 years ago

Great! Thanks for sharing.

iqbalnaved commented 6 years ago

Following 5 files failed to unpack with error msg: :

points = struct.unpack('i172f', data) struct.error: unpack requires a bytes object of length 692

There seem no data inside these files. Is it landmark detection failure or are they corrupted?

TIA

ayantian commented 6 years ago

I got the same problem with you.

HCIILAB commented 6 years ago

The error of files have been solved