接口说明:http://ai.baidu.com/forum/topic/show/497747

人体关键点识别,即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片中的所有人体的14个关键点,包含四肢、脖颈、鼻子等部位,以及人体的坐标信息和数量

-----------------------------------------------------下面开始代码-----------------------------------------------------

人体关键点识别接口示例代码-(JavaAPI)

package com.xs.image;

import java.net.URLEncoder;

import com.alibaba.fastjson.JSON;

import com.xs.common.image.ImageAPI;

import com.xs.pojo.image.BodyAnalysisBean;

import com.xs.util.baidu.Base64Util;

import com.xs.util.baidu.FileUtil;

import com.xs.util.baidu.HttpUtil;

/**

* 人体关键点识别-JavaAPI示例代码(非官方)

* @author 小帅丶

*/

public class BodyAnalysisSample {

public static void main(String[] args) throws Exception {

//返回字符串

String result = getBodyAnalysisResult("本地图片路径", "自己的accesstoken");

System.out.println(result);

//返回java对象

//BodyAnalysisBean bodyAnalysisBean = getBodyAnalysisBean("本地图片路径", "自己的accesstoken");

//System.out.println("图中有"+bodyAnalysisBean.getPerson_num()+"个人");

}

/**

* 人体关键点识别Demo

* @param imagePath

* @param accessToken

* @return 字符串

* @throws Exception

*/

public static String getBodyAnalysisResult(String imagePath,String accessToken) throws Exception{

byte[] imgData = FileUtil.readFileByBytes(imagePath);

String imgStr = Base64Util.encode(imgData);

String param = "image=" + URLEncoder.encode(imgStr,"UTF-8");

// 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。

String result = HttpUtil.post(ImageAPI.BODYANALYSIS_API, accessToken, param);

System.out.println(result);

return result;

}

/**

* 人体关键点识别Demo

* @param imagePath

* @param accessToken

* @return CarMode对象

* @throws Exception

*/

public static BodyAnalysisBean getBodyAnalysisBean(String imagePath,String accessToken) throws Exception{

byte[] imgData = FileUtil.readFileByBytes(imagePath);

String imgStr = Base64Util.encode(imgData);

String param = "image=" + URLEncoder.encode(imgStr,"UTF-8");

// 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。

String result = HttpUtil.post(ImageAPI.BODYANALYSIS_API, accessToken, param);

BodyAnalysisBean bodyAnalysisBean = JSON.parseObject(result,BodyAnalysisBean.class);

System.out.println(result);

return bodyAnalysisBean;

}

}

识别返回的JSON数据(特别长,不做格式化)

{"person_num": 2, "person_info": [{"body_parts": {"right_wrist": {"y": 187.1351776123047, "x": 356.5876770019531}, "right_hip": {"y": 245.2404174804688, "x": 334.6790466308594}, "neck": {"y": 129.0636596679688, "x": 363.0102233886719}, "left_shoulder": {"y": 130.3773803710938, "x": 382.3029479980469}, "left_knee": {"y": 333.028076171875, "x": 375.8851013183594}, "right_elbow": {"y": 183.2697601318359, "x": 306.3629760742188}, "right_shoulder": {"y": 127.7778701782227, "x": 343.6992492675781}, "right_ankle": {"y": 441.4400329589844, "x": 290.8769836425781}, "left_hip": {"y": 246.5243682861328, "x": 364.3192138671875}, "left_ankle": {"y": 440.1803283691406, "x": 396.4710693359375}, "left_elbow": {"y": 189.7247772216797, "x": 374.6240844726562}, "left_wrist": {"y": 0.0, "x": 0.0}, "right_knee": {"y": 338.1686706542969, "x": 317.9450988769531}, "nose": {"y": 91.65258026123047, "x": 393.8951416015625}}, "location": {"width": 171.0154724121094, "top": 49.52960968017578, "left": 258.1662902832031, "height": 425.4703979492188}}, {"body_parts": {"right_wrist": {"y": 219.4005584716797, "x": 136.4501953125}, "right_hip": {"y": 220.7348327636719, "x": 133.8620758056641}, "neck": {"y": 103.2406234741211, "x": 141.5971832275391}, "left_shoulder": {"y": 101.9672470092773, "x": 158.2781219482422}, "left_knee": {"y": 296.859619140625, "x": 141.5889587402344}, "right_elbow": {"y": 162.6289672851562, "x": 117.1964874267578}, "right_shoulder": {"y": 105.8178405761719, "x": 128.6884613037109}, "right_ankle": {"y": 373.0259094238281, "x": 106.87158203125}, "left_hip": {"y": 220.7161102294922, "x": 150.6210479736328}, "left_ankle": {"y": 374.3226928710938, "x": 119.7342681884766}, "left_elbow": {"y": 165.2007141113281, "x": 154.4678649902344}, "left_wrist": {"y": 222.0592193603516, "x": 166.0699157714844}, "right_knee": {"y": 302.0010681152344, "x": 160.9004821777344}, "nose": {"y": 63.22677230834961, "x": 180.2331695556641}}, "location": {"width": 153.0357818603516, "top": 23.61567878723145, "left": 67.03448486328125, "height": 382.5894470214844}}], "log_id": 1955353647031530539}

原图文件

即使图上有17个人也是可以返回每个人的姿态信息哦(最好是有半个身子)

字符串返回不太方便处理。那就对象处理。不会转对象的。我已经帮忙做了。

JavaBean对象:

package com.xs.pojo.image;

import java.util.List;

/**

* 人体关键点识别 JavaBean

* @author 小帅丶

*

*/

public class BodyAnalysisBean {

//人体数目

private int person_num;

//人体姿态信息

private List person_info;

//唯一的log id,用于问题定位

private long log_id;

public int getPerson_num() {

return person_num;

}

public void setPerson_num(int person_num) {

this.person_num = person_num;

}

public List getPerson_info() {

return person_info;

}

public void setPerson_info(List person_info) {

this.person_info = person_info;

}

public long getLog_id() {

return log_id;

}

public void setLog_id(long log_id) {

this.log_id = log_id;

}

public static class Person_info {

private Body_parts body_parts;

private Location location;

public void setBody_parts(Body_parts body_parts) {

this.body_parts = body_parts;

}

public Body_parts getBody_parts() {

return body_parts;

}

public void setLocation(Location location) {

this.location = location;

}

public Location getLocation() {

return location;

}

}

public static class Body_parts {

private Right_wrist right_wrist;

private Right_hip right_hip;

private Neck neck;

private Left_shoulder left_shoulder;

private Left_knee left_knee;

private Right_elbow right_elbow;

private Right_shoulder right_shoulder;

private Right_ankle right_ankle;

private Left_hip left_hip;

private Left_ankle left_ankle;

private Left_elbow left_elbow;

private Left_wrist left_wrist;

private Right_knee right_knee;

private Nose nose;

public void setRight_wrist(Right_wrist right_wrist) {

this.right_wrist = right_wrist;

}

public Right_wrist getRight_wrist() {

return right_wrist;

}

public void setRight_hip(Right_hip right_hip) {

this.right_hip = right_hip;

}

public Right_hip getRight_hip() {

return right_hip;

}

public void setNeck(Neck neck) {

this.neck = neck;

}

public Neck getNeck() {

return neck;

}

public void setLeft_shoulder(Left_shoulder left_shoulder) {

this.left_shoulder = left_shoulder;

}

public Left_shoulder getLeft_shoulder() {

return left_shoulder;

}

public void setLeft_knee(Left_knee left_knee) {

this.left_knee = left_knee;

}

public Left_knee getLeft_knee() {

return left_knee;

}

public void setRight_elbow(Right_elbow right_elbow) {

this.right_elbow = right_elbow;

}

public Right_elbow getRight_elbow() {

return right_elbow;

}

public void setRight_shoulder(Right_shoulder right_shoulder) {

this.right_shoulder = right_shoulder;

}

public Right_shoulder getRight_shoulder() {

return right_shoulder;

}

public void setRight_ankle(Right_ankle right_ankle) {

this.right_ankle = right_ankle;

}

public Right_ankle getRight_ankle() {

return right_ankle;

}

public void setLeft_hip(Left_hip left_hip) {

this.left_hip = left_hip;

}

public Left_hip getLeft_hip() {

return left_hip;

}

public void setLeft_ankle(Left_ankle left_ankle) {

this.left_ankle = left_ankle;

}

public Left_ankle getLeft_ankle() {

return left_ankle;

}

public void setLeft_elbow(Left_elbow left_elbow) {

this.left_elbow = left_elbow;

}

public Left_elbow getLeft_elbow() {

return left_elbow;

}

public void setLeft_wrist(Left_wrist left_wrist) {

this.left_wrist = left_wrist;

}

public Left_wrist getLeft_wrist() {

return left_wrist;

}

public void setRight_knee(Right_knee right_knee) {

this.right_knee = right_knee;

}

public Right_knee getRight_knee() {

return right_knee;

}

public void setNose(Nose nose) {

this.nose = nose;

}

public Nose getNose() {

return nose;

}

}

public static class Left_ankle {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Left_elbow {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Left_hip {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Left_knee {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Left_shoulder {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Left_wrist {

private int y;

private int x;

public void setY(int y) {

this.y = y;

}

public int getY() {

return y;

}

public void setX(int x) {

this.x = x;

}

public int getX() {

return x;

}

}

public static class Location {

private double width;

private double top;

private double left;

private double height;

public void setWidth(double width) {

this.width = width;

}

public double getWidth() {

return width;

}

public void setTop(double top) {

this.top = top;

}

public double getTop() {

return top;

}

public void setLeft(double left) {

this.left = left;

}

public double getLeft() {

return left;

}

public void setHeight(double height) {

this.height = height;

}

public double getHeight() {

return height;

}

}

public static class Neck {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Nose {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Right_ankle {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Right_elbow {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Right_hip {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Right_knee {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Right_wrist {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

public static class Right_shoulder {

private double y;

private double x;

public void setY(double y) {

this.y = y;

}

public double getY() {

return y;

}

public void setX(double x) {

this.x = x;

}

public double getX() {

return x;

}

}

}

以上就是人体关键点识别示例代码-JavaAPI形式

代码地址:https://gitee.com/xshuai/ai/blob/master/AIDemo/src/main/java/com/xs/image/BodyAnalysisSample.java

C#语言(By 图像识别群 透明色(69046437))

using AForge.Video.DirectShow;

using DevExpress.XtraBars.Docking2010.Customization;

using DevExpress.XtraEditors;

using Emgu.CV;

using Emgu.CV.Structure;

using FaceDemo.Entity;

using FaceDemo.Entity.BodyAPI;

using FaceDemo.Entity.Config;

using FaceDemo.Entity.FaceAPI;

using FaceDemo.Utils;

using Newtonsoft.Json;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Net;

using System.Text;

using System.Threading;

using System.Windows.Forms;

namespace FaceDemo

{

public partial class FormPassengerFlow XtraForm

{

public FormPassengerFlow()

{

InitializeComponent();

}

private ConfigEntity _ConfigEntity;

private string access_token;

private string authHost = httpsaip.baidubce.comoauth2.0token;获取Token POST

private string bodyAnalysisUrl = httpsaip.baidubce.comrest2.0image-classifyv1body_analysis;人体关键点识别 POST

private string bodyAttrUrl = httpsaip.baidubce.comrest2.0image-classifyv1body_attr;人体属性识别 POST

private string bodyNumUrl = httpsaip.baidubce.comrest2.0image-classifyv1body_num;人流量统计 POST

private Encoding encode = Encoding.UTF8;

private string contentType = applicationx-www-form-urlencoded;

private Rectangle detectArea = new Rectangle();检测区域

private int areaNum = 0;区域人数

private int inNum = 0;进入人数

private int outNum = 0;离开人数

private int curFPS = 1;

private bool isFormClose = false;

private void FormPassengerFlow_Load(object sender, EventArgs e)

{

_ConfigEntity = ConfigHelper.Read();

access_token = GetToken(_ConfigEntity.BodyAccount.APIKey, _ConfigEntity.BodyAccount.SecretKey);

获取并枚举所有摄像头设备

FilterInfoCollection Cameras = new FilterInfoCollection(FilterCategory.VideoInputDevice);

判断设备个数,选择第一个设备

if (Cameras != null && Cameras.Count 0)

{

VideoCaptureDevice vcd = new VideoCaptureDevice(Cameras[0].MonikerString);

检查摄像头支持的像素,优先设置为1280720

if (vcd.VideoCapabilities.ToList().Exists(p = p.FrameSize.Width == 1280 && p.FrameSize.Height == 720))

vcd.VideoResolution = vcd.VideoCapabilities.ToList().Find(p = p.FrameSize.Width == 1280 && p.FrameSize.Height == 720);

videoSourcePlayer1.VideoSource = vcd;

videoSourcePlayer1.NewFrame += VideoSourcePlayer1_NewFrame;

videoSourcePlayer1.Start();

}

}

private void VideoSourcePlayer1_NewFrame(object sender, ref Bitmap image)

{

Emgu.CV.ImageBgr, Byte imageCV = new ImageBgr, byte(image.Clone() as Bitmap);

抽帧进行客流量统计

int maxFPS = 25;

if (this.curFPS % (maxFPS Convert.ToDouble(_ConfigEntity.ImageOperate.GrabFrame)) 1)

{

if (!detectArea.IsEmpty)

{

byte[] bytes = ImageHelper.CaptureImage(imageCV.ToJpegData(), detectArea.X, detectArea.Y, detectArea.Width, detectArea.Height - detectArea.Y);

ThreadPool.QueueUserWorkItem(new WaitCallback(BodyNumLookup), bytes);

}

}

using (Graphics g = Graphics.FromImage(image))

{

设置检测区

if (detectArea.IsEmpty)

{

detectArea = new Rectangle(0, (int)(image.Height 0.4), image.Width, (int)(image.Height 0.6));

}

try

{

进入检测线

g.DrawLine(new Pen(Color.FromArgb(100, Color.Lime), 2), detectArea.X, detectArea.Y, detectArea.Width, detectArea.Y);

g.DrawString(进入检测线 ↓,

new Font(微软雅黑, 9, FontStyle.Regular),

new SolidBrush(Color.FromArgb(150, Color.Lime)),

10, detectArea.Y - 20);

离开检测线

g.DrawLine(new Pen(Color.FromArgb(100, Color.Red), 2),

0, detectArea.Height, detectArea.Width, detectArea.Height);

g.DrawString(离开检测线 ↑,

new Font(微软雅黑, 9, FontStyle.Regular),

new SolidBrush(Color.FromArgb(150, Color.Red)),

10, detectArea.Height + 5);

显示统计人数

g.DrawString(区域: + areaNum.ToString() + 人,

new Font(微软雅黑, 9, FontStyle.Regular),

new SolidBrush(Color.FromArgb(150, Color.White)),

10, 20);

g.DrawString(进入: + inNum.ToString() + 人,

new Font(微软雅黑, 9, FontStyle.Regular),

new SolidBrush(Color.FromArgb(150, Color.White)),

10, 45);

g.DrawString(离开: + outNum.ToString() + 人,

new Font(微软雅黑, 9, FontStyle.Regular),

new SolidBrush(Color.FromArgb(150, Color.White)),

10, 70);

}

catch { }

}

if (this.curFPS == maxFPS)

this.curFPS = 1;

else

this.curFPS++;

}

private void BodyNumLookup(object parameter)

{

byte[] sJpegPicBuffer = parameter as byte[];

string image = Convert.ToBase64String(sJpegPicBuffer).Replace(n, n).Replace(+, %2B);

try

{

string url = bodyNumUrl + access_token= + this.access_token;

string paras = string.Empty;

paras += image= + image ;

HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(url, paras, encode, contentType);

string content = HttpWebResponseUtility.GetResponesContent(response);

BodyNum bodyNum = JsonConvert.DeserializeObjectBodyNum(content);

this.Invoke(new MethodInvoker(() =

{

textBox1.Text = bodyNum.person_num.ToString();

}));

}

catch { }

}

private string GetToken(string client_id, string client_secret)

{

try

{

string paras = string.Empty;

string grant_type = client_credentials;

paras += grant_type= + grant_type + &;

paras += client_id= + client_id + &;

paras += client_secret= + client_secret;

HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(authHost, paras, encode, contentType);

string content = HttpWebResponseUtility.GetResponesContent(response);

OauthInfo oauthInfo = JsonConvert.DeserializeObjectOauthInfo(content);

return oauthInfo.access_token;

}

catch { }

return ;

}

private void simpleButton_ClearCount_Click(object sender, EventArgs e)

{

if (this.areaNum 0)

{

DialogResult dr = FlyoutDialog.Show(this, rn区域存在人数,确定要清除吗?rn , MessageBoxButtons.OKCancel);

if (dr == DialogResult.Cancel) return;

}

this.areaNum = 0;

this.inNum = 0;

this.outNum = 0;

}

#region 关闭窗体

private void simpleButton_Exit_Click(object sender, EventArgs e)

{

this.Close();

}

private void FormPassengerFlow_FormClosing(object sender, FormClosingEventArgs e)

{

if (videoSourcePlayer1.IsRunning)

{

videoSourcePlayer1.SignalToStop();

videoSourcePlayer1.WaitForStop();

}

this.isFormClose = true;

}

#endregion

}

}

人体模型 java代码_【人体分析-人体关键点识别】-Java示例代码相关推荐

  1. python名片打印程序代码_基于Python的名片识别接口调用代码实例

    #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #-------- ...

  2. java人体识别_【人体分析-人像分割】JavaAPI示例代码

    接口能力: 对于输入的一张图片(可正常解码,且长宽比适宜),识别人体的轮廓范围,与背景进行分离,适用于拍照背景替换.照片合成.身体特效等场景.输入正常人像图片,返回分割后的二值结果图和分割类型(目前仅 ...

  3. 看手相不?【人体分析-手部关键点】JavaAPI示例

    手相其源有西洋.印度和中国三支,中国民间的手相学源远而流长,终成博杂大观.掌纹也会随着时间发生变化.看手相分男左女右,拿男生举例子,35岁之前看左手,35之后看右手(女生相反). 接口说明可以参考 h ...

  4. python车牌识别系统开源代码_Python+Tensorflow+CNN实现车牌识别的示例代码

    一.项目概述 本次项目目标是实现对自动生成的带有各种噪声的车牌识别.在噪声干扰情况下,车牌字符分割较困难,此次车牌识别是将车牌7个字符同时训练,字符包括31个省份简称.10个阿拉伯数字.24个英文字母 ...

  5. java人体识别_【人体分析-人体属性识别】-Java示例代码

    人体属性识别,即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片中的所有人体的静态属性,包含坐标信息.性别.年龄阶段.衣着(含颜色).是否带帽子.是否带眼镜.是否背包.是否抽烟.是否使用手机. ...

  6. java printwriter 文件,java使用PrintWriter写文件,javaprintwriter写,下面示例代码演示使用Pr...

    java使用PrintWriter写文件,javaprintwriter写,下面示例代码演示使用Pr 下面示例代码演示使用PrintWriter方法写文件. PrintWriter的构造函数接受Fil ...

  7. python名片识别_基于Python的名片识别接口调用代码实例

    基于Python的名片识别接口调用代码实例 代码描述:基于Python的名片识别接口调用代码实例 #!/usr/bin/python # -*- coding: utf-8 -*- import js ...

  8. python目标检测与识别_Python 使用Opencv实现目标检测与识别的示例代码

    在上章节讲述到图像特征检测与匹配 ,本章节是讲述目标检测与识别.后者是在前者的基础上进一步完善. 在本章中,我们使用HOG算法,HOG和SIFT.SURF同属一种类型的描述符.功能代码如下: impo ...

  9. python调用百度接口实现ocr识别_Python调用百度OCR实现图片文字识别的示例代码

    百度AI提供了一天50000次的免费文字识别额度,可以愉快的免费使用!下面直接上方法: 首先在百度AI创建一个应用,按照下图创建即可,创建后会获得如下: 创建后会获得如下信息: APP_ID = '* ...

最新文章

  1. Python包管理工具Distribute的安装
  2. 用区块链改变人工智能:去中心化带来数据新范式
  3. pfSense book之静态路由
  4. 光端机与光纤收发器的应用
  5. 2021抖音电商商家经营方法论白皮书
  6. 阿呆做网站(1)--基本功能
  7. HttpRunnerManager接口自动化测试框架在win环境下搭建教程
  8. 为什么用虚拟机做服务器,虚拟机的优势:保留虚拟机的4个理由
  9. socket 支持 ipv6
  10. 概率论简明教程_Chapter-02_最大似然估计
  11. 在Novell NetWare中支持IP
  12. 隐藏微信公众号右上角的分享按钮
  13. [敏捷开发培训] 燃尽图(Burndown Chart)
  14. 二维码(微信二维码)缓存问题的解决方法
  15. 南山谷主:面包屑导航是什么意思?对SEO有何作用?
  16. 高洛峰2015年新版视频发布
  17. 深入理解GO语言:map结构原理和源码分析
  18. 【C语言】如何安装 Visual studio 2022 ?
  19. 精华阅读第 13 期 |常见的八种导致 APP 内存泄漏的问题 1
  20. 【转】不花钱,自己查论文抄袭程度

热门文章

  1. 第三章 初识MFCC以及Wavenet神经网络
  2. 在html中加一个超链接,怎么在html加超链接
  3. Ceph集群报错解决方案笔记
  4. C语言和Java的区别?
  5. 1023: 大小写转换 Python
  6. 根据字幕剪辑视频的软件
  7. Hive和数据库有什么区别
  8. 为什么加了屏蔽罩,测试效果反而不好?
  9. Java 创建文件软链接
  10. 文明游戏5的计算机配置,文明太空配置要求 最低电脑配置要求