Exemplo n.º 1
0
    help="Model to use for detecting face",
    dest="face_model",
    default="hog",
)
parser.add_argument(
    "--enable-gpu",
    help="Set to true to enable gpu support",
    dest="enable_gpu",
    default=False,
    type=bool,
)
args = parser.parse_args()

# Instantiating the required class
fdetector = FDetector()
kdetector = KDetector()

# Read the image
img = cv2.imread(args.img_path)

# Set the detectors
kdetector.set_detector(args.key_model)
fdetector.set_detector(args.face_model)

# Detect face and the points
fimg, boxes, conf = fdetector.detect_face(img, enable_gpu=True)
points = kdetector.detect_keypoints(img, rects=boxes)

# Draw the points
pimg = kdetector.draw_points(fimg, points, show=True)
Exemplo n.º 2
0
from visionlib.face.detection import FDetector
import cv2
import argparse

# Configre the parser.
parser = argparse.ArgumentParser()
parser.add_argument("img_path", help="Path to image")
parser.add_argument("--enable-gpu",
                    help="Set to true to enable gpu support",
                    dest="enable_gpu",
                    default=False,
                    type=bool)
args = parser.parse_args()

# Instantiating the required classes.
detector = FDetector()

# Read the image
img = cv2.imread(args.img_path)
detector.set_detector("hog")
# Apply face detection and show image
d_img, boxes, conf = detector.detect_face(img,
                                          show=True,
                                          enable_gpu=args.enable_gpu)
for box, conf in zip(boxes, conf):
    print(box, conf)
Exemplo n.º 3
0
parser = argparse.ArgumentParser()
parser.add_argument("img_path", help="Path to image")
parser.add_argument("--enable-gpu",
                    help="Set to true to enable gpu support",
                    dest="enable_gpu",
                    default=False,
                    type=bool)
args = parser.parse_args()
# Instantiating the required classes.
Fdetector = FDetector()
Gdetector = GDetector()
im_utils = Image()
# Read the image
img = cv2.imread(args.img_path)
Fdetector.set_detector("hog")
# Detect the Faces
d_img, boxes, conf = Fdetector.detect_face(img)
for box in boxes:
    # Get the face by cropping
    c_img = im_utils.crop(d_img, box)
    # Apply Gender Detection
    gender = Gdetector.detect_gender(c_img, enable_gpu=args.enable_gpu)
    # format the label
    label = "{}: {:.2f}%".format(gender[0], gender[1] * 100)
    # Put padding for rendering the label
    Y = box[1] - 10 if box[1] - 10 > 10 else box[1] + 10
    cv2.putText(d_img, label, (box[0], Y), cv2.FONT_HERSHEY_SIMPLEX, 0.7,
                (0, 255, 0), 2)
cv2.imshow("pic2", img)
cv2.waitKey(0)