#!/usr/bin/env python2.7
# coding: utf-8
"""
    This file use Caffe model to predict data from http://mmlab.ie.cuhk.edu.hk/archive/CNN_FacePoint.htm
"""

import os, sys
from functools import partial
import cv2
from common import getDataFromTxt, createDir, logger, drawLandmark
from common import level1, level2, level3


OUTPUT = 'dataset/test/out'
createDir(OUTPUT)
TXT = 'dataset/test/lfpw_test_249_bbox.txt'


if __name__ == '__main__':
    assert(len(sys.argv) == 2)
    level = int(sys.argv[1])
    if level == 0:
        P = partial(level1, FOnly=True)
    elif level == 1:
        P = level1
    elif level == 2:
        P = level2
    else:
        P = level3

    data = getDataFromTxt(TXT, with_landmark=False)
    for imgPath, bbox in data:
        img = cv2.imread(imgPath)
        assert(img is not None)
        imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        logger("process %s" % imgPath)

        landmark = P(imgGray, bbox)
        landmark = bbox.reprojectLandmark(landmark)
        drawLandmark(img, bbox, landmark)
        cv2.imwrite(os.path.join(OUTPUT, os.path.basename(imgPath)), img)

@@ -319,54 +319,8 @@
 3%0A%0A%0A
-OUTPUT = 'dataset/test/out'%0AcreateDir(OUTPUT)%0A
 TXT 
@@ -360,17 +360,16 @@
 x.txt'%0A%0A
-%0A
 if __nam
@@ -616,16 +616,88 @@
 level3%0A%0A
+    OUTPUT = 'dataset/test/out_%7B0%7D'.format(level)%0A    createDir(OUTPUT)%0A
     data

format output dir with level number