当前位置: 首页>>代码示例>>Python>>正文


Python openface.AlignDlib方法代码示例

本文整理汇总了Python中openface.AlignDlib方法的典型用法代码示例。如果您正苦于以下问题:Python openface.AlignDlib方法的具体用法?Python openface.AlignDlib怎么用?Python openface.AlignDlib使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openface的用法示例。


在下文中一共展示了openface.AlignDlib方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: align_face

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def align_face(img_path, save=False):
  img_bgr = cv2.imread(img_path)
  if img_bgr is None:
    raise Exception("Unable to load image '%s'" % img_path)

  # Convert to RGB
  img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
  # Get bounding box
  bbox = align.getLargestFaceBoundingBox(img_rgb)
  if bbox is None:
    raise Exception("Unable to find a face in '%s'" % img_path)

  print "Align '%s'" % img_path
  face = align.align(IMG_DIM, img_rgb, bbox,
    landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)

  if save:
    print "Save to '%s'" % save
    cv2.imwrite(save, face)
  return face 
开发者ID:zatonovo,项目名称:deep_learning_ex,代码行数:22,代码来源:align.py

示例2: _get_representation

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def _get_representation(self, bgr_image):
        """
        Gets the vector of a face in the image
        :param bgr_image: The input image
        :return: The vector representation
        """
        rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB)

        bb = self._align.getLargestFaceBoundingBox(rgb_image)
        if bb is None:
            raise Exception("Unable to find a face in image")

        aligned_face = self._align.align(96, rgb_image, bb, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)
        if aligned_face is None:
            raise Exception("Unable to align face bb image")

        return self._net.forward(aligned_face) 
开发者ID:tue-robotics,项目名称:image_recognition,代码行数:19,代码来源:face_recognizer.py

示例3: get_face_vector

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def get_face_vector(rgbImg, align, net):
    bbs = align.getAllFaceBoundingBoxes(rgbImg)

    if len(bbs) == 0:
        raise(Exception("Unable to find a face"))
    elif len(bbs) > 1:
        raise(Exception("Found more than one face"))
    else:
        print "Found exactly one face in image (no error)"

    print('bbs', bbs)
        
    alignedFace = align.align(
        96,
        rgbImg,
        bbs[0],
        landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)

    if alignedFace is None:
        raise("Unable to align image")

    print('aligned face shape', alignedFace.shape)
    rep = net.forward(alignedFace)

    return rep 
开发者ID:jremmons,项目名称:AWSLambdaFace,代码行数:27,代码来源:faceaugmentation.py

示例4: is_face_present

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def is_face_present(rgbImg, align, net, knn):
    # get face vectors
    bbs = align.getAllFaceBoundingBoxes(rgbImg)
    face_vectors = []
    for bb in bbs:
        alignedFace = align.align(
            96,
            rgbImg,
            bb,
            landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)

        if alignedFace is None:
            raise("Unable to align image")

        rep = net.forward(alignedFace)
        face_vectors.append(rep)

    # classify the faces in the image
    for face_vector in face_vectors:
        face_prediction = int(knn.predict(face_vector)[0])
        if( face_prediction == 0 ):
            return True

    return False 
开发者ID:jremmons,项目名称:AWSLambdaFace,代码行数:26,代码来源:faceknn.py

示例5: get_face

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def get_face(filename):
    # Create a HOG face detector using the built-in dlib class
    predictor_model = "shape_predictor_68_face_landmarks.dat"
    
    face_detector = dlib.get_frontal_face_detector()
    face_pose_predictor = dlib.shape_predictor(predictor_model)
    face_aligner = openface.AlignDlib(predictor_model)

    win = dlib.image_window()

    # Load the image into an array
    image = io.imread(filename)

    # Run the HOG face detector on the image data.
    # The result will be the bounding boxes of the faces in our image.
    detected_faces = face_detector(image, 1)

    # Open a window on the desktop showing the image
    win.set_image(image)

    # Loop through each face we found in the image
    for i, face_rect in enumerate(detected_faces):
        # Detected faces are returned as an object with the coordinates 
        # of the top, left, right and bottom edges
        face1 = image[face_rect.top():face_rect.bottom(), face_rect.left():face_rect.right()]
        # Draw a box around each face we found
        win.add_overlay(face_rect)
        
        # Get the the face's pose
        pose_landmarks = face_pose_predictor(image, face_rect)
        alignedFace = face_aligner.align(534, image, face_rect, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)

        # Draw the face landmarks on the screen.
        win.add_overlay(pose_landmarks)
    return face1, alignedFace
#---------------------------------------------------------------------------------------- 
开发者ID:dalmia,项目名称:WannaPark,代码行数:38,代码来源:compare_similarity.py

示例6: get_face

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def get_face(filename):
	image = io.imread(filename)

	# Run the HOG face detector on the image data.
	# The result will be the bounding boxes of the faces in our image.
	detected_faces = face_detector(image, 1)

	print("I found {} faces in the file {}".format(len(detected_faces), filename))

	# Open a window on the desktop showing the image
	win.set_image(image)

	# Loop through each face we found in the image
	for i, face_rect in enumerate(detected_faces):
		# Detected faces are returned as an object with the coordinates 
		# of the top, left, right and bottom edges
		print("- Face #{} found at Left: {} Top: {} Right: {} Bottom: {}".format(i, face_rect.left(), face_rect.top(), face_rect.right(), face_rect.bottom()))
		face1 = image[face_rect.top():face_rect.bottom(), face_rect.left():face_rect.right()]
		# Draw a box around each face we found
		win.add_overlay(face_rect)
		
		# Get the the face's pose
		pose_landmarks = face_pose_predictor(image, face_rect)
		alignedFace = face_aligner.align(256, image, face_rect, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)

		# Draw the face landmarks on the screen.
		# win.add_overlay(pose_landmarks)
		
	return alignedFace 
开发者ID:dalmia,项目名称:WannaPark,代码行数:31,代码来源:secure_camera.py

示例7: __init__

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def __init__(self, align_path, net_path):
        # Init align and net
        """
        Dlib / Openface Face recognizer
        :param align_path: Dlib align path
        :param net_path: Openface neural network path
        """
        self._align = openface.AlignDlib(os.path.expanduser(align_path))
        self._net = openface.TorchNeuralNet(os.path.expanduser(net_path), imgDim=96, cuda=False)
        self._face_detector = dlib.get_frontal_face_detector()
        self._trained_faces = [] 
开发者ID:tue-robotics,项目名称:image_recognition,代码行数:13,代码来源:face_recognizer.py

示例8: getRep

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def getRep(bgrImg, align=align, net=net):
    rgbImg = cv2.cvtColor(bgrImg, cv2.COLOR_BGR2RGB)
    bb = align.getLargestFaceBoundingBox(rgbImg)
    if bb is None:
        raise Exception("Unable to find a face")
    alignedFace = align.align(96, rgbImg, bb, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)
    if alignedFace is None:
        raise Exception("Unable to align image")
    rep = net.forward(alignedFace)
    return rep 
开发者ID:UoA-eResearch,项目名称:openface_mass_compare,代码行数:12,代码来源:util.py

示例9: getPeople

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def getPeople(bgrImg, align=align, net=net):
    faces = []
    rgbImg = cv2.cvtColor(bgrImg, cv2.COLOR_BGR2RGB)
    bb = align.getAllFaceBoundingBoxes(rgbImg)
    if bb is None:
        raise Exception("Unable to find a face")
    for face in bb:
        alignedFace = align.align(96, rgbImg, face, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)
        if alignedFace is None:
            print("Unable to align image")
            continue
        if not alignedFace is None:
            rep = net.forward(alignedFace)
            best = 4
            bestUid = "unknown"
            for i in reps.keys():
                if type(reps[i]) is not list:
                    reps[i] = [reps[i]]
                for r in reps[i]:
                    d = rep - r
                    dot = np.dot(d,d)
                    if dot < best:
                        best = dot
                        bestUid = i
            faces.append({
              "face_rectangle": {
                "left": face.left(),
                "top": face.top(),
                "width": face.width(),
                "height": face.height()
              },
              "uid": bestUid,
              "confidence": 1 - best/4,
              "data": data_dict.get(bestUid)
            })
    return faces 
开发者ID:UoA-eResearch,项目名称:openface_mass_compare,代码行数:38,代码来源:util.py

示例10: head_detection_top

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def head_detection_top(photos, dlibFacePredictor, f_head_annotate):
    align = openface.AlignDlib(dlibFacePredictor)
    head_total = 0
    for photo in photos:
        image = skimage.io.imread(photo.file_path)
        head_index = 0

        for head_id in photo.human_detections:
            front_head = check_front_head(photo, image, head_id, align, head_index)
            f_head_annotate.write(str(front_head) + '\n')
            head_total += 1
            head_index += 1 
开发者ID:ymao1993,项目名称:HumanRecognition,代码行数:14,代码来源:head_detection.py

示例11: head_extraction_top

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def head_extraction_top(photos, dlibFacePredictor, imgDim, head_dir):
	align = openface.AlignDlib(dlibFacePredictor)


	for photo in photos:
		image = skimage.io.imread(photo.file_path)
		head_index = 0
		for head_id in photo.human_detections:
			align_head(photo, image, head_id, align, head_index, imgDim, head_dir)
			head_index += 1 
开发者ID:ymao1993,项目名称:HumanRecognition,代码行数:12,代码来源:head_extraction.py

示例12: align_head

# 需要导入模块: import openface [as 别名]
# 或者: from openface import AlignDlib [as 别名]
def align_head(photo, image, head_id, align, head_index, imgDim, head_dir):
	#crop head position
	xmin = int(head_id.head_bbox[0])
	ymin = int(head_id.head_bbox[1])
	width = int(head_id.head_bbox[2])
	height = int(head_id.head_bbox[3])

	#crop to square/out of boundary
	if xmin < 0:
		x_left = 0
	else:
		x_left = xmin

	if ymin < 0:
		y_up = 0
	else:
		y_up = ymin


	if (xmin+width) > image.shape[1]:
		x_right = image.shape[1]
	else:
		x_right = xmin+width

	if (ymin+height) > image.shape[0]:
		y_down = image.shape[0]
	else:
		y_down = ymin+height

	new_width = x_right - x_left
	new_height = y_down - y_up

	if new_width > new_height:
		length = new_height
	else:
		length = new_width

	new_x_left = (x_left+x_right)/2  - length/2
	new_x_right = (x_left+x_right)/2  + length/2	
	new_y_up = (y_up+y_down)/2  - length/2
	new_y_down = (y_up+y_down)/2  + length/2	

	if (new_y_up >= new_y_down) or (new_x_left >= new_x_right):
		return

	#save head image
	if config.save_head_image == True:
		head_image = image[new_y_up:new_y_down, new_x_left:new_x_right]
		head_file = os.path.join(head_dir,  photo.album_id + '_' + photo.photo_id + '_head_' + str(head_index) + '.jpg')
		skimage.io.imsave(head_file, head_image)

	#save aligned head
	if config.save_aligned_head_image == True:
		dlib_bbox = dlib.rectangle(left=new_x_left, top=new_y_up, right=new_x_right, bottom=new_y_down)
		alignedFace = align.align(imgDim, image, dlib_bbox, landmarkIndices=openface.AlignDlib.INNER_EYES_AND_BOTTOM_LIP)
		if image.ndim == 3:
			alignedFace = cv2.cvtColor(alignedFace, cv2.COLOR_RGB2BGR)
		align_head_file = os.path.join(head_dir,  photo.album_id + '_' + photo.photo_id + '_aligned_head_' + str(head_index) + '.jpg')
		cv2.imwrite(align_head_file, alignedFace) 
开发者ID:ymao1993,项目名称:HumanRecognition,代码行数:61,代码来源:head_extraction.py


注:本文中的openface.AlignDlib方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。