HCIILAB/SCUT-FBP5500-Database-Release

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

ayantian opened this issue · 6 comments

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

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?

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()

Great! Thanks for sharing.

Following 5 files failed to unpack with error msg: :

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

  • ty401-500/fty403.pts
  • mty1001-1100/mty1006.pts
  • mty801-900/mty840.pts
  • ftw401-500/ftw442.pts
  • mtw301-400/mtw353.pts

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

TIA

I got the same problem with you.

The error of files have been solved