Пример #1
0
def process(inputs, ctx, **kwargs):
    frame, is_streaming = helpers.load_image(inputs, 'input', rgb=False)
    LOG.info("frame shape: {}".format(frame.shape))
    bboxes, probabilities = detect_bboxes(
        ctx.drivers[0],
        frame,
        PARAMS.get("threshold", .5),
    )
    for i, bbox in enumerate(bboxes):
        draw_bbox(
            frame,
            bbox.astype(int),
            label="Detected {}\nprobability: {:.2f}".format(
                PARAMS["object_name"], probabilities[i]),
        )

    if is_streaming:
        output = frame[:, :, ::-1]
    else:
        _, buf = cv2.imencode('.jpg', frame)
        output = buf.tostring()

    return {
        'output': output,
        'bboxes': bboxes.tolist(),
        'probabilities': probabilities.tolist(),
    }
Пример #2
0
def process(inputs, ctx, **kwargs):
    frame, is_streaming = helpers.load_image(inputs, 'input', rgb=False)
    LOG.info("frame shape: {}".format(frame.shape))

    detect_driver = ctx.drivers[0]

    bboxes, probabilities = detect_bboxes(
        detect_driver,
        frame,
        PARAMS.get("threshold", .5),
    )

    head_poses = []

    if len(bboxes) > 0:

        head_pose_driver = ctx.drivers[1]
        head_poses = head.head_pose(head_pose_driver, frame, bboxes, rgb=False)

        for i, bbox in enumerate(bboxes):
            draw_bbox(
                frame,
                bbox.astype(int),
                label="Detected face\n"
                "probability: {:.2f}\n"
                "yaw: {:.2f}\n"
                "pitch: {:.2f}\n"
                "roll: {:.2f}".format(probabilities[i], head_poses[i][0],
                                      head_poses[i][1], head_poses[i][2]),
            )
            head.draw_axis(frame, bbox, head_poses[i])

        head_poses = head_poses.tolist()

    if is_streaming:
        output = frame[:, :, ::-1]
    else:
        _, buf = cv2.imencode('.jpg', frame)
        output = buf.tostring()

    return {
        'output': output,
        'bboxes': bboxes.tolist(),
        'probabilities': probabilities.tolist(),
        'poses': head_poses,
    }
Пример #3
0
def process(inputs, ctx, **kwargs):
    frame, is_streaming = helpers.load_image(inputs, 'input', rgb=False)
    LOG.info("frame shape: {}".format(frame.shape))
    bboxes, probabilities = detect_bboxes(ctx.drivers[0], frame,
                                          PARAMS.get("detect_threshold", .5))
    for bbox in bboxes.astype(int):
        cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]),
                      (0, 255, 0), 1)

    if is_streaming:
        output = frame
    else:
        _, buf = cv2.imencode('.jpg', frame)
        output = buf.tostring()

    return {
        'output': output,
        'bboxes': bboxes.tolist(),
        'probabilities': probabilities.tolist(),
    }
def process(inputs, ctx, **kwargs):
    frame, is_streaming = helpers.load_image(inputs, 'input', rgb=False)
    LOG.info("frame shape: {}".format(frame.shape))

    detect_driver = ctx.drivers[0]

    bboxes, probabilities = detect_bboxes(
        detect_driver,
        frame,
        PARAMS.get("threshold", .5),
    )

    age, gender = [], []

    if len(bboxes) > 0:

        age_gender_driver = ctx.drivers[1]
        age, gender = age_gender(age_gender_driver, frame, bboxes, rgb=False)

        for i, bbox in enumerate(bboxes):
            draw_bbox(
                frame,
                bbox.astype(int),
                label="Detected face\nprobability: {:.2f}\nage: {}, gender: {}"
                .format(probabilities[i], age[i],
                        "male" if gender[i] == 1 else "female"),
            )

    if is_streaming:
        output = frame[:, :, ::-1]
    else:
        _, buf = cv2.imencode('.jpg', frame)
        output = buf.tostring()

    return {
        'output': output,
        'bboxes': bboxes.tolist(),
        'probabilities': probabilities.tolist(),
        'age': age,
        'gender': gender,
    }