mjszczep / PyStasm

Python wrapper for finding features in faces.
Other
17 stars 6 forks source link

stasm.search_pinned #4

Open mrgloom opened 8 years ago

mrgloom commented 8 years ago

Still not sure what points can be used with stasm.search_pinned.Should it be some specific points(for example eyes) or it can be arbitary subset of 77 points landmark model and > 2 ?

Here is an example:

import os.path
import cv2
import stasm

path = os.path.join(stasm.DATADIR, 'testface.jpg')

img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
if img is None:
    print("Cannot load", path)
    raise SystemExit

landmarks = stasm.search_single(img)

print landmarks.shape, type(landmarks)

input_pt= landmarks[10:20]

print input_pt.shape, type(input_pt)
landmarks= stasm.search_pinned(input_pt, img)

if len(landmarks) == 0:
    print("No face found in", path)
else:
    landmarks = stasm.force_points_into_image(landmarks, img)
    for point in landmarks:
        img[round(point[1])][round(point[0])] = 255

cv2.imshow("stasm minimal", img)
cv2.waitKey(0)

It produce an error:

(77, 2) <type 'numpy.ndarray'>
(10, 2) <type 'numpy.ndarray'>
Traceback (most recent call last):
  File "pystasm_example.py", line 22, in <module>
    landmarks= stasm.search_pinned(input_pt, img)
_stasm.StasmException: faceroi.cpp(49) : Assertion failed : roi.width > 0
mrgloom commented 8 years ago

If I use landmarks= stasm.force_points_into_image(landmarks, img)

import os.path
import cv2
import stasm

path = os.path.join(stasm.DATADIR, 'testface.jpg')

img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
if img is None:
    print("Cannot load", path)
    raise SystemExit

landmarks = stasm.search_single(img)

print landmarks.shape, type(landmarks)

landmarks= stasm.force_points_into_image(landmarks, img)

input_pt= landmarks[10:20]

print input_pt.shape, type(input_pt)

landmarks= stasm.search_pinned(input_pt, img)

if len(landmarks) == 0:
    print("No face found in", path)
else:
    landmarks = stasm.force_points_into_image(landmarks, img)
    for point in landmarks:
        img[round(point[1])][round(point[0])] = 255

cv2.imshow("stasm minimal", img)
cv2.waitKey(0)

It give me error:

(77, 2) <type 'numpy.ndarray'>
(10, 2) <type 'numpy.ndarray'>
Traceback (most recent call last):
  File "pystasm_example.py", line 25, in <module>
    landmarks= stasm.search_pinned(input_pt, img)
_stasm.StasmException: eyedist.cpp(92) : Assertion failed : eyemouth > 1 && eyemouth < 1e5