示例#1
0
文件: rec.py 项目: shook2012/pyseeta2
def test_database(img_path, db_path):
    if not os.path.isfile(img_path) or not os.path.isdir(db_path):
        print("indicated path doesn't exist!")
        return

    # load test image
    img_A = cv2.imread(img_path)
    seeta_A = seetaface.SeetaImage(img_A)
    faces_A = fd.detect(seeta_A)
    featA = extract_features(seeta_A, faces_A[0].pos)
    # load database
    for fn in os.listdir(db_path):
        fp = os.path.join(db_path, fn)
        if not os.path.isfile(fp): continue
        img_B = cv2.imread(fp)
        seeta_B = seetaface.SeetaImage(img_B)
        # detect face in image
        faces_B = fd.detect(seeta_B)
        if len(faces_A) and len(faces_B):
            sim_list = []
            for face in faces_B:
                featB = extract_features(seeta_A, face.pos)
                sim = fr.calcsim(featA, featB)
                sim_list.append(sim)
                colr = (0, 0, 255) if sim < 0.65 else (255, 0, 0)
                mark(img_B, face.pos, colr)
            print('sim: {}'.format(sim_list))
            show(img_B)
示例#2
0
文件: rec.py 项目: shook2012/pyseeta2
def test_simple():
    img = cv2.imread(single)
    seetaImg = seetaface.SeetaImage(img)
    faces = fd.detect(seetaImg)
    features = extract_features(seetaImg, faces[0].pos)

    img_B = cv2.imread(double)
    seeta_B = seetaface.SeetaImage(img_B)
    faces_B = fd.detect(seeta_B)

    for face in faces_B:
        rect = face.pos
        feats = extract_features(seeta_B, rect)
        sim = fr.calcsim(features, feats)
        print(sim)
        colr = (0, 0, 255) if sim < 0.65 else (255, 0, 0)
        mark(img_B, rect, colr)

    show(img_B)
示例#3
0
import seetaface
import cv2

root = 'example2.jpg'

image = seetaface.SeetaImage(root)

pd = seetaface.PointDetector(
    '/home/tumh/python-seetaface2/SeetaPointDetector2.0.pts5.ats')

# given a boudning box
rect = seetaface.SeetaRect()
rect.x = 221
rect.y = 130
rect.width = 232
rect.height = 278

im = cv2.imread(root)
cv2.rectangle(im, (rect.x, rect.y),
              (rect.x + rect.width, rect.y + rect.height), (0, 0, 255), 2)
points = pd.detect(image, rect)
for p in points:
    cv2.circle(im, (int(p.x), int(p.y)), 2, (0, 0, 255), -1)

cv2.imwrite('example2_result.jpg', im)
示例#4
0
文件: det.py 项目: shook2012/pyseeta2
import seetaface
import cv2

root = 'examples/example1.jpg'

fd = seetaface.FaceDetector('models/fd_2_00.dat')
fl = seetaface.FaceLandmarker('models/pd_2_00_pts81.dat')
print("model loaded")
im = cv2.imread(root)
image = seetaface.SeetaImage(im)
print("image loaded")
# or you can pass image path to SeetaImage
#  image = seetaface.SeetaImage(root)

faces = fd.detect(image)
for face in faces:
    rect = face.pos
    cv2.rectangle(im, (rect.x, rect.y),
                  (rect.x + rect.width, rect.y + rect.height), (0, 0, 255), 2)
    points = fl.detect(image, rect)
    for p in points:
        cv2.circle(im, (int(p.x), int(p.y)), 2, (0, 0, 255), -1)

cv2.imwrite('examples/example1_result.jpg', im)
cv2.imshow('win', im)
cv2.waitKey(0)