示例#1
0
    parser = argparse.ArgumentParser(description='MobilePose Realtime Webcam.')
    parser.add_argument(
        '--model',
        type=str,
        default='resnet18',
        choices=['mobilenetv2', 'resnet18', 'shufflenetv2', 'squeezenet'])
    parser.add_argument('--inp_dim', type=int, default=224, help='input size')
    parser.add_argument('--camera', type=int, default=0)

    args = parser.parse_args()

    # load the model
    #model_path = os.path.join("./models", args.model+"_%d_adam_best.t7"%args.inp_dim)
    model_path = "./models/mobilenetv2_224_adam_best.t7"
    net = CoordRegressionNetwork(n_locations=6, backbone=args.model).to("cpu")
    e = ResEstimator(model_path, net, args.inp_dim)

    #     # initial the camera
    #     cam = cv2.VideoCapture(args.camera)

    #     ret_val, image = cam.read()
    #     image = crop_camera(image)

    #     while True:
    #         # read image from the camera and preprocess
    #         ret_val , image = cam.read()
    #         image = crop_camera(image)
    #         # forward the image
    #         humans = e.inference(image)
    #         image = ResEstimator.draw_humans(image, humans, imgcopy=False)
    #         cv2.imshow('MobilePose Demo', image)
示例#2
0
    mid_width = width / 2.0
    width_20 = width * ratio
    crop_img = image[0:int(height),
                     int(mid_width - width_20):int(mid_width + width_20)]
    return crop_img


if __name__ == '__main__':

    # load the model
    model_path = './models/mobilenetv2_224_adam_best.t7'

    net = CoordRegressionNetwork(n_locations=16,
                                 backbone='mobilenetv2').to('cpu')

    estimator = ResEstimator(model_path, net, 224)

    # initialize the camera
    cam = cv2.VideoCapture(0)
    ret_val, image = cam.read()
    image = crop_camera(image)

    while True:

        # get frame
        ret_val, image = cam.read()
        image = crop_camera(image)

        # infer through network
        humans = estimator.inference(image)
        # image = ResEstimator.draw_humans(
示例#3
0
import matplotlib.pyplot as plt

if __name__ == '__main__':

    parser = argparse.ArgumentParser(description='MobilePose Realtime Webcam.')
    parser.add_argument('--model',
                        type=str,
                        default='resnet',
                        help='mobilenet|resnet')
    parser.add_argument('--camera', type=int, default=0)

    args = parser.parse_args()

    # load the model
    w, h = model_wh(get_graph_path(args.model))
    e = ResEstimator(get_graph_path(args.model), target_size=(w, h))

    # initial the camera
    cam = cv2.VideoCapture(args.camera)

    ret_val, image = cam.read()
    image = crop_camera(image)

    while True:
        # read image from the camera and preprocess
        ret_val, image = cam.read()
        image = crop_camera(image)
        # forward the image
        humans = e.inference(image, args.model)
        image = ResEstimator.draw_humans(image, humans, imgcopy=False)
        cv2.imshow('MobilePose Demo', image)