Commit 0ddeb16d by tangjiale

废弃mixins和behaviors,原生小程序受限无法动态配置

parent 1b60b956
......@@ -3,14 +3,11 @@
* @eMail: 932055106@qq.com
* @Date: 2022-01-13 17:47:44
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 15:08:24
* @LastEditTime: 2022-06-08 10:39:10
*/
// wx.setStorageSync('host', 'https://sdb.youchengzhang.cn/'); //正式环境
wx.setStorageSync('host', 'https://test.xiaobentiyu.cn'); //测试环境
//引入混合模式
require('./wx-mixins.js')
//ai姿势识别
const fetchWechat = require('fetch-wechat')
const tf = require('@tensorflow/tfjs-core')
......@@ -22,7 +19,7 @@ App({
onLaunch: function () {
this.autoUpdate();
wx.setStorageSync('appId', 'wxd56eb1b3b99e5cf0');
wx.setStorageSync('appId', 'wx7d7fbc0e6746baf5');
plugins.configPlugin({
// polyfill fetch function
......
......@@ -44,8 +44,8 @@
},
"compileType": "miniprogram",
"libVersion": "2.17.0",
"appid": "wxd56eb1b3b99e5cf0",
"projectname": "wx-tfs-demo",
"appid": "wx7d7fbc0e6746baf5",
"projectname": "奔腾宝贝",
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"editorSetting": {
......
......@@ -58,7 +58,7 @@ Page({
that.data.innerAudioContext.obeyMuteSwitch = false;
that.data.innerAudioContext2.obeyMuteSwitch = false;
that.loadMoveNet();
// that.loadMoveNet();
})
......
......@@ -3,7 +3,7 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 16:42:40
* @LastEditTime: 2022-06-08 11:01:27
*/
var API = require("../../../utils/request");
......@@ -16,148 +16,151 @@ var angle_boby = 0;
var angle_hand_l = 0;
module.exports = {
module.exports = Behavior({
onLoad:function(option){
},
data: {
showImageUrl:'https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/push-ups-bg.png'
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
//计算俯卧撑关键点
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算俯卧撑关键点
angle_hand_l = that.angle(keypoimts[8],keypoimts[6],keypoimts[10]);
console.log(angle_hand_l)
if(that.data.aiState == 1){
if(angle_boby >= 60){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
methods:{
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_boby >= 150 && angle_hand_l >= 130){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//计算俯卧撑关键点
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算俯卧撑关键点
angle_hand_l = that.angle(keypoimts[8],keypoimts[6],keypoimts[10]);
console.log(angle_hand_l)
if(that.data.aiState == 1){
if(angle_boby >= 60){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
//console.log('起身')
}
//站直
if(angle_boby >= 150 && angle_hand_l <= 85){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_boby >= 150 && angle_hand_l >= 130){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
//console.log('起身')
}
//站直
if(angle_boby >= 150 && angle_hand_l <= 85){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
//console.log('下去')
}
//console.log('下去')
}
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 14, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
var postData = {
projectId: 14, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../../packageA/pushUp/share/share?share=0' + '&id=' + uid + '&showMedal=1&sportTime='+that.formatSeconds(that.data.sportTime),
// })
}else{
that.setData({
aiState:4
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
})
......@@ -3,7 +3,7 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 16:21:18
* @LastEditTime: 2022-06-08 11:01:55
*/
// 拐踢毽子计算配置
......@@ -19,188 +19,190 @@ var correct = 0;
module.exports = {
module.exports = Behavior({
onLoad:function(option){
},
data: {
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
//左侧拐踢动作关键点角度
left_foot = that.angle(keypoimts[13],keypoimts[0],keypoimts[15]);
//右侧拐踢动作关键点
right_foot = that.angle(keypoimts[14],keypoimts[0],keypoimts[16]);
//计算开合跳手部关键点
angle_hand = that.angle(keypoimts[5],keypoimts[11],keypoimts[7]);
//console.log('当前参数',dir,count,angle_foot,angle_hand)
if(that.data.aiState == 1){
if(angle_hand < 60){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 10){
that.setData({
aiState:2
},()=>{
that.start();
})
methods:{
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//通过角度判断个数
if(that.data.aiState == 3){
//左侧抬脚拐踢
if(left_foot <= 135 && (keypoimts[0].x < keypoimts[15].x) && ((keypoimts[15].x - keypoimts[0].x) > 60)){
if(let_switch == 0){
count = count + 0.5;
let_switch = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
if(num > 7){
//console.log('不合格')
return false;
}
}
//左侧放脚
if((left_foot > 165 && left_foot <= 180)){
if(let_switch == 1){
count = count + 0.5;
let_switch = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//左侧拐踢动作关键点角度
left_foot = that.angle(keypoimts[13],keypoimts[0],keypoimts[15]);
//右侧拐踢动作关键点
right_foot = that.angle(keypoimts[14],keypoimts[0],keypoimts[16]);
//计算开合跳手部关键点
angle_hand = that.angle(keypoimts[5],keypoimts[11],keypoimts[7]);
//console.log('当前参数',dir,count,angle_foot,angle_hand)
if(that.data.aiState == 1){
if(angle_hand < 60){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 10){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//右侧抬脚拐踢
if(right_foot <= 135 && (keypoimts[0].x > keypoimts[16].x) && ((keypoimts[0].x - keypoimts[16].x) > 60)){
if(right_switch == 0){
count = count + 0.5;
right_switch = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//通过角度判断个数
if(that.data.aiState == 3){
//左侧抬脚拐踢
if(left_foot <= 135 && (keypoimts[0].x < keypoimts[15].x) && ((keypoimts[15].x - keypoimts[0].x) > 60)){
if(let_switch == 0){
count = count + 0.5;
let_switch = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
//右侧放脚
if((right_foot > 165 && right_foot <= 180)){
if(right_switch == 1){
count = count + 0.5;
right_switch = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//左侧放脚
if((left_foot > 165 && left_foot <= 180)){
if(let_switch == 1){
count = count + 0.5;
let_switch = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
//右侧抬脚拐踢
if(right_foot <= 135 && (keypoimts[0].x > keypoimts[16].x) && ((keypoimts[0].x - keypoimts[16].x) > 60)){
if(right_switch == 0){
count = count + 0.5;
right_switch = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
//右侧放脚
if((right_foot > 165 && right_foot <= 180)){
if(right_switch == 1){
count = count + 0.5;
right_switch = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
}
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 11, //项目id 比如跳绳
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
console.log('仰卧起坐结果',res)
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
})
}else{
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
var postData = {
projectId: 11, //项目id 比如跳绳
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
console.log('仰卧起坐结果',res)
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
})
}else{
that.setData({
aiState:4
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
})
......@@ -3,7 +3,7 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 16:50:37
* @LastEditTime: 2022-06-08 11:03:40
*/
var API = require("../../../utils/request");
......@@ -13,183 +13,183 @@ var correct = 0;//识别成功次数
var dir = 0;// 0躺下 1坐起
var dirr = 1;// 0躺下 1坐起
var angle_boby = 0;
var angle_l = 0;
var angle_r = 0;
module.exports = {
module.exports = Behavior({
onLoad:function(option){
},
data: {
showImageUrl:'https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/squat-bg.png'
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算深蹲关键点
angle_l = that.angle(keypoimts[14],keypoimts[12],keypoimts[16]);
angle_r = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
console.log('当前参数',angle_l,angle_r)
if(that.data.aiState == 1){
if(angle_l >= 150){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
methods:{
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_l >= 140){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
if(num > 7){
//console.log('不合格')
return false;
}
}
//站直
if(angle_l <= 100){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//计算深蹲关键点
angle_l = that.angle(keypoimts[14],keypoimts[12],keypoimts[16]);
angle_r = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
console.log('当前参数',angle_l,angle_r)
if(that.data.aiState == 1){
if(angle_l >= 150){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
if(angle_r >= 140){
if(dirr == 1){
count = count + 0.5;
dirr = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_l >= 140){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
//站直
if(angle_r <= 100){
if(dirr == 0){
count = count + 0.5;
dirr = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//站直
if(angle_l <= 100){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
if(angle_r >= 140){
if(dirr == 1){
count = count + 0.5;
dirr = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
//站直
if(angle_r <= 100){
if(dirr == 0){
count = count + 0.5;
dirr = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
}
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 15, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
var postData = {
projectId: 15, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url:'../../../packageA/highLegLifts/share/share?share=0' + '&id=' + uid + '&showMedal=1&sportTime='+that.formatSeconds(that.data.sportTime),
// })
}else{
that.setData({
aiState:4
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
})
\ No newline at end of file
......@@ -3,7 +3,7 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 16:20:56
* @LastEditTime: 2022-06-08 11:13:58
*/
var API = require("../../../utils/request");
......@@ -16,147 +16,151 @@ var angle_foot = 0;
var angle_hand = 0;
var correct = 0;//识别成功次数
module.exports = {
module.exports = Behavior({
onLoad:function(option){
},
data: {
showImageUrl:'https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/jumping-jacks.png'
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
//计算开合跳脚部关键点
angle_foot = that.angle(keypoimts[11],keypoimts[15],keypoimts[16]);
//计算开合跳手部关键点
angle_hand = that.angle(keypoimts[5],keypoimts[11],keypoimts[7]);
if(that.data.aiState == 1){
console.log('我是开合跳')
if(angle_hand < 60){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 10){
that.setData({
aiState:2
},()=>{
that.start();
})
methods:{
actionSend(object,app){ // 识别点
console.log('什么鬼啊------------')
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//通过角度判断个数
if(that.data.aiState == 3){
console.log('当前参数帧数',that.data.showTime,angle_foot)
if(angle_foot >= 20 && angle_hand > 120){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//计算开合跳脚部关键点
angle_foot = that.angle(keypoimts[11],keypoimts[15],keypoimts[16]);
//计算开合跳手部关键点
angle_hand = that.angle(keypoimts[5],keypoimts[11],keypoimts[7]);
if(that.data.aiState == 1){
console.log('我是开合跳')
if(angle_hand < 60){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 10){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//站直
if(angle_foot <= 20 && angle_hand < 30){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//通过角度判断个数
if(that.data.aiState == 3){
console.log('当前参数帧数',that.data.showTime,angle_foot)
if(angle_foot >= 20 && angle_hand > 120){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
//站直
if(angle_foot <= 20 && angle_hand < 30){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
}
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 11, //项目id 比如跳绳
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
var postData = {
projectId: 11, //项目id 比如跳绳
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1&sportTime='+that.formatSeconds(that.data.sportTime),
// })
}else{
that.setData({
aiState:4
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
})
......@@ -3,7 +3,7 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 16:34:33
* @LastEditTime: 2022-06-08 11:03:58
*/
var API = require("../../../utils/request");
......@@ -15,148 +15,151 @@ var dir = 0;// 0躺下 1坐起
var angle_boby = 0;
var angle_tui = 0;
module.exports = {
module.exports = Behavior({
onLoad:function(option){
},
data: {
showImageUrl:'https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/squat-bg.png'
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
//计算深蹲关键点
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算深蹲关键点
angle_tui = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
//console.log('当前参数',angle_boby,angle_tui)
if(that.data.aiState == 1){
if(angle_boby >= 150){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
methods:{
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_tui > 170){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//计算深蹲关键点
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算深蹲关键点
angle_tui = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
//console.log('当前参数',angle_boby,angle_tui)
if(that.data.aiState == 1){
if(angle_boby >= 150){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
console.log('下蹲')
}
//站直
if(angle_tui <= 100){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_tui > 170){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
console.log('下蹲')
}
//站直
if(angle_tui <= 100){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
console.log('站直')
}
console.log('站直')
}
}
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 13, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
var postData = {
projectId: 13, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../../packageA/deepSquat/share/sahre?share=0' + '&id=' + uid + '&showMedal=1&sportTime='+that.formatSeconds(that.data.sportTime),
// })
}else{
that.setData({
aiState:4
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
})
\ No newline at end of file
......@@ -3,7 +3,7 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 16:27:39
* @LastEditTime: 2022-06-08 11:04:17
*/
var API = require("../../../utils/request");
......@@ -17,179 +17,182 @@ var angle_l = 0;
var angle_r = 0;
var angle_boby = 0;
module.exports = {
module.exports = Behavior({
onLoad:function(option){
},
data: {
showImageUrl:'https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/jumping-jacks.png'
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算深蹲关键点
angle_l = that.angle(keypoimts[14],keypoimts[12],keypoimts[16]);
angle_r = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
console.log('当前参数',angle_l,angle_r)
if(that.data.aiState == 1){
if(angle_l >= 150){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
methods:{
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_l >= 150){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
if(num > 7){
//console.log('不合格')
return false;
}
}
//站直
if(angle_l <= 90){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算深蹲关键点
angle_l = that.angle(keypoimts[14],keypoimts[12],keypoimts[16]);
angle_r = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
console.log('当前参数',angle_l,angle_r)
if(that.data.aiState == 1){
if(angle_l >= 150){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
if(angle_r >= 150){
if(dirr == 1){
count = count + 0.5;
dirr = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_l >= 150){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
//站直
if(angle_r <= 90){
if(dirr == 0){
count = count + 0.5;
dirr = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//站直
if(angle_l <= 90){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
if(angle_r >= 150){
if(dirr == 1){
count = count + 0.5;
dirr = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
//站直
if(angle_r <= 90){
if(dirr == 0){
count = count + 0.5;
dirr = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
}
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 3, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
var postData = {
projectId: 3, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url:'../../../packageA/shuttlecock/share/share?share=0' + '&id=' + uid + '&showMedal=1&sportTime='+that.formatSeconds(that.data.sportTime),
// })
}else{
that.setData({
aiState:4
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
})
......@@ -3,15 +3,11 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 16:21:15
* @LastEditTime: 2022-06-08 11:04:30
*/
var API = require("../../../utils/request");
// 拐踢毽子计算配置
// AI混淆
var count = 0;
var correct = 0;
var dir = 0;// 0躺下 1坐起
var count = 0;//个数
var angle_foot = 0;
......@@ -20,209 +16,213 @@ var correct = 0;//识别成功次数
var lastAngle = 0;//上一次的角度
var pointList = [];//基准点列表
var point = 0;//基准点
var skipType = 1;//当前跳绳模式 0两者都行 1 双脚 2 单双脚交替
var equal = 0;//个数相等的次数
module.exports = {
var prey = 0;
var hanld = 0;
var hanld_a = 0;
var p = 0;
module.exports = Behavior({
onLoad:function(option){
},
data: {
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
//计算开合跳脚部关键点
angle_foot = that.angle(keypoimts[11],keypoimts[15],keypoimts[16]);
var nowPoint = (keypoimts[11].y + keypoimts[2].y) / 2;//每个的基准点
angle_knee = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
if(that.data.aiState == 1){
if(angle_foot - lastAngle < 10){
correct++;
pointList.push(nowPoint);
if(correct >= 8){
that.setData({
aiState:2
},()=>{
//console.log('当前的基准点',pointList)
const arrayAverage = arr => arr.reduce((acc, val) => acc + val, 0) / arr.length;//取平均基准点
//console.log('姿势识别成功,基准点平均数',arrayAverage(pointList));
point = arrayAverage(pointList) - 10; //基准点
that.start();
})
}
}else{
correct = 0;
pointList = [];
console.log('姿势识别失败',angle_foot)
}
}
lastAngle = angle_foot;
//通过角度判断个数
//console.log('当前基准点',nowPoint,'平均基准点',point,'当前个数',that.data.aiCount)
if(that.data.aiState == 3){
console.log('当前个数',Math.floor(count),that.data.aiCount,skipType,that.data.showTime)
if(Math.floor(count) == that.data.aiCount){
equal++;
}else{
equal = 0;
}
//console.log('相等次数',equal)
if(equal == 15){
skipType = skipType == 1 ? 2 : 1;
equal = 0;
console.log('一秒没数据,切换模式',skipType)
// if(that.data.aiCount > 0){
// console.log('自动加1')
// count = count + 1;
// }
}
//当前为双脚模式
if(skipType == 1){
if(nowPoint - 15 > point){
if(dir == 0){
count = count + 0.5;
dir = 1;
equal = 0;
that.setData({
aiCount:Math.floor(count)
})
}
}
//站直
if(nowPoint < point){
if(dir == 1){
count = count + 0.5;
dir = 0;
skipType = 1;
equal = 0;
console.log('双脚模式',nowPoint + '---' + point)
that.setData({
aiCount:Math.floor(count)
})
console.log('双脚+1')
}
}
}
console.log('当前膝盖角度',angle_knee)
//当前为单双脚模式
if(skipType == 2){
if(angle_knee >= 177){
if(dir == 0){
if(that.data.aiCount > 0 && that.data.aiCount < 270){
count = count + 1.9;
}else{
count = count + 0.5;
}
dir = 1;
equal = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
if(angle_knee <= 165){
if(dir == 1){
count = count + 0.9;
dir = 0;
skipType = 2;
equal = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
console.log('单双脚+1')
}
}
}
}
}).catch(function (err) {
console.log(err)
});
showImageUrl:'https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/jumping-jacks.png',
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 1, //项目id 比如跳绳
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
that.setData({
aiState:4
methods:{
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
//计算开合跳脚部关键点
angle_foot = that.angle(keypoimts[11],keypoimts[15],keypoimts[16]);
var nowPoint = (keypoimts[11].y + keypoimts[2].y) / 2;//每个的基准点
angle_knee = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
var pointfoot = keypoimts[16];
hanld = that.angle(keypoimts[8],keypoimts[6],keypoimts[10]);
hanld_a = that.angle(keypoimts[7],keypoimts[5],keypoimts[9]);
p = pointfoot.y;
if(that.data.aiState == 1){
if(angle_foot - lastAngle < 10){
correct++;
pointList.push(nowPoint);
if(correct >= 8){
that.setData({
aiState:2
},()=>{
//console.log('当前的基准点',pointList)
const arrayAverage = arr => arr.reduce((acc, val) => acc + val, 0) / arr.length;//取平均基准点
//console.log('姿势识别成功,基准点平均数',arrayAverage(pointList));
point = arrayAverage(pointList) - 10; //基准点
that.start();
})
}
}else{
correct = 0;
pointList = [];
console.log('姿势识别失败',angle_foot)
}
}
lastAngle = angle_foot;
//通过角度判断个数
//console.log('当前基准点',nowPoint,'平均基准点',point,'当前个数',that.data.aiCount)
if(that.data.aiState == 3){
//当前为双脚模式
if(that.data.skipType == 2){
console.log('当前角度',hanld + '脚坐标' + p + 'prey' + prey)
if(prey == 0){
prey = p
}else{
if(p > prey + 2 && hanld >= 120){
if(dir == 1){
count = count + 0.5;
dir = 0;
if(count > that.data.sportTime *5 + 20){
count = that.data.sportTime *5 + 20
}
that.setData({
aiCount:Math.floor(count)
})
}
}
if(p < prey - 2 && hanld >= 120 && (hanld <= 170 || hanld_a <= 170)){
if(dir == 0){
count = count + 0.5;
dir = 1;
if(count > that.data.sportTime *5 + 20){
count = that.data.sportTime *5 + 20
}
that.setData({
aiCount:Math.floor(count)
})
}
}
prey = p;
}
}
//console.log('当前膝盖角度',angle_knee)
//当前为单双脚模式
if(that.data.skipType == 1){
console.log('当前角度',hanld + '脚坐标' + p + 'prey' + prey)
if(prey == 0){
prey = p
}else{
if(p > prey + 2 && hanld >= 120){
if(dir == 1){
count = count + 1;
dir = 0;
if(count > that.data.sportTime *5 + 20){
count = that.data.sportTime *5 + 20
}
that.setData({
aiCount:Math.floor(count)
})
}
}
if(p < prey - 2 && hanld >= 120 && (hanld <= 170 || hanld_a <= 170)){
if(dir == 0){
count = count + 1;
dir = 1;
if(count > that.data.sportTime *5 + 20){
count = that.data.sportTime *5 + 20
}
that.setData({
aiCount:Math.floor(count)
})
}
}
prey = p;
}
}
}
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 1, //项目id 比如跳绳
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
wx.redirectTo({
// url: '../../../packageA/aiSkip/share/share?share=0' + '&id=' + uid + '&showMedal=1&sportTime='+that.formatSeconds(that.data.sportTime),
})
}else{
wx.showModal({
title: '提示',
content: res.message,
showCancel: false,
success: function (res) {
if (res.confirm) {//这里是点击了确定以后
wx.navigateBack({//返回
delta: 1
})
} else {//这里是点击了取消以后
console.log('用户点击取消')
}
}
})
}
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
})
......@@ -3,7 +3,7 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 17:09:07
* @LastEditTime: 2022-06-08 11:04:44
*/
var API = require("../../../utils/request");
......@@ -18,179 +18,181 @@ var angle_l = 0;
var angle_r = 0;
module.exports = {
module.exports = Behavior({
onLoad:function(option){
},
data: {
showImageUrl:'https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/squat-bg.png'
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算深蹲关键点
angle_l = that.angle(keypoimts[14],keypoimts[12],keypoimts[16]);
angle_r = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
console.log('当前参数',angle_l,angle_r)
if(that.data.aiState == 1){
if(angle_l >= 150){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
methods:{
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_l >= 155){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
if(num > 7){
//console.log('不合格')
return false;
}
}
//站直
if(angle_l <= 155){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算深蹲关键点
angle_l = that.angle(keypoimts[14],keypoimts[12],keypoimts[16]);
angle_r = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
console.log('当前参数',angle_l,angle_r)
if(that.data.aiState == 1){
if(angle_l >= 150){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
if(angle_r >= 155){
if(dirr == 1){
count = count + 0.5;
dirr = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_l >= 155){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
//站直
if(angle_r <= 155){
if(dirr == 0){
count = count + 0.5;
dirr = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//站直
if(angle_l <= 155){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
if(angle_r >= 155){
if(dirr == 1){
count = count + 0.5;
dirr = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
//站直
if(angle_r <= 155){
if(dirr == 0){
count = count + 0.5;
dirr = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
}
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 17, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
var postData = {
projectId: 17, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
that.setData({
aiState:4
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
})
......@@ -3,7 +3,7 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 16:57:57
* @LastEditTime: 2022-06-08 11:04:59
*/
var API = require("../../../utils/request");
......@@ -17,179 +17,181 @@ var angle_boby = 0;
var angle_l = 0;
var angle_r = 0;
module.exports = {
module.exports = Behavior({
onLoad:function(option){
},
data: {
showImageUrl:'https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/squat-bg.png'
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算深蹲关键点
angle_l = that.angle(keypoimts[14],keypoimts[12],keypoimts[16]);
angle_r = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
console.log('当前参数',angle_l,angle_r)
if(that.data.aiState == 1){
if(angle_boby >= 70){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
methods:{
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_l >= 140){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
if(num > 7){
//console.log('不合格')
return false;
}
}
//站直
if(angle_l <= 80){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
angle_boby = that.angle(keypoimts[12],keypoimts[6],keypoimts[16]);
//计算深蹲关键点
angle_l = that.angle(keypoimts[14],keypoimts[12],keypoimts[16]);
angle_r = that.angle(keypoimts[13],keypoimts[11],keypoimts[15]);
console.log('当前参数',angle_l,angle_r)
if(that.data.aiState == 1){
if(angle_boby >= 70){
correct++;
console.log('姿势识别成功',correct)
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
console.log('姿势识别失败',correct)
}
}
if(angle_r >= 140){
if(dirr == 1){
count = count + 0.5;
dirr = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//通过角度判断个数
if(that.data.aiState == 3){
if(angle_l >= 140){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
//站直
if(angle_r <= 80){
if(dirr == 0){
count = count + 0.5;
dirr = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//站直
if(angle_l <= 80){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
if(angle_r >= 140){
if(dirr == 1){
count = count + 0.5;
dirr = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
//站直
if(angle_r <= 80){
if(dirr == 0){
count = count + 0.5;
dirr = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
}
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 16, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
var postData = {
projectId: 16, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url:'../../../packageA/hipKicked/share/share?share=0' + '&id=' + uid + '&showMedal=1&sportTime='+that.formatSeconds(that.data.sportTime),
// })
}else{
that.setData({
aiState:4
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
return angleA;
},
}
})
......@@ -3,7 +3,7 @@
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 09:53:47
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 17:21:47
* @LastEditTime: 2022-06-08 11:05:18
*/
var API = require("../../../utils/request");
......@@ -13,142 +13,144 @@ var correct = 0;//识别成功次数
var dir = 0;// 0躺下 1坐起
module.exports = {
module.exports = Behavior({
onLoad:function(option){
},
data: {
showImageUrl:'https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/bg-sit.png'
},
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
methods:{
actionSend(object,app){ // 识别点
var that = this;
//console.log('app.globalData.movenet',app.globalData.movenet)
app.globalData.movenet.estimatePoses(object).then(function (res) {
var ctx = that.ctx,
keypoimts = res[0].keypoints
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height)
//console.log('关键点',keypoimts);
//判断当前点位信任度,信任度低过多的舍弃,
var num = 0;
for(var i = 0; i < keypoimts.length; i++){
if(keypoimts[i].score < 0.3){
num++
}
if(num > 7){
//console.log('不合格')
return false;
}
}
if(num > 7){
//console.log('不合格')
return false;
}
}
that.angle(keypoimts[11],keypoimts[5],keypoimts[13])
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0){
that.setData({
aiState:4
})
return false;
}
var postData = {
projectId: 2, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(this.data.loading);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1',
// })
}else{
that.angle(keypoimts[11],keypoimts[5],keypoimts[13])
}).catch(function (err) {
console.log(err)
});
},
//上传成绩
save(){
var that = this;
if(that.data.aiCount == 0 || that.data.aiCount > 100){
that.setData({
aiState:4
})
return false;
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = 0;
if(that.data.aiState > 0){
angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
}
//console.log('当前的状态',that.data.type,angleA)
if(that.data.aiState == 1){
if(angleA >= 120 && angleA <= 150){
correct ++;
console.log('姿势识别成功',correct);
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
var postData = {
projectId: 2, //项目id
sportValue: that.data.aiCount,//运动值
sourceType: 21, //1 活动,2课程
sportTime: that.data.sportTime,//运动时长 单位为s
isDev:0,
videoUrl:that.data.uuid
}
console.log('当前的参数',postData)
API.requestAll('/project/addReord', postData, (res) => {
clearTimeout(that.data.waitTimer);
var uid = res.data.id;
if(res.code == 200){
// wx.redirectTo({
// url: '../../../packageA/sitUp/share/share?share=0' + '&id=' + uid + '&showMedal=1&sportTime='+that.formatSeconds(that.data.sportTime),
// })
}else{
that.setData({
aiState:4
})
}
})
},
//计算角度
angle(one,two,three){
var that = this;
let A = {X:one.x,Y:one.y}
let B = {X:two.x,Y:two.y}
let C = {X:three.x,Y:three.y}
var AB = Math.sqrt(Math.pow(A.X - B.X, 2) + Math.pow(A.Y - B.Y, 2));
var AC = Math.sqrt(Math.pow(A.X - C.X, 2) + Math.pow(A.Y - C.Y, 2));
var BC = Math.sqrt(Math.pow(B.X - C.X, 2) + Math.pow(B.Y - C.Y, 2));
var cosA = (
Math.pow(AB, 2) + Math.pow(AC, 2) - Math.pow(BC, 2)
) / (
2 * AB * AC
);
var angleA = 0;
if(that.data.aiState > 0){
angleA = Math.round( Math.acos(cosA) * 180 / Math.PI );
}
}
//通过角度判断个数
if(that.data.aiState == 3){
if(angleA <= 55){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//console.log('当前的状态',that.data.type,angleA)
if(that.data.aiState == 1){
if(angleA >= 120 && angleA <= 150){
correct ++;
console.log('姿势识别成功',correct);
if(correct >= 5){
that.setData({
aiState:2
},()=>{
that.start();
})
}
}else{
correct = 0;
}
}
if(angleA >= 120){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
//通过角度判断个数
if(that.data.aiState == 3){
if(angleA <= 55){
if(dir == 0){
count = count + 0.5;
dir = 1;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
if(angleA >= 120){
if(dir == 1){
count = count + 0.5;
dir = 0;
that.setData({
levelfontsize: 'font-size:40px;color:#FFFF00;line-height:44px;',
aiCount:Math.floor(count)
},()=>{
setTimeout(()=>{
that.setData({
levelfontsize: 'font-size:34px;color:#FFFFFF;line-height:48px;',
})
},200)
})
}
}
}
}
},
}
},
}
})
var app = getApp()
var poseDetection = require('@tensorflow-models/pose-detection');
//引入混合模式
var flagTimer = null;
var time = 0;
var iosNum = 0;//ios不能重复播放同一地址音频,后加一位数,加时间戳不行
const aiSportType = app._aiSportType || '1'
var ts = require('../ai-mixins/ai-gtjz-mixins.js') //跳绳
var ts = require('../ai-mixins/ai-ts-mixins.js') //跳绳
var ywqz = require('../ai-mixins/ai-ywqz-mixins.js') //仰卧起坐
var tjz = require('../ai-mixins/ai-tjz-mixins.js') //踢毽子
var kht = require('../ai-mixins/ai-kht-mixins.js') //开合跳
......@@ -28,8 +30,12 @@ const sportObj = {
16:ydtt, //原地踢腿
17:ydp, //原地跑
}
console.log('aiSportType',aiSportType)
Page({
mixins: [sportObj[aiSportType]],
// mixins: [sportObj[aiSportType]],
behaviors: [sportObj[aiSportType]],
name:'ai-sport',
data: {
fps:20,//控制频率
......@@ -58,6 +64,7 @@ Page({
levelfontsize:'',
sportTime:60, //运动时长
skipType:1, //当前跳绳模式 0两者都行 1 双脚 2 单双脚交替
},
onLoad: function (options) {
......@@ -68,7 +75,7 @@ Page({
//运动时长(秒)
if(options.sportTime){
// 30/60/120/180
this.setData({sportTime:options.sportTime})
this.setData({sportTime:options.sportTime,skipType:options.type})
}
// 音频/语音交互相关
......
......@@ -2,7 +2,7 @@
<canvas type="2d" id="myCanvas" class="canvas"></canvas>
</camera>
<view wx:if="{{aiState == 1 || aiState == 6}}">
<image class="help-img" src="https://cdn.xiaobentiyu.cn/sport_minapp_img/sitUp/jumping-jacks.png"></image>
<image class="help-img" wx:if="{{showImageUrl}}" src="{{showImageUrl}}"></image>
<view class="help">
<view class="title">互动小提示</view>
<view class="content">手机竖屏固定放置,调整屏幕角度,训练者全身及双脚出现至屏幕内,识别更精准。</view>
......
......@@ -109,7 +109,7 @@ Page({
start(e){
//运动时常
let time = this.data.timeList[this.data.popupActive].value
if(this.data.sportDetail.id == 2){ //仰卧起坐
wx.navigateTo({
url:'../../../subPages/sport/ai-ywqz-sport/ai-ywqz-sport?sportTime=' + time,
......
/*
* @Author: tangjiale
* @eMail: 932055106@qq.com
* @Date: 2022-05-11 17:06:34
* @LastEditors: tangjiale
* @LastEditTime: 2022-06-07 15:16:02
*/
//代码转自:https://blog.csdn.net/yezi__6/article/details/118362069
//微信小程序中优先级为 Page > Mixins,所以需要劫持并改写 Page 函数,最后再重新把它释放出来
function mixinPage () {
// 保存原生的 Page 函数
const originPage = Page
Page = (options) => {
const mixins = options.mixins
// mixins 必须为数组
if (Array.isArray(mixins)) {
delete options.mixins
// mixins 注入并执行相应逻辑
options = mergePage(mixins, options)
}
originPage(options)
}
}
const ORIGIN_PROPERTIES_PAGE = [
'data'
]
const ORIGIN_METHODS = [
'onLoad',
'onReady',
'onShow',
'onHide',
'onUnload',
'onPullDownRefresh',
'onReachBottom',
'onShareAppMessage',
'onPageScroll',
'onResize',
'onTabItemTap'
]
function mergePage (mixins, options) {
mixins.forEach((mixin) => {
if (typeof mixin == 'object') {
// 遍历 mixin 里面的所有属性
for (let key in mixin) {
// for (let [key, value] of Object.entries(mixin)) {
if (ORIGIN_PROPERTIES_PAGE.includes(key)) {
// 内置对象属性混入
options[key] = { ...mixin[key], ...options[key] }
} else if (ORIGIN_METHODS.includes(key)) {
// 内置方法属性混入,优先执行混入的部分
const originFunc = options[key]
options[key] = function (...args) {
mixin[key].call(this, ...args)
return originFunc && originFunc.call(this, ...args)
}
} else {
// 自定义方法混入
options = { ...mixin, ...options }
}
}
}
})
return options
}
mixinPage()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment