單人的姿態檢測|tensorflow singlepose
import tensorflow as tf
import tensorflow_hub as hub
import cv2
from matplotlib import pyplot as plt
import numpy as np
def movenet(input_image):
"""Runs detection on an input image.
Args:
input_image: A [1, height, width, 3] tensor represents the input image
pixels. Note that the height/width should already be resized and match the
expected input resolution of the model before passing into this function.
Returns:
A [1, 1, 17, 3] float numpy array representing the predicted keypoint
coordinates and scores.
"""
# Download the model from TF Hub.
model = hub.load("https://tfhub.dev/google/movenet/singlepose/lightning/4")
model = model.signatures['serving_default']
# SavedModel format expects tensor type of int32.
input_image = tf.cast(input_image, dtype=tf.int32)
# Run model inference.
outputs = model(input_image)
# Output is a [1, 1, 17, 3] tensor.
keypoints_with_scores = outputs['output_0'].numpy()
keypoints_with_scores = keypoints_with_scores.reshape((1, 17, 3))
return keypoints_with_scores
def draw_keypoints(frame, keypoints, confidence_threshold):
y, x, c = frame.shape
shaped = np.squeeze(np.multiply(keypoints, [y, x, 1]))
print("shaped in draw_keypoints:", shaped)
for kp in shaped:
ky, kx, kp_conf = kp
if kp_conf > confidence_threshold:
cv2.circle(frame, (int(kx), int(ky)), 6, (0, 255, 0), -1)
EDGES = {
(0, 1): 'm',
(0, 2): 'c',
(1, 3): 'm',
(2, 4): 'c',
(0, 5): 'm',
(0, 6): 'c',
(5, 7): 'm',
(7, 9): 'm',
(6, 8): 'c',
(8, 10): 'c',
(5, 6): 'y',
(5, 11): 'm',
(6, 12): 'c',
(11, 12): 'y',
(11, 13): 'm',
(13, 15): 'm',
(12, 14): 'c',
(14, 16): 'c'
}
def draw_connections(frame, keypoints, edges, confidence_threshold):
print('frame', frame)
y, x, c = frame.shape
shaped = np.squeeze(np.multiply(keypoints, [y, x, 1]))
for edge, color in edges.items():
p1, p2 = edge
y1, x1, c1 = shaped[p1]
y2, x2, c2 = shaped[p2]
if (c1 > confidence_threshold) & (c2 > confidence_threshold):
cv2.line(frame, (int(x1), int(y1)), (int(x2), int(y2)), (0, 0, 255), 4)
def loop_through_people(frame, keypoints_with_scores, edges, confidence_threshold):
for person in keypoints_with_scores:
draw_connections(frame, person, edges, confidence_threshold)
draw_keypoints(frame, person, confidence_threshold)
image_path =跟單網gendan5.com 'C:/Users/Harry/Desktop/fitness.jpeg'
image = tf.io.read_file(image_path)
# image = tf.compat.v1.image.decode_image(image)
image = tf.compat.v1.image.decode_jpeg(image)
# Resize and pad the image to keep the aspect ratio and fit the expected size.
input_size = 192
input_image = tf.expand_dims(image, axis=0)
input_image = tf.image.resize_with_pad(input_image, input_size, input_size)
# Run model inference.
keypoints_with_scores = movenet(input_image)
display_image = tf.cast(tf.image.resize_with_pad(image, 1280, 1280), dtype = tf.int32)
display_image = np.array(display_image)
origin_image = np.copy(display_image)
loop_through_people(display_image, keypoints_with_scores, EDGES, 0.1)
plt.subplot(1, 2, 1)
plt.imshow(origin_image)
plt.subplot(1, 2, 2)
plt.imshow(display_image)
plt.show()
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69946337/viewspace-2906188/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 無需人臉檢測,即可實時,6自由度3維人臉姿態估計方法
- 人臉檢測的harr檢測函式函式
- 【3D】姿態檢測網路PoseCNN復現過程記錄3DCNN
- 活體檢測API對接php語言方式-人臉靜態/動態活體檢測免費APIPHP
- 基於opencv實現簡單人臉檢測OpenCV
- CPU上跑到 33 FPS 的簡單輕量級人體姿態估計網路
- [深度學習]人臉檢測-Tensorflow2.x keras程式碼實現深度學習Keras
- 人臉檢測識別,人臉檢測,人臉識別,離線檢測,C#原始碼C#原始碼
- 深度有趣 | 11 TensorFlow物體檢測
- [計算機視覺]人臉應用:人臉檢測、人臉對比、五官檢測、眨眼檢測、活體檢測、疲勞檢測計算機視覺
- 人臉檢測 二
- 人眼疲勞檢測之opencv人眼檢測xml說明OpenCVXML
- 檢測mysql狀態的指令碼MySql指令碼
- 人臉活體檢測
- 前端人臉檢測指南前端
- 檢測網路狀態
- JavaScript人臉檢測的實現方法JavaScript
- IT人喝酒不同崗位不同姿態,最服程式設計師!程式設計師
- 【譯】.NET 的新的動態檢測分析
- 加盟依圖科技後,顏水成首篇頂會論文提出“多人體姿態檢測SPM”
- opencv視訊人臉檢測OpenCV
- OpenCV 人臉檢測自學(3)OpenCV
- 30秒輕鬆實現TensorFlow物體檢測
- 檢測網路狀態 - flutterFlutter
- iOS 檢測網路狀態iOS
- APISpace的 人臉檢測API 它來啦~API
- 80篇CVPR 2020論文分方向整理:目標檢測/影像分割/姿態估計等
- Mediapipe入門——搭建姿態檢測模型並實時輸出人體關節點3d座標API模型3D
- Facebook實時人體姿態估計:Dense Pose及其應用展望
- CVPR 2024 | 讓影片姿態Transformer變得飛速,北大提出高效三維人體姿態估計框架HoTORM框架
- 實時單人姿態估計,在自己手機上就能實現 : ) 安卓和iOS都可以哦~安卓iOS
- 機器人位姿描述機器人
- 網路狀態檢測的利器 - ss命令
- 實驗18-使用TensorFlow完成影片物體檢測
- TensorFlow 的簡單例子單例
- 目標檢測 YOLO v3 訓練 人臉檢測模型YOLO模型
- iOS 人臉關鍵點檢測iOS
- Android人臉檢測介紹Android