Example #1
0
def openpose_25_kp(image):
    datum = op.Datum()
    image_to_process = copy.copy(image)
    datum.cvInputData = image_to_process
    opWrapper.emplaceAndPop([datum])
    pose_key_points = datum.poseKeypoints
    return pose_key_points
Example #2
0
def init():
    # Try to import OpenPose
    try:
        # Get path from system environment
        OPENPOSE_ROOT = os.environ["OPENPOSE_ROOT"]
        sys.path.append(OPENPOSE_ROOT + '/' + 'build/python/')
        from openpose import pyopenpose as op

    except ImportError as e:
        print(
            'Error: OpenPose library could not be found. '
            'Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?'
        )
        raise e
    # Init OpenPose
    global Data, PoseDetector
    # Set OpenPose parameters
    params = dict()
    params["model_folder"] = OPENPOSE_ROOT + os.sep + "models" + os.sep
    params["face"] = False
    params["hand"] = False
    params["disable_blending"] = True
    # Start OpenPose wrapper
    op_wrapper = op.WrapperPython()
    op_wrapper.configure(params)
    op_wrapper.start()
    # Init Datum object
    Data = op.Datum()
    # Rename op_wrapper
    PoseDetector = op_wrapper
def analyze():
    ret_val, final_image = cam.read()
    

    final_image = edit_video(final_image)

    ###############
    # Process openpose
    ############
    # Process image
    datum = op.Datum()
    datum.cvInputData = final_image
    opWrapper.emplaceAndPop([datum])

    # Display Image
    frame = datum.poseKeypoints
    cv2.imshow("Frame", datum.cvOutputData)

    ############
    # Classify current passenger state.
    ######
    prediction = safety_check(frame)
    
    
    return prediction, frame, datum.cvOutputData
    def detect_poses(self, image):
        # `op` added to globals in the constructor
        datum = op.Datum()  # pylint: disable=undefined-variable # noqa: F821
        datum.cvInputData = image
        self._openpose_wrapper.emplaceAndPop(op.VectorDatum([datum]))

        keypoints = datum.poseKeypoints
        overlayed_image = datum.cvOutputData

        recognitions = []

        if keypoints is not None and len(
                keypoints.shape
        ) == 3:  # If no detections, keypoints will be None
            num_persons, num_bodyparts, _ = keypoints.shape
            for person_id in range(0, num_persons):
                for body_part_id in range(0, num_bodyparts):
                    body_part = self._model["body_parts"][body_part_id]
                    x, y, probability = keypoints[person_id][body_part_id]
                    if probability > 0:
                        recognitions.append(
                            Recognition(group_id=person_id,
                                        roi=RegionOfInterest(width=1,
                                                             height=1,
                                                             x_offset=int(x),
                                                             y_offset=int(y)),
                                        categorical_distribution=
                                        CategoricalDistribution(probabilities=[
                                            CategoryProbability(
                                                label=body_part,
                                                probability=float(probability))
                                        ])))

        return recognitions, overlayed_image
def get_keypoints(image):

    try:
        # Starting OpenPose
        opWrapper = op.WrapperPython()
        opWrapper.configure(params)
        opWrapper.start()

        # Process Image
        datum = op.Datum()
        datum.cvInputData = image

        opWrapper.emplaceAndPop([datum])

        if (datum.poseKeypoints.ndim == 0):
            print("No person found in image!")
            sys.exit(-1)
        num = len(datum.poseKeypoints)
        if (num is 0):
            print("No person found in image!")
            sys.exit(-1)
        return datum

    except Exception as e:
        print("Openpose Error: ")
        print(e)
Example #6
0
    def predict_image(self, image_path):
        datum = op.Datum()
        image_to_process = cv2.imread(image_path)
        datum.cvInputData = image_to_process
        self.opWrapper.emplaceAndPop([datum])

        return datum.poseKeypoints
Example #7
0
    def hand_skel(self, image_path, is_left=False):
        from openpose import pyopenpose as op

        # Read image and face rectangle locations
        img = cv2.imread(image_path)
        if img is None:
            return None
        height, width = img.shape[:2]
        top, bottom, left, right = get_square_padding(img)
        img = squarify(img, (top, bottom, left, right))
        hand_rect = op.Rectangle(0.0, 0.0, img.shape[0], img.shape[0])
        null_rect = op.Rectangle(0.0, 0.0, 0.0, 0.0)
        if is_left:
            hand_rects = [[hand_rect, null_rect]]
        else:
            hand_rects = [[null_rect, hand_rect]]

        datum = op.Datum()
        datum.cvInputData = img
        datum.handRectangles = hand_rects
        self.op_wrap.emplaceAndPop(op.VectorDatum([datum]))

        if is_left:
            kps = datum.handKeypoints[0][0]
        else:
            kps = datum.handKeypoints[1][0]
        if left:
            kps[:, 0] -= left
        elif top:
            kps[:, 1] -= top
        return kps, width, height
Example #8
0
    def __init__(self, debug=0):

        self.debug = debug

        self.frameCount = 0
        self.timePrev = time.time()

        #region OPENPOSE
        opParams = dict()
        opParams['model_folder'] = '/home/aufar/Documents/openpose/models/'
        opParams['net_resolution'] = '176x176'

        self.opWrapper = op.WrapperPython()

        self.opWrapper.configure(opParams)
        self.opWrapper.start()

        self.datum = op.Datum()
        #endregion

        self.subscriberImageDetections = rospy.Subscriber(
            'yolo_detector/output/compresseddetections',
            CompressedImageAndBoundingBoxes,
            self.callback,
            queue_size=1)

        self.publisherDetectionDirections = rospy.Publisher(
            'yact/output/detectiondirections',
            DetectionAndDirection,
            queue_size=1)
Example #9
0
def skeleton_from_video(video_path, icam=0, visual=True):
    cap = cv2.VideoCapture(video_path)

    all_poseKeypoints = []

    i = 0
    while True:
        ret, frame = cap.read()
        if not ret:
            break
        datum = op.Datum()
        imageToProcess = copy.copy(frame)
        datum.cvInputData = imageToProcess
        opWrapper.emplaceAndPop([datum])

        if visual:
            cv2.imshow("OpenPose 1.4.0 - Tutorial Python API",
                       datum.cvOutputData)
            key = cv2.waitKey(15)
            if key == 27:
                break

        poseKeyPoints = datum.poseKeypoints

        if isinstance(poseKeyPoints, np.ndarray):
            for k, pose in enumerate(poseKeyPoints):
                pose = np.hstack((icam, i, pose))
                all_poseKeypoints.append(pose)
        i += 1
    return np.asarray(all_poseKeypoints)
Example #10
0
def get_points_from_image(image_path):
    try:
        logger.debug('Starting analysis')

        # parameters
        params = dict()
        params["model_folder"] = "./openpose_models/"
        params["face"] = True
        params["hand"] = True
        # params["write_json"] = "./json_outputs/"

        # Starting OpenPose
        opWrapper = op.WrapperPython()
        opWrapper.configure(params)
        opWrapper.start()

        # Process Image
        datum = op.Datum()
        imageToProcess = cv2.imread(image_path)
        datum.cvInputData = imageToProcess
        opWrapper.emplaceAndPop([datum])

        logger.debug('Analysis done, raw data: {}'.format(datum.cvOutputData))

        return datum.cvOutputData
    except Exception as e:
        logger.error('An error occurred while analysing an image')
        logger.error(e, exc_info=True)
        # propagate error forward
        raise e
Example #11
0
def extractHeatMap(image):
    params["model_folder"] = "./openpose/models/"
    params["heatmaps_add_parts"] = True
    params["heatmaps_add_bkg"] = True
    params["heatmaps_add_PAFs"] = True
    params["heatmaps_scale"] = 2
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()

    # Process Image
    datum = op.Datum()
    #imageToProcess = cv2.imread(args[0].image_path)
    imageToProcess = image
    datum.cvInputData = imageToProcess
    opWrapper.emplaceAndPop([datum])

    # Process outputs
    outputImageF = (datum.inputNetData[0].copy())[0, :, :, :] + 0.5
    outputImageF = cv2.merge(
        [outputImageF[0, :, :], outputImageF[1, :, :], outputImageF[2, :, :]])
    outputImageF = (outputImageF * 255.).astype(dtype='uint8')
    heatmaps = datum.poseHeatMaps.copy()
    heatmaps = (heatmaps).astype(dtype='uint8')
    return heatmaps
Example #12
0
def generate_kpts(video_name):
    kpt_results = []

    cap = cv2.VideoCapture(video_name)
    length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    opWrapper = load_model()
    for i in tqdm(range(length)):

        try:
            datum = op.Datum()
            _, imageToProcess = cap.read()
            datum.cvInputData = imageToProcess
            opWrapper.emplaceAndPop([datum])
            results = datum.poseKeypoints

            #25 to 17
            assert len(
                results
            ) == 1, 'videopose3D only support one pserson restruction'
            kpts = convert(results[0])
            kpt_results.append(kpts)
        except Exception as e:
            print(e)

    # pose processes
    result = np.array(kpt_results)
    return result
    def HandKeypoint_getKeypoints(self, HandImage, box):
        #
        # implementCODE
        #
        # keypoints = KeypointType()
        arr = np.fromstring(HandImage.image, np.uint8)
        frame = np.reshape(
            arr, (HandImage.height, HandImage.width, HandImage.depth))
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        print('Input Data Recieved')
        box = np.array(box)
        ## Creating openpose rectangle
        hands_rectangles = [[
            self.box2oprectangle(box),
            op.Rectangle(0., 0., 0., 0.)
        ]]

        # Create new datum
        datum = op.Datum()
        datum.cvInputData = frame
        datum.handRectangles = hands_rectangles
        # Process and display image
        self.openpose_wrapper.emplaceAndPop([datum])

        if datum.handKeypoints[0].shape == ():
            # if there were no detections
            hand_keypoints = None
        else:
            hand_keypoints = datum.handKeypoints[0][0]
        return hand_keypoints
Example #14
0
    def __init__(self):
        # image array config
        self.bridge = CvBridge()
        self.threat_boxes_topic = rospy.get_param("~threat_image_topic",
                                                  "/threats/potential_images")
        self.threat_boxes_sub = rospy.Subscriber(self.threat_boxes_topic,
                                                 ImageArray, self.threat_boxes)
        self.msg_seq = 0
        self.msg_time = 0
        self.skeletons = []

        # openpose config
        self.params = dict()
        self.params["model_folder"] = rospy.get_param("~model_folder_path",
                                                      "/cfg/models/")
        self.opWrapper = op.WrapperPython()
        self.opWrapper.configure(self.params)
        self.opWrapper.start()
        self.datum = op.Datum()

        # publish skeleton topics
        self.op_image_pub_topic = rospy.get_param("~skeleton_image_topic",
                                                  "/threats/skeleton_images")
        self.op_image_pub = rospy.Publisher(self.op_image_pub_topic,
                                            Image,
                                            queue_size=10)
        self.op_image_seq = 0

        # threat model params
        self.threat_model_name = rospy.get_param("~threat_model_name",
                                                 "default_model")
        self.threat_model_path = rospy.get_param("~threat_model_path")
        self.threat_model_meta = self.threat_model_path + self.threat_model_name + ".meta"
Example #15
0
    def processPic(self):
        # ============================= 启动openPose ===================================

        datum = op.Datum()

        datum.cvInputData = cv2.imread(self.picPaths)  # 输入
        opWrapper.emplaceAndPop(op.VectorDatum([datum]))  # 输出
        keyPoints = datum.poseKeypoints.tolist()

        dstPicPath = "../dataset/marked_pic/p_" + self.picPaths.split('/')[
            -1]  # 处理后的图片
        cv2.imwrite(dstPicPath, datum.cvOutputData)
        # ============================= 写骨骼数据文件 ===================================
        with open("../dataset/bone_dataSet.data", "a+") as dataSet:
            dataSet.writelines(
                str(
                    self.pointDistance(keyPoints[0]) +
                    self.pointAngle(keyPoints[0]) +
                    [int(self.lineEdit.text())]))
            dataSet.write("\n")
        # ============================= 写骨骼图片文件 ===================================
        bone_img = datum.cvOutputData
        height, width, channel = bone_img.shape
        pixmap = QPixmap.fromImage(
            QImage(bone_img.data, width, height, 3 * width,
                   QImage.Format_RGB888).rgbSwapped())
        self.label_3.setPixmap(pixmap)
    def analyze(self):
        rate = rospy.Rate(5)
        while self.image_ready == False and not rospy.is_shutdown():
            rate.sleep()
        final_image = self.image_raw

        final_image = self.edit_video(final_image)
        ###############
        # Process openpose
        ############
        # Process image
        datum = op.Datum()
        datum.cvInputData = final_image
        self.opWrapper.emplaceAndPop(op.VectorDatum([datum]))

        # Display Image
        frame = datum.poseKeypoints
        cv2.imshow("Frame", datum.cvOutputData)

        ############
        # Classify current passenger state.
        ######
        prediction = self.safety_check(frame)

        return prediction, frame, datum.cvOutputData
Example #17
0
def process(input_dir, openpose_model_dir):
    params = {}

    # Configure openpose params
    params['image_dir'] = input_dir
    params['model_folder'] = openpose_model_dir
    params['face'] = True

    op_wrapper = op.WrapperPython()
    op_wrapper.configure(params)
    op_wrapper.start()

    # Process images in input dir
    paths = op.get_images_on_directory(input_dir)
    joints_2d = []
    face_2d = []

    for path in paths:
        datum = op.Datum()
        img = cv2.imread(path)
        resolution = img.shape[:2]
        datum.cvInputData = img

        op_wrapper.emplaceAndPop([datum])

        joints_2d.append(format_pose(datum.poseKeypoints, resolution))
        face_2d.append(format_face(datum.faceKeypoints, resolution))

    return joints_2d, face_2d
Example #18
0
    def get_sample_heatmaps():
        # These parameters are globally set. You need to unset variables set here if you have a new OpenPose object. See *
        params = dict()
        params["model_folder"] = "/usr/local/src/openpose-1.7.0/models/"
        params["heatmaps_add_parts"] = True
        params["heatmaps_add_bkg"] = True
        params["heatmaps_add_PAFs"] = True
        params["heatmaps_scale"] = 3
        params["upsampling_ratio"] = 1
        params["body"] = 1

        # Starting OpenPose
        opWrapper = op.WrapperPython()
        opWrapper.configure(params)
        opWrapper.start()

        # Process Image and get heatmap
        datum = op.Datum()
        imageToProcess = cv2.imread(args[0].image_path)
        datum.cvInputData = imageToProcess
        opWrapper.emplaceAndPop([datum])
        poseHeatMaps = datum.poseHeatMaps.copy()
        opWrapper.stop()

        return poseHeatMaps
Example #19
0
    def __init__(self, parent=None):
        super(MainWIndow, self).__init__(parent)
        self.timer_camera = QtCore.QTimer()
        self.width = 720
        self.height = 480
        self.set_ui()
        self.slot_init()
        # openpose params

        print(params)
        # Starting OpenPose
        self.opWrapper = opWrapper
        self.opWrapper.start()

        # Process Image
        self.datum = op.Datum()

        self.SEQ_LEN = 10
        self.isStarted = False
        self.UserFrames = {}

        self.make_pause = False
        self.saved_count = 0
        self.backgorund_image = {}
        self.users_complete = {}
        self.tracker = Sort(20, 3)
        self.currentExamination = 0

        # initiate the video
        self.cap = cv2.VideoCapture("/home/prince/Desktop/destination.mp4")
Example #20
0
    def __init__(self, pose_type=BODY25B, params=None):
        if params is None:
            params = {}
        if 'model_pose' in params:
            logger.warning(
                'model_pose param specified by pose_type arg, conflict.')
        super().__init__()
        self.pose_type = pose_type
        self.full_params = {
            'model_folder': self.model_path,
            'number_people_max': 3,
            # 'net_resolution': '-1x368', # it is default value
            'logging_level': 3,
            'display': 0,
            'alpha_pose': 0.79,
            # 'face': 1,
            # 'hand': 1,
        }
        self.full_params.update(params)
        self.full_params.update({
            'model_pose': pose_type.NAME,
        })

        self.opWrapper = opp.WrapperPython()
        self.opWrapper.configure(self.full_params)
        self.opWrapper.start()
        self.datum: opp.Datum = opp.Datum()
Example #21
0
    def initialize_openpose(self, args):
        # Custom Params (refer to include/openpose/flags.hpp for more parameters)
        params = dict()

        # Openpose params

        # Model path
        params["model_folder"] = args[0].openpose_folder

        # Face disabled
        params["face"] = False

        # Hand disabled
        params["hand"] = False

        # Net Resolution
        params["net_resolution"] = args[0].net_size

        # Gpu number
        params["num_gpu"] = 1  # Set GPU number

        # Gpu Id
        # Set GPU start id (not considering previous)
        params["num_gpu_start"] = 0

        # Starting OpenPose
        self.opWrapper = op.WrapperPython()
        self.opWrapper.configure(params)
        self.opWrapper.start()

        self.datum = op.Datum()
Example #22
0
def detection(pipe_img, pipe_center, pipe_scale, pipe_img_2, pipe_kp):

    params = set_params()
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()
    detection_count = 0
    detection_time = time.time()
    while True:
        img = pipe_img.recv()
        datum = op.Datum()
        datum.cvInputData = img
        opWrapper.emplaceAndPop([datum])
        bodyKeypoints_img = datum.cvOutputData
        cv2.rectangle(bodyKeypoints_img, (330, 620), (630, 720), (0, 0, 255),
                      3)
        #cv2.imwrite('kps.jpg',bodyKeypoints_img)
        json_path = glob.glob('/media/ramdisk/output_op/*keypoints.json')
        scale, center = op_util.get_bbox(json_path[0])
        if scale == -1 and center == -1: continue
        if scale >= 10: continue
        pipe_img_2.send(img)
        pipe_center.send(center)
        pipe_scale.send(scale)
        pipe_kp.send(bodyKeypoints_img)
        os.system("rm /media/ramdisk/output_op/*keypoints.json")
        detection_count = detection_count + 1
        if detection_count == 100:
            print('Detection FPS:',
                  1.0 / ((time.time() - detection_time) / 100.0))
            detection_count = 0
            detection_time = time.time()
Example #23
0
 def return_Ib_Pb(self, imagePath):  # [Pb, Ib]をリターン ポーズが取れなかった場合はNoneをリターン
     # print(imagePath)
     datum = op.Datum()
     image = cv2.imread(imagePath)
     datum.cvInputData = image
     self.opWrapper.emplaceAndPop([datum])
     try:
         int(datum.poseKeypoints)
         return None, None
     except:
         keypoints_images = self.draw_keypoints(image, datum.poseKeypoints)
         # return image, keypoints_images
         return_image = cv2.resize(
             image, (int(image.shape[0] / 8), int(image.shape[1] / 8)))
         return_keypoints_images = []
         for keypoints_image in keypoints_images:
             resize_keypoints_image = cv2.resize(
                 keypoints_image, (int(keypoints_image.shape[0] / 8),
                                   int(keypoints_image.shape[1] / 8)))
             # height, width = resize_keypoints_image.shape[:2]
             #     # 取得結果(幅,高さ,チャンネル数,depth)を表示
             # print("width: " + str(width))
             # print("height: " + str(height))
             return_keypoints_images.append(resize_keypoints_image)
         return return_image, return_keypoints_images
Example #24
0
def generate_kpts(video_name):
    kpt_results = []

    cap = cv2.VideoCapture(video_name)
    length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    opWrapper = load_model()
    for i in tqdm(range(length)):

        try:
            datum = op.Datum()
            _, imageToProcess = cap.read()
            datum.cvInputData = imageToProcess
            opWrapper.emplaceAndPop([datum])
            results = datum.poseKeypoints

            #25 to 17
            assert len(
                results
            ) == 1, 'videopose3D only support one pserson restruction'
            kpts = convert(results[0])
            kpt_results.append(kpts)
        except Exception as e:
            print(e)

    # pose processes
    result = np.array(kpt_results)

    # save
    name = '/home/xyliu/experiments/VideoPose3D/data/tmp.npz'
    kpts = result.astype(np.float32)
    print('kpts npz save in ', name)
    np.savez_compressed(name, kpts=kpts)
    return kpts

    return result
Example #25
0
def test_video(model, video_name=0):
    opWrapper = model

    cam = cv2.VideoCapture(video_name)
    # warm up
    for i in range(5):
        datum = op.Datum()
        _, imageToProcess = cam.read()
        datum.cvInputData = imageToProcess
        opWrapper.emplaceAndPop([datum])

    for i in tqdm(range(2000)):
        datum = op.Datum()
        _, imageToProcess = cam.read()
        datum.cvInputData = imageToProcess
        opWrapper.emplaceAndPop([datum])
Example #26
0
def analyze():
    params = dict()
    params["model_folder"] = "../../../../models/"


    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()
    datum = op.Datum()
    
    while True:
        yuv_data_raw = dequeue()
        while yuv_data_raw == None:
            yuv_data_raw = dequeue()
        yuv_data = struct.unpack('c'*1620*1920, yuv_data_raw)
        yuv_img = np.array(list(map(ord, yuv_data)), dtype=np.uint8).reshape(1620,1920)
        print(str(yuv_img.shape))
        
        imageToProcess = cv2.cvtColor(yuv_img, cv2.COLOR_YUV2RGB_I420)
        print('cvt to rgb end')
        datum.cvInputData = imageToProcess
        print('start analyze')
        opWrapper.emplaceAndPop([datum])
        print('analyze end')
        rgba_data = cv2.cvtColor(datum.cvOutputData, cv2.COLOR_BGR2BGRA)
        print('cvt to rgba end')
        rgba_bin = rgba_data.reshape(1920*1080*4).ctypes.data
        print('start enqueue')
        while enqueue(rgba_bin) == -1:
            pass
Example #27
0
    def openpose_hand_detect(self, handRectangles, cv_image):
        # Create new datum
        datum = op.Datum()
        datum.cvInputData = cv_image
        datum.handRectangles = handRectangles

        # Process and display image
        self.opWrapper.emplaceAndPop([datum])
        # Uncomment to see the output of openpose
        # [hand_position_pixel_x, hand_position_pixel_y, probability]
        # print("Right hand keypoints: \n" + str(datum.handKeypoints[0]))
        # print("Left hand keypoints: \n" + str(datum.handKeypoints[1]))
        pCount_left = 0
        pCount_right = 0
        for i in range(2):
            # i=0 right hand
            # i=1 left hand
            temp_hand = datum.handKeypoints[i]
            for point in datum.handKeypoints[i][0]:
                if point[2] > 4e-1 and i == 0:
                    pCount_right += 1
                if point[2] > 4e-1 and i == 1:
                    pCount_left += 1
        if pCount_left > 6:
            self.pub_result.publish("Left hand detected")
        if pCount_right > 6:
            self.pub_result.publish("Right hand detected")
        if pCount_left < 6 and pCount_right < 6:
            self.pub_result.publish("No hand detected")

        cv2.imshow("wave detect result", datum.cvOutputData)
        cv2.imwrite(
            "/home/zmx/catkin_ws/src/kamerider_image/kamerider_image_detection/result/wave_detect_result.png",
            datum.cvOutputData)
        cv2.waitKey(1)
def main():
    with open("openpose_config.yml", 'r') as ymlfile:
        if sys.version_info[0] > 2:
            cfg = yaml.load(ymlfile, Loader=yaml.FullLoader)
        else:
            cfg = yaml.load(ymlfile)

    # Custom Params (refer to include/openpose/flags.hpp for more parameters)
    params = dict()
    # params["model_folder"] = "/home/benjamin/CMU/openpose/models/"
    params["model_folder"] = cfg['model_folder']
    params["model_pose"] = cfg['model_pose']

    # Starting OpenPose
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()

    # Process Image
    datum = op.Datum()

    # walk 'unique' for renamable list
    image_list = []
    for (dirpath, dirnames, filenames) in walk(cfg['image_folder']):
        image_list.extend(filenames)
        break

    images_processed = 0
    for image in image_list:
        current_image = cfg['image_folder'] + image
        keypoint_file = cfg['keypoint_folder'] + image[:-4]
        output_file = cfg['output_folder'] + image
        # print("output_file = {}".format(output_file))
        # print("current_image = {}".format(current_image))

        imageToProcess = cv2.imread(current_image)
        datum.cvInputData = imageToProcess
        opWrapper.emplaceAndPop([datum])

        # Save numpy arrays
        if cfg['save_keypoints']:
            # print("Body keypoints: \n" + str(datum.poseKeypoints))
            # print(type(datum.cvOutputData))
            np.save(keypoint_file, datum.poseKeypoints)

        # Display Image
        if cfg['show_images']:
            cv2.imshow(image, datum.cvOutputData)
            cv2.waitKey(0)
            cv2.destroyWindow(image)

        if cfg['save_output_image']:
            cv2.imwrite(output_file, datum.cvOutputData)

        images_processed += 1
        if images_processed % 100 == 0:
            print("\n    Images to process remaining in {} : {} \n").format(
                cfg['image_folder'],
                len(image_list) - images_processed)
Example #29
0
    def __init__(self):
        params = dict()
        params["model_folder"] = model_folder

        self.opWrapper = op.WrapperPython()
        self.opWrapper.configure(params)
        self.opWrapper.start()
        self.datum = op.Datum()
Example #30
0
    def estimate_pose(self, imageToProcess):
        datum = op.Datum()
        if not isinstance(imageToProcess, np.ndarray):
            return None
        datum.cvInputData = imageToProcess
        self.opWrapper.emplaceAndPop([datum])

        return datum