Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ayantian opened this issue Mar 21, 2018 · 6 comments

Comments

@ayantian
Copy link

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
Copy link

iqbalnaved commented Apr 2, 2018

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
Copy link
Author

ayantian commented Apr 3, 2018

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
Copy link

Great! Thanks for sharing.

@iqbalnaved
Copy link

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

@ayantian
Copy link
Author

ayantian commented Apr 4, 2018

I got the same problem with you.

@HCIILAB
Copy link
Owner

HCIILAB commented May 25, 2018

The error of files have been solved

HCIILAB pushed a commit that referenced this issue Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants