Save & load metrics when outputdir is set
This commit is contained in:
parent
0de8e62300
commit
d6e54cf59a
1 changed files with 25 additions and 4 deletions
29
head_pose.py
29
head_pose.py
|
@ -88,6 +88,11 @@ c.set(4, 720)
|
|||
|
||||
predictor_path = "shape_predictor_68_face_landmarks.dat"
|
||||
|
||||
if args.output_dir:
|
||||
lastMetricsFilename = os.path.join(args.output_dir, 'last_metrics.p')
|
||||
else:
|
||||
lastMetricsFilename = None
|
||||
|
||||
detector = dlib.get_frontal_face_detector()
|
||||
predictor = dlib.shape_predictor(predictor_path)
|
||||
|
||||
|
@ -97,7 +102,20 @@ screenDrawCorners = np.array([[10,60], [90, 60], [10, 110], [90, 110]])
|
|||
metricsSize = [1920,1080]
|
||||
metricsSize = [1280,800]
|
||||
dataframe = pd.DataFrame(columns=['x','y'])
|
||||
metrics = np.zeros((metricsSize[1], metricsSize[0])) # (y, x)
|
||||
|
||||
metrics = None
|
||||
if lastMetricsFilename and os.path.isfile(lastMetricsFilename):
|
||||
try:
|
||||
with open(lastMetricsFilename, "rb") as fp:
|
||||
metrics = pickle.load(fp)
|
||||
logger.warn("Loaded metrics from {}".format(lastMetricsFilename))
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
|
||||
if metrics is None:
|
||||
metrics = np.zeros((metricsSize[1], metricsSize[0])) # (y, x)
|
||||
logger.warn("New metrics")
|
||||
|
||||
screenDrawCorners = np.array([[0,0], [1919,0], [0, 1079], [1919,1079]])
|
||||
|
||||
def create_perspective_transform_matrix(src, dst):
|
||||
|
@ -461,12 +479,12 @@ while True:
|
|||
tm21 = time.time()
|
||||
normalisedMetrics = metrics / (np.max(metrics))
|
||||
# convert to colormap, thanks to: https://stackoverflow.com/a/10967471
|
||||
normalisedMetrics = np.uint8(cm.plasma(normalisedMetrics)*255)
|
||||
normalisedMetricsColored = np.uint8(cm.plasma(normalisedMetrics)*255)
|
||||
tm22 = time.time()
|
||||
logger.debug("Max normalised metrics: %f", np.max(normalisedMetrics))
|
||||
# logger.info(normalisedMetrics)
|
||||
tm23 = time.time()
|
||||
image = Image.fromarray(normalisedMetrics)
|
||||
image = Image.fromarray(normalisedMetricsColored)
|
||||
wpercent = (imageWindowSize[0] / float(image.size[0]))
|
||||
hsize = int((float(image.size[1]) * float(wpercent)))
|
||||
image = image.resize((imageWindowSize[0], hsize))
|
||||
|
@ -507,9 +525,12 @@ while True:
|
|||
)
|
||||
)
|
||||
image.save(filename)
|
||||
|
||||
with open(lastMetricsFilename, 'wb') as fp:
|
||||
pickle.dump( metrics, fp )
|
||||
|
||||
logger.debug("Saved frame to {}".format(filename))
|
||||
lastSaveTime = now
|
||||
pass
|
||||
|
||||
# (optionally) very slowly fade out previous metrics:
|
||||
metrics = metrics * .9997
|
||||
|
|
Loading…
Reference in a new issue