MAC 配置openpose和python API的使用

MAC 配置openpose和python API的使用

无GPU,使用CPU,python环境为3.8.

安装python

  1. 安装Xcode,MAC应用商店安装
  2. 安装brew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

在这里插入图片描述
出现如下显示,说明安装成功
在这里插入图片描述

  1. 安装python
brew install python

下载项目

git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose

获取model

brew install wget
bash getModels.sh

如果下载速度慢,这里提供下载好的模型放到相应的位置。
./models/… 文件中自己替换。
链接: https://pan.baidu.com/s/1nTaaUi0SstuH2vUGSiVXPg 密码: 95n8

安装CMAKE

brew cask install cmake

安装Caffe, OpenCV, and Caffe prerequisites

bash scripts/osx/install_deps.sh

CMAKE设置

打开CMAKE
在这里插入图片描述
设置source code源码的位置以及build的位置;
souce code的位置就选你自己的openpose放置的目录;
build的话可以自己话创建一下,我把它设置在openpose/build/, 这样方便管理;
在这里插入图片描述

点击Configure按键, 然后确认一下Generator是不是Unix Makefile
错误:
在这里插入图片描述
解决方案:

定位到最关键的报错信息:

Caffe will be built from source now.
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.17/Modules/ExternalProject.cmake:2659 (message):
  No download info given for 'openpose_lib' and its source directory:

   /Users/lovelyqian/study/openpose/3rdparty/caffe

  is not an existing non-empty directory.  Please specify one of:

   * SOURCE_DIR with an existing non-empty directory
   * DOWNLOAD_COMMAND
   * URL
   * GIT_REPOSITORY
   * SVN_REPOSITORY
   * HG_REPOSITORY
   * CVS_REPOSITORY and CVS_MODULE
Call Stack (most recent call first):
  /Applications/CMake.app/Contents/share/cmake-3.17/Modules/ExternalProject.cmake:3267 (_ep_add_download_command)
  CMakeLists.txt:796 (ExternalProject_Add)

大概意思是cmake GUI没有办法为我们下载Caffe的安装包。

进入到openpose/3rdparty中发现caffe目录是空的;

所以执行git clone https://github.com/CMU-Perceptual-Computing-Lab/caffe将openpose支持的caffe下载下来。

再次点击Configure and Generate:
在这里插入图片描述

Openpose building

cd build/
make -j`sysctl -n hw.logicalcpu`

试运行

./build/examples/openpose/openpose.bin --video examples/media/video.avi

python api使用

import sys
import cv2
import os
from sys import platform
import argparse

def wxfopenpose(i):
    try:
        dir_path = os.path.dirname(os.path.realpath(__file__))
        try:
            sys.path.append('/usr/local/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
        parser = argparse.ArgumentParser()
        args = parser.parse_known_args()
        params = dict()
        params["model_folder"] = "../../models/"
        params["face"] = True
        params["hand"] = True
        for i in range(0, len(args[1])):
            curr_item = args[1][i]
            if i != len(args[1]) - 1:
                next_item = args[1][i + 1]
            else:
                next_item = "1"
            if "--" in curr_item and "--" in next_item:
                key = curr_item.replace('-', '')
                if key not in params:  params[key] = "1"
            elif "--" in curr_item and "--" not in next_item:
                key = curr_item.replace('-', '')
                if key not in params: params[key] = next_item
        opWrapper = op.WrapperPython()
        opWrapper.configure(params)
        opWrapper.start()
        datum = op.Datum()
        #imageToProcess = cv2.imread('../../examples/media/COCO_val2014_000000000241.jpg')
        datum.cvInputData = i
        opWrapper.emplaceAndPop([datum])
        print("Body keypoints: \n" + str(datum.poseKeypoints))
        print("Face keypoints: \n" + str(datum.faceKeypoints))
        print("Left hand keypoints: \n" + str(datum.handKeypoints[0]))
        print("Right hand keypoints: \n" + str(datum.handKeypoints[1]))
        # cv2.imshow("OpenPose 1.6.0 - Tutorial Python API", datum.cvOutputData)
        # cv2.waitKey(0)
        return datum
    except Exception as e:
        print(e)
        sys.exit(-1)

# 打开摄像头并灰度化显示
import cv2

capture = cv2.VideoCapture(0)

while(True):
    # 获取一帧
    ret, frame = capture.read()
    # 将这帧转换为灰度图
#    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    a = wxfopenpose(frame)

    cv2.imshow('frame', a.cvOutputData)
    if cv2.waitKey(1) == ord('q'):
        break

注:调试时一定要用当前默认python环境,不要使用anaconda的python环境。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值