diff --git a/client/components/LandingPage.js b/client/components/LandingPage.js index 0559318..a886660 100644 --- a/client/components/LandingPage.js +++ b/client/components/LandingPage.js @@ -2,10 +2,12 @@ import React from 'react' import { Link } from 'react-router-dom' import Brand from './Brand' +import Navbar from './Navbar' const LandingPage = () => { return (
+
@@ -20,6 +22,7 @@ const LandingPage = () => { Get started +
) diff --git a/client/components/Main.js b/client/components/Main.js index 024c3ed..95eccb3 100644 --- a/client/components/Main.js +++ b/client/components/Main.js @@ -1,107 +1,36 @@ import React, { useRef, useState, useEffect } from 'react' import { connect } from 'react-redux' -import * as tf from '@tensorflow/tfjs' -import * as tmImage from '@teachablemachine/image' -import * as handPoseDetection from '@tensorflow-models/hand-pose-detection' import Webcam from 'react-webcam' import { drawHand } from '../utilities/hand' -import { drawFace } from '../utilities/face' -import { drawPose } from '../utilities/pose' -import { drawBothHands } from '../utilities/bothHands' import * as handpose from '@tensorflow-models/handpose' -import * as poseDetection from '@tensorflow-models/pose-detection' import '@tensorflow/tfjs-backend-webgl' import * as fp from 'fingerpose' -import * as blazeface from '@tensorflow-models/blazeface' -import { paperGesture } from './phrases/hello-thankyou' -import { loveYouGesture } from './phrases/iloveyou' -import { pleaseGesture } from './phrases/please' -import { youGesture } from './phrases/you' -import { niceGesture } from './phrases/nice' -/** - * COMPONENT - */ -//url = https://teachablemachine.withgoogle.com/models/86Rqg3NFc/ -const decideGesture = (gestureName, hand, face, pose) => { - const tipOfIndex = hand[0].landmarks[8] - const tipOfPinky = hand[0].landmarks[20] - const rightEye = face[0].landmarks[0] - const mouth = face[0].landmarks[3] - const shoulder = pose[0].keypoints[5] - if (gestureName === 'hello-thankyou') { - if ( - Math.abs(tipOfIndex[0] - mouth[0]) <= 50 && - tipOfIndex[1] > mouth[1] && - tipOfPinky[1] < shoulder.y - ) { - return 'thank you' - } else if (tipOfIndex[1] < rightEye[1]) { - return 'hello' - } else if (tipOfPinky[1] >= shoulder.y) { - return 'please' - } - } else return gestureName -} +import { aSign } from './letters/letterA' +import { bSign } from './letters/letterB' +import { cSign } from './letters/letterC' +import { dSign } from './letters/letterD' +import { eSign } from './letters/letterE' +import { fSign } from './letters/letterF' +import { gSign } from './letters/letterG' +import { hSign } from './letters/letterH' +import { iSign } from './letters/letterI' + export const Home = props => { const webcamRef = useRef(null) const canvasRef = useRef(null) const [translation, setTranslation] = useState(null) + const [word, setWord] = useState(null) - const URL = 'https://teachablemachine.withgoogle.com/models/86Rqg3NFc/' - const checkpointURL = URL + 'model.json' - const metadataURL = URL + 'metadata.json' - - const loadModel = async () => { - const model = await tmImage.load(checkpointURL, metadataURL) + const runHandpose = async () => { const net = await handpose.load() - - const netFace = await blazeface.load() - //pose - const detectorConfig = { - architecture: 'MobileNetV1', - outputStride: 16, - inputResolution: { width: 640, height: 480 }, - multiplier: 0.75 - } - const netPose = await poseDetection.createDetector( - poseDetection.SupportedModels.PoseNet, - detectorConfig - ) - - //both hands detection - const modelBothHands = handPoseDetection.SupportedModels.MediaPipeHands - const detectorConfigBothHands = { - runtime: 'tfjs', - modelType: 'full' - } - const netBothHands = await handPoseDetection.createDetector( - modelBothHands, - detectorConfigBothHands - ) - console.log('net both hands', netBothHands) - console.log('pose detector ', netPose) - - console.log('net', net.pipeline.maxHandsNumber) + console.log('Handpose model loaded.') + // Loop and detect hands setInterval(() => { - detect(model, net, netFace, netPose, netBothHands) - //this function is being called so quickly, you want to make it as optimized - //as possible - //"the fact you're using a setInterval could be a problem" - //it's asynchronous, so it's possible that two detects can happen at the same time. - //detect function sets a state on the component that says detection is happening. - //when detect function is completed you change that state back to false - //so you can create a gaurd that prevents another detect function - //request animation frame - //if resources are available, and I can perform this function. - //Window.requestAnimationFrame(detect()) - //then within detect, call this again. sort of recursive for detect - //this means that the detect funtions are less likely to overlap with each other - }, 100) + detect(net) + }, 1000) } - - //Loop and detect hands - - async function detect(model, net, netFace, netPose, netBothHands) { + const array = [] + async function detect(net) { // predict can take in an image, video or canvas html element if ( @@ -109,12 +38,6 @@ export const Home = props => { webcamRef.current !== null && webcamRef.current.video.readyState === 4 ) { - //we don't need to use this every time we call detect. maybe we should move this outside - //of the detect function context. - //go through this code and ensure that everything is actually something we have to redo - //in order to detect. if not, we can find a way to do it once in load model, keep - //a reference using useRef, and use reference to it. - // Get Video Properties const video = webcamRef.current.video const videoWidth = webcamRef.current.video.videoWidth const videoHeight = webcamRef.current.video.videoHeight @@ -127,68 +50,22 @@ export const Home = props => { canvasRef.current.width = videoWidth canvasRef.current.height = videoHeight //make detections for hand - const estimationConfig = { flipHorizontal: false } - const bothHands = await netBothHands.estimateHands(video, estimationConfig) const hand = await net.estimateHands(video) - //make detections for face - const returnTensors = false - const face = await netFace.estimateFaces(video, returnTensors) - const pose = await netPose.estimatePoses(video) - - console.log('face is', face) - // const face = await - console.log('hand', hand) - console.log('both hands are', bothHands) - console.log('pose is', pose) - - //this grabbing of the 2d context, this shouldn't need to be done more than once. - //you should be able to grab context and have reference to it, and use it in - //every detect call. we're doing this often enough to make it matter. - //want to dig through detect code and sus out whether everything we're doing - //in detect code absolutely needed - //draw mesh - const ctx = canvasRef.current.getContext('2d') - - //drawHand(hand, ctx); - drawBothHands(bothHands, ctx) - drawFace(face, ctx) - drawPose(pose, ctx) - // if (bothHands.length === 2) { - // console.log("get inside both hands???"); - // const gestureEstimatorForBothHand = new fp.GestureEstimator([ - // niceGesture, - // ]); - // const gestureLeftHand = await gestureEstimatorForBothHand.estimate( - // bothHands[0].keypoints, - // 8 - // ); - // console.log("gesture left hand is", gestureLeftHand); - // const gestureRightHand = await gestureEstimatorForBothHand.estimate( - // bothHands[1].keypoints, - // 8 - // ); - // console.log("gesture right hand is", gestureRightHand); - // if (gestureLeftHand.gestures && gestureRightHand.gestures) { - // if ( - // gestureLeftHand.gestures[0].name === "nice" && - // gestureRightHand.gestures[0].name === "nice" - // ) { - // setTranslation("nice"); - // } - // } - // //make detections for hands and finger gestures - // } - if (bothHands.length === 1 && hand.length > 0 && face.length > 0) { + if (hand.length > 0) { const gestureEstimator = new fp.GestureEstimator([ - paperGesture, - loveYouGesture, - pleaseGesture, - youGesture + aSign, + bSign, + cSign, + dSign, + eSign, + fSign, + gSign, + hSign, + iSign ]) - // 8 is the confidence level - const gesture = await gestureEstimator.estimate(hand[0].landmarks, 8) + const gesture = await gestureEstimator.estimate(hand[0].landmarks, 4) console.log('gesture is ', gesture) if (gesture.gestures && gesture.gestures.length > 0) { const score = gesture.gestures.map(prediction => prediction.score) @@ -197,39 +74,29 @@ export const Home = props => { const gestureName = gesture.gestures[maxScore].name console.log('gestures name is -', gesture.gestures[maxScore].name) - const result = decideGesture(gestureName, hand, face, pose) - console.log('result is ---', result) - setTranslation(result) - } - } else if (bothHands.length === 2) { - let prediction = await model.predict(video) - console.log('PREDICTION-----', prediction) - if (prediction && prediction.length > 0) { - const probability = prediction.map( - prediction => prediction.probability - ) - console.log(probability) - const maxPro = probability.indexOf(Math.max.apply(null, probability)) - - //// Kaia just added the line below (hand.length > 0) - if (prediction[maxPro].probability > 0.8 && bothHands.length > 0) { - setTranslation(prediction[maxPro].className) - } else { - setTranslation(null) - } + array.push(gestureName) + console.log('array=====', array) + let result=array.join('') + console.log('result=====', result) + setTranslation(gestureName) + setWord(result) } - } else if (bothHands.length === 0) { - setTranslation(null) - return } + const ctx = canvasRef.current.getContext('2d') + drawHand(hand, ctx) } } useEffect(() => { - loadModel() + runHandpose() }, []) - + console.log('translation====', translation) + console.log('word=====', word) return (
+

Online translator

+

Letter:{translation}

+

Word:{word}

+ { height: 480 }} /> -
- {translation} -
) } -/** - * CONTAINER - */ + const mapState = state => { return { username: state.auth.username diff --git a/client/components/Navbar.js b/client/components/Navbar.js new file mode 100644 index 0000000..3b629a0 --- /dev/null +++ b/client/components/Navbar.js @@ -0,0 +1,35 @@ +import React from 'react' +import { Link } from 'react-router-dom' + +const Navbar = () => { + return ( + + ) +} + +export default Navbar diff --git a/client/components/letters/letterA.js b/client/components/letters/letterA.js index e69de29..eb4e69d 100644 --- a/client/components/letters/letterA.js +++ b/client/components/letters/letterA.js @@ -0,0 +1,26 @@ +import { Finger, FingerCurl, FingerDirection, GestureDescription } from 'fingerpose' + +export const aSign = new GestureDescription('A') + +//Thumb +aSign.addCurl(Finger.Thumb, FingerCurl.NoCurl, 1.0) +aSign.addDirection(Finger.Index, FingerDirection.DiagonalUpRight, 0.7) +// aSign.addDirection(Finger.Index, FingerDirection.DiagonalUpLeft, 0.70); + +//Index +aSign.addCurl(Finger.Index, FingerCurl.FullCurl, 1) +aSign.addDirection(Finger.Index, FingerDirection.VerticalUp, 0.7) +// aSign.addDirection(Finger.Index, FingerDirection.DiagonalUpLeft, 0.70); + +//Middle +aSign.addCurl(Finger.Middle, FingerCurl.FullCurl, 1) +aSign.addDirection(Finger.Middle, FingerDirection.VerticalUp, 0.7) +// aSign.addDirection(Finger.Middle, FingerDirection.DiagonalUpLeft, 0.70); + +//Ring +aSign.addCurl(Finger.Ring, FingerCurl.FullCurl, 1) +aSign.addDirection(Finger.Ring, FingerDirection.VerticalUp, 0.7) + +//Pinky +aSign.addCurl(Finger.Pinky, FingerCurl.FullCurl, 1) +aSign.addDirection(Finger.Pinky, FingerDirection.VerticalUp, 0.7) diff --git a/client/components/letters/letterB.js b/client/components/letters/letterB.js index e69de29..62398e6 100644 --- a/client/components/letters/letterB.js +++ b/client/components/letters/letterB.js @@ -0,0 +1,24 @@ +import { Finger, FingerCurl, FingerDirection, GestureDescription } from 'fingerpose' + +export const bSign = new GestureDescription('B') + +//Thumb +bSign.addCurl(Finger.Thumb, FingerCurl.HalfCurl, 1.0) +bSign.addDirection(Finger.Index, FingerDirection.DiagonalUpLeft, 0.7) +bSign.addDirection(Finger.Index, FingerDirection.DiagonalUpRight, 0.7) + +//Index +bSign.addCurl(Finger.Index, FingerCurl.NoCurl, 1) +bSign.addDirection(Finger.Index, FingerDirection.VerticalUp, 0.7) + +//Middle +bSign.addCurl(Finger.Middle, FingerCurl.NoCurl, 1) +bSign.addDirection(Finger.Middle, FingerDirection.VerticalUp, 0.7) + +//Ring +bSign.addCurl(Finger.Ring, FingerCurl.NoCurl, 1) +bSign.addDirection(Finger.Ring, FingerDirection.VerticalUp, 0.7) + +//Pinky +bSign.addCurl(Finger.Pinky, FingerCurl.NoCurl, 1) +bSign.addDirection(Finger.Pinky, FingerDirection.VerticalUp, 0.7) diff --git a/client/components/letters/letterC.js b/client/components/letters/letterC.js index e69de29..4aee811 100644 --- a/client/components/letters/letterC.js +++ b/client/components/letters/letterC.js @@ -0,0 +1,23 @@ +import {Finger, FingerCurl, FingerDirection, GestureDescription} from 'fingerpose'; + +export const cSign = new GestureDescription('C'); + +//Thumb +cSign.addCurl(Finger.Thumb, FingerCurl.NoCurl, 1.0); +cSign.addDirection(Finger.Index, FingerDirection.DiagonalUpRight, 0.70); + +//Index +cSign.addCurl(Finger.Index, FingerCurl.NoCurl, 1); +cSign.addDirection(Finger.Index, FingerDirection.DiagonalUpRight, 0.70); + +//Middle +cSign.addCurl(Finger.Middle, FingerCurl.HalfCurl, 1); +cSign.addDirection(Finger.Middle, FingerDirection.DiagonalUpRight, 0.70); + +//Ring +cSign.addCurl(Finger.Ring, FingerCurl.HalfCurl, 1); +cSign.addDirection(Finger.Ring, FingerDirection.DiagonalUpRight, 0.70); + +//Pinky +cSign.addCurl(Finger.Pinky, FingerCurl.HalfCurl, 1); +cSign.addDirection(Finger.Pinky, FingerDirection.DiagonalUpRight, 0.70); \ No newline at end of file diff --git a/client/components/letters/letterD.js b/client/components/letters/letterD.js index e69de29..7ee844c 100644 --- a/client/components/letters/letterD.js +++ b/client/components/letters/letterD.js @@ -0,0 +1,23 @@ +import { Finger, FingerCurl, FingerDirection, GestureDescription } from 'fingerpose' + +export const dSign = new GestureDescription('D') + +//Thumb +dSign.addCurl(Finger.Thumb, FingerCurl.HalfCurl, 1.0) +dSign.addDirection(Finger.Index, FingerDirection.VerticalUp, 0.7) + +//Index +dSign.addCurl(Finger.Index, FingerCurl.NoCurl, 1) +dSign.addDirection(Finger.Index, FingerDirection.VerticalUp, 0.7) + +//Middle +dSign.addCurl(Finger.Middle, FingerCurl.FullCurl, 1) +dSign.addDirection(Finger.Middle, FingerDirection.VerticalUp, 0.7) + +//Ring +dSign.addCurl(Finger.Ring, FingerCurl.FullCurl, 1) +dSign.addDirection(Finger.Ring, FingerDirection.VerticalUp, 0.7) + +//Pinky +dSign.addCurl(Finger.Pinky, FingerCurl.FullCurl, 1) +dSign.addDirection(Finger.Pinky, FingerDirection.VerticalUp, 0.7) diff --git a/client/components/letters/letterE.js b/client/components/letters/letterE.js index e69de29..cbe00b5 100644 --- a/client/components/letters/letterE.js +++ b/client/components/letters/letterE.js @@ -0,0 +1,23 @@ +import {Finger, FingerCurl, FingerDirection, GestureDescription} from 'fingerpose'; + +export const eSign = new GestureDescription('E'); + +//Thumb +eSign.addCurl(Finger.Thumb, FingerCurl.HalfCurl, 1.0); +eSign.addDirection(Finger.Index, FingerDirection.VerticalUp, 0.70); + +//Index +eSign.addCurl(Finger.Index, FingerCurl.FullCurl, 1); +eSign.addDirection(Finger.Index, FingerDirection.VerticalUp, 0.70); + +//Middle +eSign.addCurl(Finger.Middle, FingerCurl.FullCurl, 1); +eSign.addDirection(Finger.Middle, FingerDirection.VerticalUp, 0.70); + +//Ring +eSign.addCurl(Finger.Ring, FingerCurl.FullCurl, 1); +eSign.addDirection(Finger.Ring, FingerDirection.VerticalUp, 0.70); + +//Pinky +eSign.addCurl(Finger.Pinky, FingerCurl.FullCurl, 1); +eSign.addDirection(Finger.Pinky, FingerDirection.VerticalUp, 0.70); \ No newline at end of file diff --git a/client/components/letters/letterF.js b/client/components/letters/letterF.js index e69de29..3ad91e7 100644 --- a/client/components/letters/letterF.js +++ b/client/components/letters/letterF.js @@ -0,0 +1,23 @@ +import { Finger, FingerCurl, FingerDirection, GestureDescription } from 'fingerpose' + +export const fSign = new GestureDescription('F') + +//Thumb +fSign.addCurl(Finger.Thumb, FingerCurl.HalfCurl, 1.0) +fSign.addDirection(Finger.Index, FingerDirection.DiagonalUpRight, 0.7) + +//Index +fSign.addCurl(Finger.Index, FingerCurl.FullCurl, 1) +fSign.addDirection(Finger.Index, FingerDirection.DiagonalUpRight, 0.7) + +//Middle +fSign.addCurl(Finger.Middle, FingerCurl.NoCurl, 1) +fSign.addDirection(Finger.Middle, FingerDirection.VerticalUp, 0.7) + +//Ring +fSign.addCurl(Finger.Ring, FingerCurl.NoCurl, 1) +fSign.addDirection(Finger.Ring, FingerDirection.VerticalUp, 0.7) + +//Pinky +fSign.addCurl(Finger.Pinky, FingerCurl.NoCurl, 1) +fSign.addDirection(Finger.Pinky, FingerDirection.VerticalUp, 0.7) diff --git a/client/components/letters/letterG.js b/client/components/letters/letterG.js index e69de29..26da5dc 100644 --- a/client/components/letters/letterG.js +++ b/client/components/letters/letterG.js @@ -0,0 +1,23 @@ +import {Finger, FingerCurl, FingerDirection, GestureDescription} from 'fingerpose'; + +export const gSign = new GestureDescription('G'); + +//Thumb +gSign.addCurl(Finger.Thumb, FingerCurl.NoCurl, 1.0); +gSign.addDirection(Finger.Index, FingerDirection.DiagonalUpRight, 0.70); + +//Index +gSign.addCurl(Finger.Index, FingerCurl.NoCurl, 1); +gSign.addDirection(Finger.Index, FingerDirection.HorizontalRight, 0.70); + +//Middle +gSign.addCurl(Finger.Middle, FingerCurl.FullCurl, 1); +gSign.addDirection(Finger.Middle, FingerDirection.DiagonalUpRight, 0.70); + +//Ring +gSign.addCurl(Finger.Ring, FingerCurl.FullCurl, 1); +gSign.addDirection(Finger.Ring, FingerDirection.HorizontalRight, 0.70); + +//Pinky +gSign.addCurl(Finger.Pinky, FingerCurl.FullCurl, 1); +gSign.addDirection(Finger.Pinky, FingerDirection.HorizontalRight, 0.70); \ No newline at end of file diff --git a/client/components/letters/letterH.js b/client/components/letters/letterH.js index e69de29..8301756 100644 --- a/client/components/letters/letterH.js +++ b/client/components/letters/letterH.js @@ -0,0 +1,23 @@ +import {Finger, FingerCurl, FingerDirection, GestureDescription} from 'fingerpose'; + +export const hSign = new GestureDescription('H'); + +//Thumb +hSign.addCurl(Finger.Thumb, FingerCurl.NoCurl, 1.0); +hSign.addDirection(Finger.Index, FingerDirection.HorizontalRight, 0.70); + +//Index +hSign.addCurl(Finger.Index, FingerCurl.NoCurl, 1); +hSign.addDirection(Finger.Index, FingerDirection.HorizontalRight, 0.70); + +//Middle +hSign.addCurl(Finger.Middle, FingerCurl.NoCurl, 1); +hSign.addDirection(Finger.Middle, FingerDirection.HorizontalRight, 0.70); + +//Ring +hSign.addCurl(Finger.Ring, FingerCurl.FullCurl, 1); +hSign.addDirection(Finger.Ring, FingerDirection.HorizontalRight, 0.70); + +//Pinky +hSign.addCurl(Finger.Pinky, FingerCurl.FullCurl, 1); +hSign.addDirection(Finger.Pinky, FingerDirection.HorizontalRight, 0.70); \ No newline at end of file diff --git a/client/components/letters/letterI.js b/client/components/letters/letterI.js index e69de29..c2cd2f7 100644 --- a/client/components/letters/letterI.js +++ b/client/components/letters/letterI.js @@ -0,0 +1,23 @@ +import { Finger, FingerCurl, FingerDirection, GestureDescription } from 'fingerpose' + +export const iSign = new GestureDescription('I') + +//Thumb +iSign.addCurl(Finger.Thumb, FingerCurl.HalfCurl, 1.0) +iSign.addDirection(Finger.Index, FingerDirection.DiagonalUpLeft, 0.7) + +//Index +iSign.addCurl(Finger.Index, FingerCurl.FullCurl, 1) +iSign.addDirection(Finger.Index, FingerDirection.VerticalUp, 0.7) + +//Middle +iSign.addCurl(Finger.Middle, FingerCurl.FullCurl, 1) +iSign.addDirection(Finger.Middle, FingerDirection.VerticalUp, 0.7) + +//Ring +iSign.addCurl(Finger.Ring, FingerCurl.FullCurl, 1) +iSign.addDirection(Finger.Ring, FingerDirection.VerticalUp, 0.7) + +//Pinky +iSign.addCurl(Finger.Pinky, FingerCurl.NoCurl, 1) +iSign.addDirection(Finger.Pinky, FingerDirection.VerticalUp, 0.7) diff --git a/client/utilities/hand.js b/client/utilities/hand.js index 7cf428a..0668b3b 100644 --- a/client/utilities/hand.js +++ b/client/utilities/hand.js @@ -1,62 +1,85 @@ -//Pointers for fingers +// Points for fingers const fingerJoints = { - thumb: [0, 1, 2, 3, 4], - indexFinger: [0, 5, 6, 7, 8], - middleFinger: [0, 9, 10, 11, 12], - ringFinger: [0, 13, 14, 15, 16], - pinky: [0, 17, 18, 19, 20], -}; + thumb: [0, 1, 2, 3, 4], + indexFinger: [0, 5, 6, 7, 8], + middleFinger: [0, 9, 10, 11, 12], + ringFinger: [0, 13, 14, 15, 16], + pinky: [0, 17, 18, 19, 20] +} -//drawing function -export const drawHand = (prediction, ctx) => { - console.log("get in draw hand"); - if (prediction.length > 0) { - prediction.forEach((prediction) => { - //extract landmarks - const landmarks = prediction.landmarks; +// Infinity Gauntlet Style +const style = { + 0: { color: 'yellow', size: 15 }, + 1: { color: 'gold', size: 6 }, + 2: { color: 'green', size: 10 }, + 3: { color: 'gold', size: 6 }, + 4: { color: 'gold', size: 6 }, + 5: { color: 'purple', size: 10 }, + 6: { color: 'gold', size: 6 }, + 7: { color: 'gold', size: 6 }, + 8: { color: 'gold', size: 6 }, + 9: { color: 'blue', size: 10 }, + 10: { color: 'gold', size: 6 }, + 11: { color: 'gold', size: 6 }, + 12: { color: 'gold', size: 6 }, + 13: { color: 'red', size: 10 }, + 14: { color: 'gold', size: 6 }, + 15: { color: 'gold', size: 6 }, + 16: { color: 'gold', size: 6 }, + 17: { color: 'orange', size: 10 }, + 18: { color: 'gold', size: 6 }, + 19: { color: 'gold', size: 6 }, + 20: { color: 'gold', size: 6 } +} - //Loop through fingers - for (let j = 0; j < Object.keys(fingerJoints).length; j++) { - //loop through the pair of joints - const finger = Object.keys(fingerJoints)[j]; - for (let k = 0; k < fingerJoints[finger].length - 1; k++) { - //Get pair of joints - const firstJointIndex = fingerJoints[finger][k]; - const secondJoinIndex = fingerJoints[finger][k + 1]; +// Drawing function +export const drawHand = (predictions, ctx) => { + // Check if we have predictions + if (predictions.length > 0) { + // Loop through each prediction + predictions.forEach(prediction => { + // Grab landmarks + const landmarks = prediction.landmarks - // 203.90426040496055, 388.1905885750879; - //draw path - ctx.beginPath(); + // Loop through fingers + for (let j = 0; j < Object.keys(fingerJoints).length; j++) { + let finger = Object.keys(fingerJoints)[j] + // Loop through pairs of joints + for (let k = 0; k < fingerJoints[finger].length - 1; k++) { + // Get pairs of joints + const firstJointIndex = fingerJoints[finger][k] + const secondJointIndex = fingerJoints[finger][k + 1] - ctx.moveTo( - landmarks[firstJointIndex][0], - landmarks[firstJointIndex][1] - ); - ctx.lineTo( - landmarks[secondJoinIndex][0], - landmarks[secondJoinIndex][1] - ); - ctx.stroke(); - // ctx.strokeStyle = "plum"; - // ctx.lineWidth = 4; - } - } + // Draw path + ctx.beginPath() + ctx.moveTo( + landmarks[firstJointIndex][0], + landmarks[firstJointIndex][1] + ) + ctx.lineTo( + landmarks[secondJointIndex][0], + landmarks[secondJointIndex][1] + ) + ctx.strokeStyle = 'plum' + ctx.lineWidth = 4 + ctx.stroke() + } + } - //loop through landmarks and draw them (each landmark has [x, y, z]) - for (let i = 0; i < landmarks.length; i++) { - //get x - const x = landmarks[i][0]; - //get y - const y = landmarks[i][1]; - //start drawing - //ctx.arc(x, y, radius, startAngle, endAngle [, counterclockwise]); - ctx.beginPath(); - ctx.arc(x, y, 5, 0, 3 * Math.PI); + // Loop through landmarks and draw em + for (let i = 0; i < landmarks.length; i++) { + // Get x point + const x = landmarks[i][0] + // Get y point + const y = landmarks[i][1] + // Start drawing + ctx.beginPath() + ctx.arc(x, y, style[i]['size'], 0, 3 * Math.PI) - //set line colow - ctx.fillStyle = "indigo"; - ctx.fill(); - } - }); - } -}; + // Set line color + ctx.fillStyle = style[i]['color'] + ctx.fill() + } + }) + } +} diff --git a/css/index.css b/css/index.css index 2ffa8e8..423afbc 100644 --- a/css/index.css +++ b/css/index.css @@ -2,6 +2,8 @@ @import url('unset.css'); @import url('landingPage.css'); @import url('auth.css'); +@import url('navbar.css'); +@import url('main.css'); /* Global variables. */ :root { @@ -15,3 +17,4 @@ --clr-three: #edf6ff; --clr-four: #ffa500; } + diff --git a/css/main.css b/css/main.css new file mode 100644 index 0000000..b28b04f --- /dev/null +++ b/css/main.css @@ -0,0 +1,3 @@ + + + diff --git a/css/navbar.css b/css/navbar.css new file mode 100644 index 0000000..21e7817 --- /dev/null +++ b/css/navbar.css @@ -0,0 +1,90 @@ +.nav { + height: 50px; + width: 100%; + background-color: #e0975c; + position: relative; + margin-top: -380px; +} + +.nav > .nav-header { + display: inline; +} + +.nav > .nav-header > .nav-title { + display: inline-block; + font-size: 22px; + color: #fff; + padding: 10px 10px 10px 10px; +} + +.nav > .nav-btn { + display: none; +} + +.nav > .nav-links { + display: inline; + float: right; + font-size: 18px; +} + +.nav > .nav-links > a { + display: inline-block; + padding: 13px 10px 13px 10px; + text-decoration: none; + color: #efefef; +} + +.nav > .nav-links > a:hover { + background-color: rgba(0, 0, 0, 0.3); +} + +.nav > #nav-check { + display: none; +} + +@media (max-width: 600px) { + .nav > .nav-btn { + display: inline-block; + position: absolute; + right: 0px; + top: 0px; + } + .nav > .nav-btn > label { + display: inline-block; + width: 50px; + height: 50px; + padding: 13px; + } + .nav > .nav-btn > label:hover, + .nav #nav-check:checked ~ .nav-btn > label { + background-color: rgba(0, 0, 0, 0.3); + } + .nav > .nav-btn > label > span { + display: block; + width: 25px; + height: 10px; + border-top: 2px solid #eee; + } + .nav > .nav-links { + position: absolute; + display: block; + width: 100%; + background-color: #333; + height: 0px; + transition: all 0.3s ease-in; + overflow-y: hidden; + top: 50px; + left: 0px; + } + .nav > .nav-links > a { + display: block; + width: 100%; + } + .nav > #nav-check:not(:checked) ~ .nav-links { + height: 0px; + } + .nav > #nav-check:checked ~ .nav-links { + height: calc(100vh - 50px); + overflow-y: auto; + } +} diff --git a/package.json b/package.json index bc0f779..2f6f016 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "author": "Fullstack Academy of Code", "license": "MIT", "dependencies": { + "@mediapipe/pose": "^0.5.1635988162", "@teachablemachine/image": "^0.8.5", "@tensorflow-models/blazeface": "^0.0.7", "@tensorflow-models/hand-pose-detection": "^2.0.0",