Пример #1
0
    facelist.create(facelist_id, facelist_name)
    logger.info("Finished making facelist.")
except Exception as e:
    logger.error("Problem creating facelist: %s" % e)

face_result = []
if os.path.exists(args.source):
    if os.path.isdir(args.source):
        for dirName, subdirList, fileList in os.walk(args.source):
            if len(fileList) != 0 and len(subdirList) == 0:
                faces = []
                for fname in fileList:
                    if (fname not in [".DS_Store"]):
                        fpath = os.path.realpath(os.path.join(dirName, fname))
                        try:
                            face_result = face.detect({'path': fpath})
                            logger.info("Got faces (%d) for image %s." %
                                        (len(face_result), fname))
                        except Exception as e:
                            logger.error(
                                "Error %s finding face in image (%s)." %
                                (e, fpath))

                        # TODO: If face list doesn't have enough room for all the faces, make a new one and keep track of the names
                        if len(face_result) > 0:
                            for face_found in face_result:
                                target_face = "%s,%s,%s,%s" % (
                                    face_found['faceRectangle']['left'],
                                    face_found['faceRectangle']['top'],
                                    face_found['faceRectangle']['width'],
                                    face_found['faceRectangle']['height'])
Пример #2
0
        
def pick(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        face = find_face(x, y)
        print "Face found: %s" % face['faceId']
        try:
            similar = client.similar(face['faceId'], candidateFaceListId=face_list_id)
            print similar
        except Exception as e:
            if 'FaceNotFound' in e.message:
                print "Face not found."    

        cv2.imshow(window_name, img)
             
try:
    faces = client.detect({'path': args.image})
except Exception as e:
    print e
    print "Error finding face in image (%s)." % args.image

img = cv2.imread(args.image)
img_width, img_height = img.shape[:2]

width_scale = 1024.0 / img_width
height_scale = 768.0 / img_height

resized_image = cv2.resize(img, (0,0), fx=width_scale, fy=height_scale) 

cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
cv2.setMouseCallback(window_name, pick)
Пример #3
0
    facelist.create(facelist_id, facelist_name)
    logger.info("Finished making facelist.")
except Exception as e:
    logger.error("Problem creating facelist: %s" % e)
    
face_result = []
if os.path.exists(args.source):
    if os.path.isdir(args.source):
        for dirName, subdirList, fileList in os.walk(args.source):
            if len(fileList) != 0 and len(subdirList) == 0:
                faces = []
                for fname in fileList:
                    if(fname not in [".DS_Store"]):
                        fpath = os.path.realpath(os.path.join(dirName, fname))
                        try:
                            face_result = face.detect({'path': fpath})
                            logger.info("Got faces (%d) for image %s." % (len(face_result), fname))
                        except Exception as e:
                            logger.error("Error %s finding face in image (%s)." % (e, fpath))
                        
                        # TODO: If face list doesn't have enough room for all the faces, make a new one and keep track of the names
                        if len(face_result) > 0:
                            for face_found in face_result:
                                target_face = "%s,%s,%s,%s" % (face_found['faceRectangle']['left'], face_found['faceRectangle']['top'], face_found['faceRectangle']['width'], face_found['faceRectangle']['height'])
                                user_data = json.dumps({'file': fname, 'faceRectangle':face_found['faceRectangle']})
                                try:
                                    facelist.addFace(facelist_id, {'path':fpath}, targetFace=target_face, userData=user_data)
                                    logger.info("Added face %s (%s, %s) to %s" % (face_found, target_face, user_data, facelist_id))
                                except Exception as e:
                                  logger.error("Error %s adding face (%s)." % (e, user_data))