本文整理汇总了Python中dlib.rectangle方法的典型用法代码示例。如果您正苦于以下问题:Python dlib.rectangle方法的具体用法?Python dlib.rectangle怎么用?Python dlib.rectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dlib
的用法示例。
在下文中一共展示了dlib.rectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getLargestFaceBoundingBox
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def getLargestFaceBoundingBox(self, rgbImg, skipMulti=False):
"""
Find the largest face bounding box in an image.
:param rgbImg: RGB image to process. Shape: (height, width, 3)
:type rgbImg: numpy.ndarray
:param skipMulti: Skip image if more than one face detected.
:type skipMulti: bool
:return: The largest face bounding box in an image, or None.
:rtype: dlib.rectangle
"""
assert rgbImg is not None
faces = self.getAllFaceBoundingBoxes(rgbImg)
if (not skipMulti and len(faces) > 0) or len(faces) == 1:
return max(faces, key=lambda rect: rect.width() * rect.height())
else:
return None
示例2: findLandmarks
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def findLandmarks(self, rgbImg, bb):
"""
Find the landmarks of a face.
:param rgbImg: RGB image to process. Shape: (height, width, 3)
:type rgbImg: numpy.ndarray
:param bb: Bounding box around the face to find landmarks for.
:type bb: dlib.rectangle
:return: Detected landmark locations.
:rtype: list of (x,y) tuples
"""
assert rgbImg is not None
assert bb is not None
points = self.predictor(rgbImg, bb)
#return list(map(lambda p: (p.x, p.y), points.parts()))
return [(p.x, p.y) for p in points.parts()]
#pylint: disable=dangerous-default-value
示例3: getLargestFaceBoundingBox
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def getLargestFaceBoundingBox(self, rgbImg, skipMulti=False):
"""
Find the largest face bounding box in an image.
:param rgbImg: RGB image to process. Shape: (height, width, 3)
:type rgbImg: numpy.ndarray
:param skipMulti: Skip image if more than one face detected.
:type skipMulti: bool
:return: The largest face bounding box in an image, or None.
:rtype: dlib.rectangle
"""
assert rgbImg is not None
faces = self.getAllFaceBoundingBoxes(rgbImg)
if (not skipMulti and len(faces) > 0) or len(faces) == 1:
return max(faces, key=lambda rect: rect.width() * rect.height())
else:
return None
示例4: getLargestFaceBoundingBox
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def getLargestFaceBoundingBox(self, rgbImg):
"""
Find the largest face bounding box in an image.
:param rgbImg: RGB image to process. Shape: (height, width, 3)
:type rgbImg: numpy.ndarray
:return: The largest face bounding box in an image, or None.
:rtype: dlib.rectangle
"""
assert rgbImg is not None
faces = self.getAllFaceBoundingBoxes(rgbImg)
if len(faces) > 0:
return max(faces, key=lambda rect: rect.width() * rect.height())
else:
return None
示例5: findLandmarks
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def findLandmarks(self, rgbImg, bb):
"""
Find the landmarks of a face.
:param rgbImg: RGB image to process. Shape: (height, width, 3)
:type rgbImg: numpy.ndarray
:param bb: Bounding box around the face to find landmarks for.
:type bb: dlib.rectangle
:return: Detected landmark locations.
:rtype: list of (x,y) tuples
"""
assert rgbImg is not None
assert bb is not None
points = self.predictor(rgbImg, bb)
return list(map(lambda p: (p.x, p.y), points.parts()))
示例6: predict
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def predict(image, model, shape_predictor=None):
# get landmarks
if NETWORK.use_landmarks or NETWORK.use_hog_and_landmarks or NETWORK.use_hog_sliding_window_and_landmarks:
face_rects = [dlib.rectangle(left=0, top=0, right=NETWORK.input_size, bottom=NETWORK.input_size)]
face_landmarks = np.array([get_landmarks(image, face_rects, shape_predictor)])
features = face_landmarks
if NETWORK.use_hog_sliding_window_and_landmarks:
hog_features = sliding_hog_windows(image)
hog_features = np.asarray(hog_features)
face_landmarks = face_landmarks.flatten()
features = np.concatenate((face_landmarks, hog_features))
else:
hog_features, _ = hog(image, orientations=8, pixels_per_cell=(16, 16),
cells_per_block=(1, 1), visualise=True)
hog_features = np.asarray(hog_features)
face_landmarks = face_landmarks.flatten()
features = np.concatenate((face_landmarks, hog_features))
tensor_image = image.reshape([-1, NETWORK.input_size, NETWORK.input_size, 1])
predicted_label = model.predict([tensor_image, features.reshape((1, -1))])
return get_emotion(predicted_label[0])
else:
tensor_image = image.reshape([-1, NETWORK.input_size, NETWORK.input_size, 1])
predicted_label = model.predict(tensor_image)
return get_emotion(predicted_label[0])
return None
示例7: getLandmarks
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def getLandmarks(im):
imSmall = cv2.resize(im, None,
fx = 1.0/FACE_DOWNSAMPLE_RATIO,
fy = 1.0/FACE_DOWNSAMPLE_RATIO,
interpolation = cv2.INTER_LINEAR)
rects = detector(imSmall, 0)
if len(rects) == 0:
return 0
newRect = dlib.rectangle(int(rects[0].left() * FACE_DOWNSAMPLE_RATIO),
int(rects[0].top() * FACE_DOWNSAMPLE_RATIO),
int(rects[0].right() * FACE_DOWNSAMPLE_RATIO),
int(rects[0].bottom() * FACE_DOWNSAMPLE_RATIO))
points = []
[points.append((p.x, p.y)) for p in predictor(im, newRect).parts()]
return points
开发者ID:jaisayush,项目名称:Fatigue-Detection-System-Based-On-Behavioural-Characteristics-Of-Driver,代码行数:20,代码来源:blinkDetect.py
示例8: featurize
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def featurize(self, img, bbox):
""" Compute face feature of the face bounding box in `bbox` in the image `img`.
:param img: image
:type img: :class:`numpy.ndarray`
:param bbox: bounding box dictionary
:type bbox: dict
:return: face feature
:rtype: :class:`numpy.ndarray`
"""
# Deal with B&W images
if len(img.shape)==2:
import skimage
img = skimage.color.gray2rgb(img)
# Build dlib rectangle from bounding box
from dlib import rectangle
dlib_bbox = rectangle(bbox['left'], bbox['top'], bbox['right'], bbox['bottom'])
shape = self.sp(img, dlib_bbox)
# Return feature
return np.squeeze(self.facerec.compute_face_descriptor(img, shape))
示例9: _return_landmarks
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def _return_landmarks(self, inputImg, roiX, roiY, roiW, roiH, points_to_return=range(0,68)):
""" Return the the roll pitch and yaw angles associated with the input image.
@param image It is a colour image. It must be >= 64 pixel.
@param radians When True it returns the angle in radians, otherwise in degrees.
"""
#Creating a dlib rectangle and finding the landmarks
dlib_rectangle = dlib.rectangle(left=int(roiX), top=int(roiY), right=int(roiW), bottom=int(roiH))
dlib_landmarks = self._shape_predictor(inputImg, dlib_rectangle)
#It selects only the landmarks that
#have been indicated in the input parameter "points_to_return".
#It can be used in solvePnP() to estimate the 3D pose.
landmarks = np.zeros((len(points_to_return),2), dtype=np.float32)
counter = 0
for point in points_to_return:
landmarks[counter] = [dlib_landmarks.parts()[point].x, dlib_landmarks.parts()[point].y]
counter += 1
return landmarks
示例10: returnLandmarks
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def returnLandmarks(self, inputImg, roiX, roiY, roiW, roiH, points_to_return=range(0,68)):
#Creating a dlib rectangle and finding the landmarks
dlib_rectangle = dlib.rectangle(left=int(roiX), top=int(roiY), right=int(roiW), bottom=int(roiH))
dlib_landmarks = self._predictor(inputImg, dlib_rectangle)
#It selects only the landmarks that
# have been indicated in the input parameter "points_to_return".
#It can be used in solvePnP() to estimate the 3D pose.
self._landmarks = numpy.zeros((len(points_to_return),2), dtype=numpy.float32)
counter = 0
for point in points_to_return:
self._landmarks[counter] = [dlib_landmarks.parts()[point].x, dlib_landmarks.parts()[point].y]
counter += 1
#Estimation of the eye dimesnion
#self._right_eye_w = self._landmark_matrix[RIGHT_TEAR].item((0,0)) - self._landmark_matrix[RIGHT_EYE].item((0,0))
#self._left_eye_w = self._landmark_matrix[LEFT_EYE].item((0,0)) - self._landmark_matrix[LEFT_TEAR].item((0,0))
return self._landmarks
示例11: detect_landmarks
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def detect_landmarks(self, frame):
"""Detect 5-point facial landmarks for faces in frame."""
predictor = get_landmarks_predictor()
landmarks = []
for face in frame['faces']:
l, t, w, h = face
rectangle = dlib.rectangle(left=int(l), top=int(t), right=int(l+w), bottom=int(t+h))
landmarks_dlib = predictor(frame['grey'], rectangle)
def tuple_from_dlib_shape(index):
p = landmarks_dlib.part(index)
return (p.x, p.y)
num_landmarks = landmarks_dlib.num_parts
landmarks.append(np.array([tuple_from_dlib_shape(i) for i in range(num_landmarks)]))
frame['landmarks'] = landmarks
示例12: to_dlib_rect
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def to_dlib_rect(self):
import dlib
return dlib.rectangle(left=self.x1, right=self.x2, top=self.y1, bottom=self.y2)
示例13: _tuple_to_rect
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def _tuple_to_rect(rect):
"""
Convert a tuple in (top, right, bottom, left) order to a dlib `rect` object
:param rect: plain tuple representation of the rect in (top, right, bottom, left) order
:return: a dlib `rect` object
"""
return dlib.rectangle(rect[3], rect[0], rect[1], rect[2])
示例14: findLandmarks
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def findLandmarks(self, rgbImg, bb):
"""
Find the landmarks of a face.
:param rgbImg: RGB image to process. Shape: (height, width, 3)
:type rgbImg: numpy.ndarray
:param bb: Bounding box around the face to find landmarks for.
:type bb: dlib.rectangle
:return: Detected landmark locations.
:rtype: list of (x,y) tuples
"""
assert rgbImg is not None
assert bb is not None
points = self.predictor(rgbImg, bb)
return list(map(lambda p: (p.x, p.y), points.parts()))
示例15: __init__
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import rectangle [as 别名]
def __init__(self,bbox,img):
self.tracker = correlation_tracker()
self.tracker.start_track(img,rectangle(long(bbox[0]),long(bbox[1]),long(bbox[2]),long(bbox[3])))
self.confidence = 0. # measures how confident the tracker is! (a.k.a. correlation score)
self.time_since_update = 0
self.id = CorrelationTracker.count
CorrelationTracker.count += 1
self.hits = 0
self.hit_streak = 0
self.age = 0