Exemplo n.º 1
0
        '--show-process',
        type=bool,
        default=False,
        help='for debug purpose, if enabled, speed for inference is dropped.')
    parser.add_argument('--showBG',
                        type=bool,
                        default=True,
                        help='False to show skeleton only.')
    args = parser.parse_args()

    logger.debug('initialization %s : %s' %
                 (args.model, get_graph_path(args.model)))

    w, h = model_wh(args.resize)
    if w > 0 and h > 0:
        e = TfPoseEstimator(get_graph_path(args.model), target_size=(w, h))
    else:
        e = TfPoseEstimator(get_graph_path(args.model), target_size=(432, 368))

    cap = cv2.VideoCapture(args.video)
    width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
    fps = cap.get(cv2.CAP_PROP_FPS)

    if cap.isOpened() is False:
        print("Error opening video stream or file")

    fourcc = cv2.VideoWriter_fourcc(*'DIVX')
    writer = cv2.VideoWriter('./video/output.mp4', fourcc, fps,
                             (width, height))
Exemplo n.º 2
0
def init_TF_pose_estimator():
    global TF_POSE_ESTIMATOR
    model = "mobilenet_thin"
    TF_POSE_ESTIMATOR = TfPoseEstimator(get_graph_path(model),
                                        target_size=(216, 216))
    print("TF Pose estimator Initialized!")
                        type=bool,
                        default=False,
                        help='False to show skeleton only.',
                        required=False)

    try:
        args = argp.parse_args()
    except:
        argp.print_help(sys.stderr)
        exit(1)

    logger.debug('initialization %s : %s' %
                 (args.model[0], get_graph_path(args.model[0])))
    w, h = model_wh(args.resolution)
    if w > 0 and h > 0:
        e = TfPoseEstimator(get_graph_path(args.model[0]), target_size=(w, h))
    else:
        e = TfPoseEstimator(get_graph_path(args.model[0]),
                            target_size=(224, 224))
    cap = cv2.VideoCapture(args.video[0])

    if cap.isOpened() is False:
        print("Error opening video stream or file")

    print(args.path)
    i = 0
    while cap.isOpened():
        ret_val, image = cap.read()

        if ret_val == False:
            break
        type=bool,
        default=False,
        help='for debug purpose, if enabled, speed for inference is dropped.')

    parser.add_argument('--tensorrt',
                        type=str,
                        default="False",
                        help='for tensorrt process.')
    args = parser.parse_args()

    logger.debug('initialization %s : %s' %
                 (args.model, get_graph_path(args.model)))
    w, h = model_wh(args.resize)
    if w > 0 and h > 0:
        e = TfPoseEstimator(get_graph_path(args.model),
                            target_size=(w, h),
                            trt_bool=str2bool(args.tensorrt))
    else:
        e = TfPoseEstimator(get_graph_path(args.model),
                            target_size=(432, 368),
                            trt_bool=str2bool(args.tensorrt))
    logger.debug('cam read+')
    cam = cv2.VideoCapture(args.camera)
    ret_val, image = cam.read()
    logger.info('cam image=%dx%d' % (image.shape[1], image.shape[0]))

    while True:
        ret_val, image = cam.read()

        # logger.debug('image process+')
        humans = e.inference(image,
Exemplo n.º 5
0
        '--resize-out-ratio',
        type=float,
        default=4.0,
        help=
        'if provided, resize heatmaps before they are post-processed. default=1.0'
    )

    args = parser.parse_args()

    gpu_options = tf.GPUOptions()
    gpu_options.allow_growth = True

    w, h = model_wh(args.resize)
    if w == 0 or h == 0:
        e = TfPoseEstimator(get_graph_path(args.model),
                            target_size=(432, 368),
                            tf_config=tf.ConfigProto(gpu_options=gpu_options))
    else:
        e = TfPoseEstimator(get_graph_path(args.model),
                            target_size=(w, h),
                            tf_config=tf.ConfigProto(gpu_options=gpu_options))

    # estimate human poses from a single image !
    image = common.read_imgfile(args.image, None, None)
    if image is None:
        logger.error('Image can not be read, path=%s' % args.image)
        sys.exit(-1)

    t = time.time()
    humans = e.inference(image,
                         resize_to_default=(w > 0 and h > 0),
Exemplo n.º 6
0
def recognize(img):
    w = 432
    h = 368
    model = "cmu"
    e = TfPoseEstimator(get_graph_path(model), target_size=(w, h))
    humans = e.inference(frame, resize_to_default=(w > 0 and h > 0), upsample_size=4.0)
    '''
        {0,  "Nose"},
        {1,  "Neck"},
        {2,  "RShoulder"},
        {3,  "RElbow"},
        {4,  "RWrist"},
        {5,  "LShoulder"},
        {6,  "LElbow"},
        {7,  "LWrist"},
        {8,  "RHip"},
        {9,  "RKnee"},
        {10, "RAnkle"},
        {11, "LHip"},
        {12, "LKnee"},
        {13, "LAnkle"},
        {14, "REye"},
        {15, "LEye"},
        {16, "REar"},
        {17, "LEar"},
        {18, "Bkg"}
    '''
    if(len(humans) == 0):
        return (0,0,0,0)
    human = humans[0]

    height, width, channels = frame.shape
    #return human.get_upper_body_box(width, height)

    x_min = 1
    y_min = 1
    x_max = 0
    y_max = 0

    print(human.body_parts)

    necessary_parts = [0,9,10,12,13,14,15]

    for parts in necessary_parts:
        if parts not in human.body_parts:
            return (0,0,0,0)
    
    eye_y = (human.body_parts[14].y + human.body_parts[15].y) / 2
    #neck_y = human.body_parts[1].y
    nose_y = (human.body_parts[0].y)
    y_min = eye_y - (nose_y - eye_y) * 3.2
    #y_max = 1 - y_max
    if(human.body_parts[13].y < human.body_parts[10].y):
        y_max = human.body_parts[13].y + 0.32 * (human.body_parts[13].y - human.body_parts[12].y)
    else:
        y_max = human.body_parts[10].y + 0.32 * (human.body_parts[10].y - human.body_parts[9].y)
    #y_min = 1 - y_min
    for k in human.body_parts:
        bodypart = human.body_parts[k]
        x = bodypart.x
        if x < x_min:
            x_min = x
        if x > x_max:
            x_max = x
    x_max = math.ceil(x_max * width)
    x_min = math.floor(x_min * width)
    y_max = math.ceil(y_max * height)
    y_min = math.floor(y_min * height)
    bbox = (x_min, y_min, (x_max - x_min), (y_max - y_min))
    print(bbox)
    print(x_min, x_max, y_min, y_max)
    print("eye",human.body_parts[14].y)
    print("ankle",human.body_parts[10].y)
    print("lWrist",human.body_parts[4].x)
    print("rWrist",human.body_parts[7].x)
    return bbox
Exemplo n.º 7
0
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    '[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

print("CHOOSING THE PIC")
image = cv.imread("test.jpg")

print("SETTING THE NEURAL NETWORK")
sys.path.insert(0, '../tf-openpose')
from tf_pose.estimator import TfPoseEstimator
from tf_pose.networks import get_graph_path, model_wh
#logger.debug('initialization %s : %s' % (args.model, get_graph_path(args.model)))
e = TfPoseEstimator(get_graph_path('cmu'), target_size=(432, 368))

print('THE ACTUAL PROCESSING HAPPEN HERE')

humans = e.inference(image,
                     resize_to_default=(w > 0 and h > 0),
                     upsample_size=resize_out_ratio)
image = TfPoseEstimator.draw_humans(image, humans, imgcopy=False)

print("SAVING THE STUFF")

cv.imwrite("result.jpg", image)
data = {'positions': {}}
human = humans[0]

body_position = {}
Exemplo n.º 8
0
from tf_pose.networks import get_graph_path, model_wh

w, h = 432, 368
parts = [
    'nose', 'neck', 'r_shoulder', 'r_elbow', 'r_wrist', 'l_shoulder',
    'l_elbow', 'l_wrist', 'r_hip', 'r_knee', 'r_ankle', 'l_hip', 'l_knee',
    'l_ankle', 'r_eye', 'l_eye', 'r_ear', 'l_ear'
]

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.75,
                            allow_growth=True)

tf_config = tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False)

e = TfPoseEstimator(get_graph_path("mobilenet_thin"),
                    target_size=(w, h),
                    tf_config=tf_config)


def action_classifie(img):
    img_shape = img.shape
    humans = e.inference(img,
                         resize_to_default=(w > 0 and h > 0),
                         upsample_size=4.0)

    bodys_pos = []

    for human in humans:
        temp = {}
        for i in range(len(parts)):
            if i not in human.body_parts.keys():
    return GetPersonsResponse(msg)


if __name__ == '__main__':
    # Initialize Node and Parameters
    rospy.init_node('point_detection_3d')
    image = rospy.get_param("~camera", "/camera/color/image_raw")
    model = rospy.get_param('~model', 'mobilenet_thin')
    resolution = rospy.get_param('~resolution', '432x368')
    resize_out_ratio = float(rospy.get_param('~resize_out_ratio', '4.0'))

    tf_lock = Lock()

    try:
        w, h = model_wh(resolution)
        graph_path = get_graph_path(model)

        rospack = rospkg.RosPack()
        graph_path = os.path.join(rospack.get_path('tfpose_ros'), graph_path)
    except Exception as e:
        rospy.logerr('invalid model: %s, e=%s' % (model, e))
        sys.exit(-1)

    pose_estimator = TfPoseEstimator(graph_path, target_size=(w, h))
    cv_bridge = CvBridge()

    s = rospy.Service('get_persons', GetPersons, find_persons_handler)

    rospy.spin()