本文整理汇总了Python中cv2.CASCADE_SCALE_IMAGE属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.CASCADE_SCALE_IMAGE属性的具体用法?Python cv2.CASCADE_SCALE_IMAGE怎么用?Python cv2.CASCADE_SCALE_IMAGE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.CASCADE_SCALE_IMAGE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: detect_faces
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def detect_faces(img, draw_box=True):
# convert image to grayscale
grayscale_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# detect faces
faces = face_cascade.detectMultiScale(grayscale_img, scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE)
face_box, face_coords = None, []
for (x, y, w, h) in faces:
if draw_box:
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 5)
face_box = img[y:y+h, x:x+w]
face_coords = [x,y,w,h]
return img, face_box, face_coords
示例2: camera_stream
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def camera_stream():
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
# Display the resulting frame in browser
return cv2.imencode('.jpg', frame)[1].tobytes()
示例3: detectFaces
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def detectFaces(frame):
cascPath = "../data/haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
detected_faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=6,
minSize=(50, 50),
flags=cv2.CASCADE_SCALE_IMAGE)
return gray, detected_faces
开发者ID:its-izhar,项目名称:Emotion-Recognition-Using-SVMs,代码行数:13,代码来源:Train Classifier and Test Video Feed.py
示例4: prediction
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def prediction(self, image):
objects = self.model.detectMultiScale(
image,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
return objects
示例5: detect
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def detect(self, image, scale_factor=1.1, min_neighbors=5):
# Detect faces in the image
boxes = self.face_cascade.detectMultiScale(image, scale_factor, min_neighbors, flags=cv2.CASCADE_SCALE_IMAGE)
# Return the bounding boxes
return boxes
示例6: detect
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def detect(img, cascade):
rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE)
if len(rects) == 0:
return []
rects[:,2:] += rects[:,:2]
return rects
示例7: detectFace
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def detectFace(self, img):
rects = self.cc.detectMultiScale(img, scaleFactor=1.2, minNeighbors=2, \
minSize=(30, 30), flags = cv2.CASCADE_SCALE_IMAGE)
for rect in rects:
rect[2:] += rect[:2]
yield BBox([rect[0], rect[2], rect[1], rect[3]])
示例8: get_lbp_facebox
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def get_lbp_facebox(image):
"""
Get the bounding box fo faces in image by LBP feature.
"""
rects = CASCADES.detectMultiScale(image, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30),
flags=cv.CASCADE_SCALE_IMAGE)
if len(rects) == 0:
return []
for rect in rects:
rect[2] += rect[0]
rect[3] += rect[1]
return rects
示例9: detect_faces
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def detect_faces(self, image: np.ndarray):
# haarclassifiers work better in black and white
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray_image = cv2.equalizeHist(gray_image)
faces = self.classifier.detectMultiScale(gray_image,
scaleFactor=1.3,
minNeighbors=4,
flags=cv2.CASCADE_SCALE_IMAGE,
minSize=self._min_size)
return faces
示例10: detect_face_in_image_data
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def detect_face_in_image_data(self, image_data):
"""
function detects faces in image data,
draws rectangle for faces in image data,
and returns this updated image data with highlighted face/s
"""
self._red = (0, 0, 255)
self._width = 2
self._min_size = (30, 30)
# haarclassifiers work better in black and white
gray_image = cv2.cvtColor(image_data, cv2.COLOR_BGR2GRAY)
gray_image = cv2.equalizeHist(gray_image)
# path to Haar face classfier's xml file
face_cascade_xml = './cascades/haarcascades_cuda/" \
"haarcascade_frontalface_default.xml'
self.classifier = cv2.CascadeClassifier(face_cascade_xml)
faces = self.classifier.detectMultiScale(gray_image,
scaleFactor=1.3,
minNeighbors=4,
flags=cv2.CASCADE_SCALE_IMAGE,
minSize=self._min_size)
for (x, y, w, h) in faces:
cv2.rectangle(image_data,
(x, y),
(x+w, y+h),
self._red,
self._width)
return image_data
示例11: format_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def format_image(image_to_format):
image_to_format = cv2.cvtColor(image_to_format, cv2.COLOR_BGR2GRAY)
image_border = np.zeros((150, 150), np.uint8)
image_border[:, :] = 200
image_border[
int((150 / 2) - (Constants.FACE_SIZE / 2)): int((150 / 2) + (Constants.FACE_SIZE / 2)),
int((150 / 2) - (Constants.FACE_SIZE / 2)): int((150 / 2) + (Constants.FACE_SIZE / 2))
] = image_to_format
image_to_format = image_border
detected_faces = cascade_classifier.detectMultiScale(
image_to_format,
scaleFactor=1.3,
minNeighbors=5,
minSize=(48, 48),
flags=cv2.CASCADE_SCALE_IMAGE
)
# If no faces are found, return Null
if not detected_faces:
return None
max_face = detected_faces[0]
for face in detected_faces:
if face[2] * face[3] > max_face[2] * max_face[3]:
max_face = face
# Chop image to face
face = max_face
image_to_format = image_to_format[face[1]:(face[1] + face[2]), face[0]:(face[0] + face[3])]
# Resize image to fit network specs
try:
image_to_format = cv2.resize(image_to_format, (Constants.FACE_SIZE, Constants.FACE_SIZE),
interpolation=cv2.INTER_CUBIC) / 255.
except Exception:
# This happened once and now I'm scared to remove it.
print("Image resize exception. Check input resolution inconsistency.")
return None
return image_to_format
示例12: format_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def format_image(image_to_format):
if len(image_to_format.shape) > 2 and image_to_format.shape[2] == 3:
image_to_format = cv2.cvtColor(image_to_format, cv2.COLOR_BGR2GRAY)
else:
image_to_format = cv2.imdecode(image_to_format, cv2.CV_LOAD_IMAGE_GRAYSCALE)
detected_faces = face_cascade.detectMultiScale(
image_to_format,
scaleFactor=1.3,
minNeighbors=5,
minSize = (48, 48),
flags = cv2.CASCADE_SCALE_IMAGE
)
# If we don't find a face, return None
if not len(detected_faces) > 0:
return None
max_face = detected_faces[0]
for face in detected_faces:
if face[2] * face[3] > max_face[2] * max_face[3]:
max_face = face
# Chop image to face
face = max_face
image_to_format = image_to_format[face[1]:(face[1] + face[2]), face[0]:(face[0] + face[3])]
# Resize image to fit network specs
try:
image_to_format = cv2.resize(image_to_format, (Constants.FACE_SIZE, Constants.FACE_SIZE),
interpolation=cv2.INTER_CUBIC) / 255.
except Exception:
print("Image resize exception. Check input resolution inconsistency.")
return None
return image_to_format
示例13: apply_Haar_filter
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def apply_Haar_filter(img, haar_cascade, scaleFact=1.1, minNeigh=5, minSizeW=30):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
features = haar_cascade.detectMultiScale(
gray,
scaleFactor=scaleFact,
minNeighbors=minNeigh,
minSize=(minSizeW, minSizeW),
flags=cv2.CASCADE_SCALE_IMAGE,
)
return features
# Adjust the given sprite to the head's width and position
# in case of the sprite not fitting the screen in the top, the sprite should be trimed
示例14: apply_Haar_filter
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def apply_Haar_filter(img, haar_cascade,scaleFact = 1.1, minNeigh = 5, minSizeW = 30):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
features = haar_cascade.detectMultiScale(
gray,
scaleFactor=scaleFact,
minNeighbors=minNeigh,
minSize=(minSizeW, minSizeW),
flags=cv2.CASCADE_SCALE_IMAGE
)
return features
示例15: detect_single
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CASCADE_SCALE_IMAGE [as 别名]
def detect_single(self, image):
"""Return bounds (x, y, width, height) of detected face in grayscale image.
If no face or more than one face are detected, None is returned.
"""
faces = self.haar_faces.detectMultiScale(image,
scaleFactor=self.haar_scale_factor,
minNeighbors=self.haar_min_neighbors_face,
minSize=self.haar_min_size_face,
flags=cv2.CASCADE_SCALE_IMAGE)
if len(faces) != 1:
return None
return faces[0]