PaddleHub
PaddleHub copied to clipboard
下面这个代码,识别的很慢吗?
只有不到10帧,怎么才能做个火柴人的功能呢。流畅的。
import requests
import json
import cv2
import base64
def cv2_to_base64(image):
data = cv2.imencode('.jpg', image)[1]
return base64.b64encode(data.tostring()).decode('utf8')
cap = cv2.VideoCapture(0)
while (True):
# 开始用摄像头读数据,返回hx为true则表示读成功,frame为读的图像
hx, frame = cap.read()
data = {'images': [cv2_to_base64(frame)]}
headers = {"Content-type": "application/json"}
url = "http://127.0.0.1:8866/predict/human_pose_estimation_resnet50_mpii"
r = requests.post(url=url, headers=headers, data=json.dumps(data))
# 打印预测结果
print(r.json()["results"])
# 如果hx为Flase表示开启摄像头失败,那么就输出"read vido error"并退出程序
if hx is False:
# 打印报错
print('read video error')
# 退出程序
exit(0)
# 显示摄像头图像,其中的video为窗口名称,frame为图像
cv2.imshow('video', frame)
# 监测键盘输入是否为q,为q则退出程序
if cv2.waitKey(1) & 0xFF == ord('q'): # 按q退出
break
# 释放摄像头
cap.release()
# 结束所有窗口
cv2.destroyAllWindows()
# 发送HTTP请求
# data = {'images':[cv2_to_base64(cv2.imread("./test_image.jpg"))]}
# headers = {"Content-type": "application/json"}
# url = "http://127.0.0.1:8866/predict/human_pose_estimation_resnet50_mpii"
# r = requests.post(url=url, headers=headers, data=json.dumps(data))
#
# # 打印预测结果
# print(r.json()["results"])
https://github.com/PaddlePaddle/PaddleHub/tree/release/v2.2/modules/image/keypoint_detection/human_pose_estimation_resnet50_mpii
可调用模型时将use_gpu打开:https://github.com/PaddlePaddle/PaddleHub/blob/release/v2.2/modules/image/keypoint_detection/human_pose_estimation_resnet50_mpii/module.py#L58
可调用模型时将use_gpu打开:https://github.com/PaddlePaddle/PaddleHub/blob/release/v2.2/modules/image/keypoint_detection/human_pose_estimation_resnet50_mpii/module.py#L58
那我看别人的摄像头,几百块做的火柴人的模型比这个强大吗?不应该啊,用GPU的价格就好几千了。