from rockx import RockX
import cv2

if __name__ == '__main__':

    parser = argparse.ArgumentParser(description="RockX Object Detection Demo")
    parser.add_argument('-i', '--image', help="input image", type=str)
    parser.add_argument('-d', '--device', help="target device id", type=str)
    args = parser.parse_args()

    object_det_handle = RockX(RockX.ROCKX_MODULE_OBJECT_DETECTION, target_device=args.device)

    in_img = cv2.imread(args.image)
    in_img_h, in_img_w = in_img.shape[:2]

    ret, results = object_det_handle.rockx_face_detect(in_img, in_img_w, in_img_h, RockX.ROCKX_PIXEL_FORMAT_BGR888)

    for result in results:
        label = RockX.ROCKX_OBJECT_DETECTION_LABELS_91[result.cls_idx]
        print('%s (%d %d %d %d) %f' % (label, result.box.left, result.box.top, result.box.right, result.box.bottom, result.score))
        cv2.rectangle(in_img,
                        (result.box.left, result.box.top),
                        (result.box.right, result.box.bottom),
                        (0, 255, 0), 2)
        cv2.putText(in_img, "%s" % label,
                    (result.box.left, result.box.top - 10),
                    cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0))

    cv2.imwrite('out.jpg', in_img)

    object_det_handle.release()
示例#2
0
    face_attr_handle = RockX(RockX.ROCKX_MODULE_FACE_ANALYZE,
                             target_device=args.device)

    cap = cv2.VideoCapture(args.camera)
    cap.set(3, 1280)
    cap.set(4, 720)
    last_face_feature = None

    while True:
        ret, frame = cap.read()

        show_frame = frame.copy()

        in_img_h, in_img_w = frame.shape[:2]
        start = time.time()
        ret, results = face_det_handle.rockx_face_detect(
            frame, in_img_w, in_img_h, RockX.ROCKX_PIXEL_FORMAT_BGR888)
        end = time.time()
        print('face detect use: ', end - start)

        index = 0
        for result in results:
            # face landmark
            start = time.time()
            ret, landmark = face_landmark68_handle.rockx_face_landmark(
                frame, in_img_w, in_img_h, RockX.ROCKX_PIXEL_FORMAT_BGR888,
                result.box)
            end = time.time()
            print('face landmark use: ', end - start)
            # face align
            ret, align_img = face_landmark5_handle.rockx_face_align(
                frame, in_img_w, in_img_h, RockX.ROCKX_PIXEL_FORMAT_BGR888,