Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What did I do wrong, if "Test Handtracking.html:98 Uncaught (in promise) ReferenceError: drawKeyPoints is not defined
at Test Handtracking.html:98:13
at Array.forEach (<anonymous>)
at detectHands (Test Handtracking.html:97:20)" appears?

What I have tried:

I am SUPER new to programming so I have no idea what to do

JavaScript
  1  function drawPoint(y, x, r) {
  2      ctx.beginPath();
  3      ctx.arc(x, y, r, 0, 2 * Math.PI);
  4      ctx.fill();
  5  }
  6  
  7  function drawKeypoints(keypoints) {
  8      const keypointsArray = keypoints;
  9      for (let i = 0; i < keypointsArray.length; i++) {
 10          const y = keypointsArray[i][0];
 11          const x = keypointsArray[i][1];
 12          drawPoint(x - 2, y - 2, 3);
 13      }
 14      
 15      const fingers = Object.keys(fingerLookupIndices);
 16      for (let i = 0; i < fingers.length; i++) {
 17          const finger = fingers[i];
 18          const points = fingerLookupIndices[finger].map(idx => keypoints[idx]);
 19          drawPath(points, false);
 20      }
 21  }
 22  
 23  function drawPath(points, closePath) {
 24      const region = new Path2D();
 25      region.moveTo(points[0][0], points[0][1]);
 26      for (let i = 1; i < points.length; i++) {
 27          const point = points[i];
 28          region.lineTo(point[0], point[1]);
 29      }
Posted
Updated 18-Nov-22 0:22am
v2

1 solution

We can't see any part of your code, so we can only guess.

Based on the error message, you are trying to call a function called drawKeyPoints, but that function either doesn't exist, or is not available in the scope where you're trying to call it.

Scope - MDN Web Docs Glossary&colon; Definitions of Web-related terms | MDN[^]

If you want more specific advice, you'll need to edit your question to show the relevant parts of your code.
 
Share this answer
 
Comments
Member 15835623 18-Nov-22 6:05am    
@Richard Deeming

function drawPoint(y, x, r) {
ctx.beginPath();
ctx.arc(x, y, r, 0, 2 * Math.PI);
ctx.fill();
}
function drawKeypoints(keypoints) {
const keypointsArray = keypoints;


for (let i = 0; i < keypointsArray.length; i++) {
const y = keypointsArray[i][0];
const x = keypointsArray[i][1];
drawPoint(x - 2, y - 2, 3);
}
const fingers = Object.keys(fingerLookupIndices);
for (let i = 0; i < fingers.length; i++) {
const finger = fingers[i];
const points = fingerLookupIndices[finger].map(idx => keypoints[idx]);
drawPath(points, false);
}
}

function drawPath(points, closePath) {
const region = new Path2D();
region.moveTo(points[0][0], points[0][1]);
for (let i = 1; i < points.length; i++) {
const point = points[i];
region.lineTo(point[0], point[1]);
}
Richard Deeming 18-Nov-22 6:23am    
That code is incomplete. Rather than trying to post your code in the comments, edit your question and post it there. I have added this code to your question.
Richard Deeming 18-Nov-22 6:24am    
NB: You have a function called drawKeypoints, and the error says you're trying to call drawKeyPoints. Javascript is case-sensitive, so those are two completely different functions.
Member 15835623 18-Nov-22 6:59am    
Oh okay. Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900