使用Pthon中的Opencv获取人体关键点并再在unity中展
为了给同门们做备忘录。细到扣脚没有你打我。细节细节细节(重要的......)
目录
一、环境配置
二、pycharm的操作
三、Unity中的操作
一、环境配置
电脑配置
1.1Python的下载安装
1.2Pycharm的下载安装
1.3Unity Hub的下载
在Hub里面下载Unity
1.3.1Unity的下载
1.3.2项目创建
1.4VisualStudio的下载
二、pycharm的操作 1建立项目(补上?) 2配置工具包
Pycharm专业版(professional)本来整的社区版的我也不知道为啥变成了这样。
先来配置环境进入File>Projectuserfiles(项目名称)Python Interpreter(这里已经是装了几个工具包的样子了)看看有哪些工具包,一会安装工具包也需要在这里。
书写代码,这里有个“BUG”能看出来的举手
from cvzone.PoseModule import PoseDetector
import cv2
cap = cv2.VideoCapture("Video.mp4")
detector = PoseDetector()
hile True:
suess, img = cap.read()
img = detector.findPose(img)
lmList, bboxInfo = detector.findPosition(img)
cv2.imsho("Image", img)
cv2.aitkey(1)
调出视频看看成成功不
报错了
File>Projectuserfiles(项目名称)>Python Interpreter>左下角的“+”号>
点开Manage Repositories更镜像源网站
点击小加号把网站放进去
https://pypi.tuna.tsinghua.edu./simple/
返回到这个页面再搜索框里输入想要的安装包名称
so 我们安装一下google
还有 protobuf
又有错误了
所以再安装matplotlib
So红色我的最爱
继续安装不过这里要安装“attrs”
成功了视频一闪而过并提示 ,错误在“aitKey”K要大写,(对这就是那个BUG)
from cvzone.PoseModule import PoseDetector
import cv2
cap = cv2.VideoCapture("Video.mp4")
detector = PoseDetector()
hile True:
suess, img = cap.read()
img = detector.findPose(img)
lmList, bboxInfo = detector.findPosition(img)
cv2.imsho("Image", img)
cv2.aitKey(1)
这样就成功了~ 模特是你们可爱的琦学长
这里只调动了CPU,并为启动GPU所以you'dai
运行
from cvzone.PoseModule import PoseDetector
import cv2
cap = cv2.VideoCapture("Video.mp4")
detector = PoseDetector()
hile True:
suess, img = cap.read()
img = detector.findPose(img)
lmList, bboxInfo = detector.findPosition(img)
if bboxInfo:
lmString = ""
for lm in lmList:
print(lm)
cv2.imsho("Image", img)
cv2.aitKey(1)
得出
下一步将数据存在文件中
import cv2
from cvzone.PoseModule import PoseDetector
cap = cv2.VideoCapture('Video.mp4')
detector = PoseDetector()
posList = []
hile True:
suess, img =cap.read()
img = detector.findPose(img)
lmList,bboxInfo = detector.findPosition(img)
if bboxInfo:
lmString = ""
for lm in lmList:
lmString += f'{lm[1]},{img.shape[0] - lm[2]},{lm[3]} , '
posList.append(lmString)
print(len(posList))
cv2.imsho("Image",img)
key = cv2.aitKey(1)
if key == ord("1"):#按“1”按键这个整了4个小时,...(简直是天才~)
ith open("data.txt","") as f:
f.ritelines(['%sn'% item for item in posList])
这个“1”要在英文输入法中按切记。就这样我们得到了数据啦啦啦啦啦~
三、Unity中的操作
3.1Unity的配置
申请账号、
3.1建立项目
点击Create project
建立C#文件
这是导入并执行文件的代码可以显示动画咯
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.Threading;
public class AnimationCode : MonoBehaviour
{
public GameObject[] Body;
List lines;
int counter = 0;
// Start is called before the first frame update
void Start()
{
lines = System.IO.File .ReadLines("Assets/data.txt").ToList();
}
// Update is called once per frame
void Update()
{
string[] points = lines[counter].Split(',');
for (int i = 0; i <= 32; i++)
{
float x = float.Parse(points[0 + (i 3)]) / 100;
float y = float.Parse(points[1 + (i 3)]) / 100;
float z = float.Parse(points[2 + (i 3)]) / 100;
Body[i].transform.localPosition = ne Vector3(x, y, z);
}
counter += 1;
if (counter == lines.Count) { counter = 0; }
Thread.Sleep(30);
}
}
下一步就是在球球中间连线编辑C#文件
上代码了Script点的
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.Threading;
public class AnimationCode : MonoBehaviour
{
public GameObject[] Body;
List lines;
int counter = 0;
// Start is called before the first frame update
void Start()
{
lines = System.IO.File .ReadLines("Assets/202204131410(1).mp4.txt").ToList();
}
// Update is called once per frame
void Update()
{
string[] points = lines[counter].Split(',');
for (int i = 0; i <=32; i++)
{
float x = float.Parse(points[0 + (i 3)]) / 100;
float y = float.Parse(points[1 + (i 3)]) / 100;
float z = float.Parse(points[2 + (i 3)]) / 300;
Body[i].transform.localPosition = ne Vector3 (x,y,z);
// Debug.Log(Body.Length);
}
counter += 1;
if (counter == lines.Count) { counter = 0; }
Thread.Sleep(90);
}
}
线的Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LineCode : MonoBehaviour
{
LineRenderer lineRenderer;
public Transform origin;
public Transform destination;
// Start is called before the first frame update
void Start()
{
lineRenderer = GetComponent();
lineRenderer.startWidth = 0.05f;
lineRenderer.endWidth = 0.05f;
}
// Update is called once per frame
void Update()
{
lineRenderer.SetPosition(0, origin.position);
lineRenderer.SetPosition(1, destination.position);
}
}
环境配置
- 安装python、IDE(pycharm)、Unity Hub、Unity、visual studio就不在这做讲解了(有其他的道友。)
得空了再填加。
参考网站(科学上网)
https://.youtube./atch?v=BtMs0ysTdkM
空调维修
- 我的世界电脑版运行身份怎么弄出来(我的世界
- 空调抽湿是什么意思,设置抽湿的温度有什么意
- 方太燃气灶有一个打不着火 怎么修复与排查方法
- 夏季免费清洗汽车空调的宣传口号
- 清洗完空调后出现漏水现象
- iphone6能玩什么游戏(iphone6游戏)
- 如何设置电脑密码锁屏(如何设置电脑密码锁屏
- win10删除开机密码提示不符合密码策略要求
- 电脑w7显示不是正版(w7不是正版怎么解决)
- 万家乐z8热水器显示e7解决 怎么修复与排查方法
- 1匹空调多少瓦数(1匹空调多少瓦)
- 安卓手机连接电脑用什么软件好(关于安卓手机
- 电脑网页看视频卡是什么原因(爱拍看视频卡)
- 华帝燃气灶点火器一直响然后熄火怎么办:问题
- 电脑壁纸怎么换(关于电脑壁纸怎么换的介绍)
- 冬天空调的出风口应该朝什么方向(冬天空调风