OpenCV3与深度学习实例-使用OpenPose进行人体姿态估算

 

import cv2
import time
import numpy as np
import matplotlib.pyplot as plt
import os


# Load a Caffe Model

if not os.path.isdir('model'):
  os.mkdir("model")    

protoFile = "datas/models/caffe/openpose/pose_deploy_linevec_faster_4_stages.prototxt"
weightsFile = "datas/models/caffe/openpose/pose_iter_160000.caffemodel"


# Specify number of points in the model 
nPoints = 15
POSE_PAIRS = [[0,1], [1,2], [2,3], [3,4], [1,5], [5,6], [6,7], [1,14], [14,8], [8,9], [9,10], [14,11], [11,12], [12,13] ]
net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)


# Read Image
im = cv2.imread("datas/images/man.jpg")
im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
inWidth = im.shape[1]
inHeight = im.shape[0]


# Convert image to blob
netInputSize = (368, 368)
inpBlob = cv2.dnn.blobFromImage(im, 1.0 / 255, netInputSize, (0, 0, 0), swapRB=True, crop=False)
net.setInput(inpBlob)


# Run Inference (forward pass)
output = net.forward()

# Display probabi

你可能感兴趣的:(深度学习)