jetson nano 人体姿态识别
识别 Jetson NANO 人体 姿态
2023-09-14 09:15:50 时间
jetpack 版本 4.2 ,直接安装 gluoncv ,如果需要能直接跑nano的镜像,可以加入星球,
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 1 17:17:29 2021
@author: ledi
"""
import cv2
def gstreamer_pipeline(
capture_width=1280,
capture_height=720,
display_width=1280,
display_height=720,
framerate=60,
flip_method=0,
):
return (
"nvarguscamerasrc ! "
"video/x-raw(memory:NVMM), "
"width=(int)%d, height=(int)%d, "
"format=(string)NV12, framerate=(fraction)%d/1 ! "
"nvvidconv flip-method=%d ! "
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
"videoconvert ! "
"video/x-raw, format=(string)BGR ! appsink"
% (
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)
# def show_camera():
# cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
# while cap.isOpened():
# flag, img = cap.read()
# cv2.imshow("CSI Camera", img)
# kk = cv2.waitKey(1)
# # do other things
# if kk == ord('q'): # 按下 q 键,退出
# break
# cap.release()
# cv2.destroyAllWindows()
#from __future__ import division
import argparse, time, logging, os, math, tqdm, cv2
import numpy as np
import mxnet as mx
from mxnet import gluon, nd, image
from mxnet.gluon.data.vision import transforms
import matplotlib.pyplot as plt
import gluoncv as gcv
from gluoncv import data
from gluoncv.data import mscoco
from gluoncv.model_zoo import get_model
from gluoncv.data.transforms.pose import detector_to_simple_pose, heatmap_to_coord
from gluoncv.utils.viz import cv_plot_image, cv_plot_keypoints
ctx = mx.cpu()
detector_name = "ssd_512_mobilenet1.0_coco"
detector = get_model(detector_name, pretrained=True, ctx=ctx)
detector.reset_class(classes=['person'], reuse_weights={'person':'person'})
detector.hybridize()
estimator = get_model('simple_pose_resnet18_v1b', pretrained='ccd24037', ctx=ctx)
estimator.hybridize()
#cap = cv2.VideoCapture(0)
time.sleep(1) ### letting the camera autofocus
axes = None
num_frames = 100
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
while cap.isOpened():
flag, frame = cap.read()
print(11111)
# cv2.imshow("CSI Camera", img)
# kk = cv2.waitKey(1)
# # do other things
# if kk == ord('q'): # 按下 q 键,退出
# break
# ret, frame = cap.read()
frame = mx.nd.array(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).astype('uint8')
print(2222)
x, frame = gcv.data.transforms.presets.ssd.transform_test(frame, short=512, max_size=350)
print(333)
x = x.as_in_context(ctx)
class_IDs, scores, bounding_boxs = detector(x)
print(444)
pose_input, upscale_bbox = detector_to_simple_pose(frame, class_IDs, scores, bounding_boxs,
output_shape=(128, 96), ctx=ctx)
print(pose_input)
if len(upscale_bbox) > 0:
predicted_heatmap = estimator(pose_input)
pred_coords, confidence = heatmap_to_coord(predicted_heatmap, upscale_bbox)
img = cv_plot_keypoints(frame, pred_coords, confidence, class_IDs, bounding_boxs, scores,
box_thresh=0.5, keypoint_thresh=0.2)
cv_plot_image(img)
if cv2.waitKey(1) & 0xFF == ord('q'):
# 存储图片
cv2.imwrite("camera.jpeg", frame)
break
#python cam_demo.py --num-frames 100
相关文章
- 【华为云技术分享】云图说|人工智能新科技—文字识别服务
- Solidworks如何自动打开和关闭特征识别FeatureWorks
- selenium借助AutoIt识别上传(下载)详解
- [Wap] 识别访问手机的能力
- SAS信用评分之番外篇异常值的识别
- Python视觉深度学习系列教程 第三卷 第9章 Kaggle竞赛:情绪识别
- 有没有高效的记视频笔记方法?--天若OCR文字识别记视频笔记
- Atitit 图像处理--图像分类 模式识别 肤色检测识别原理 与attilax的实践总结
- 详解GaussDB(DWS)的query_band负载识别与应用
- Jetson_Zoo,jetson nano
- 在OpenCV里使用减法识别数字
- python OCR识别验证码
- 网络流量分析——NPMD关注IT运维、识别宕机和运行不佳进行性能优化。智能化分析是关键-主动发现业务运行异常。科来做APT相关的安全分析
- matlab 男女声识别+源码
- Python基于深度学习yolov5的扑克牌识别
- r去掉向量中的空字符串 在R里如何去掉字符串矩阵中的空字符串 r r 识别字符串中的双引号 识别字符串中的双引号 str_detect