This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 3
Sep 2018

Dear all,

I am trying to detect hand's palm positions and draw the palm positions on the image by circles using OpenCV.
Now I get hand's palm positions in 3D space as below:

// Get hand position
Leap::Frame frame = controller.frame();
Leap::HandList hands = frame.hands();
std::vector Positions;
int hands_size = hands.count();
for(int i=0; i<hands_size; i++){
Leap::Hand hand = hands[i];
Leap::Vector position = hand.palmPosition();
Positions.push_back(position);
}
However, to draw the palm position on image, i have to convert 3D coordinate to 2D coordinate. So do you know how to draw the palm position by red circles on image as the photo below?

Thank you so much for your help!
Best,

  • created

    Sep '18
  • last reply

    Oct '18
  • 2

    replies

  • 1.2k

    views

  • 1

    user

  • 3

    links

Hi all,

I drawn the palm position by the circle on image as the photo below.

To convert 3D coordinate to 2D coordinate, you can use as below:
float hSlope = -(tip.getX() + cameraOffset * (2 * image.id() - 1))/tip.getY();
float vSlope = tip.getZ()/tip.getY();

The following example draws circles over the finger tips in the image.

float cameraOffset = 20; //Physical x-axis offset of cameras in millimeters
Frame frame = controller.frame();
if(frame.isValid()){
ImageList images = frame.images();
for(Image image : images)
{
FingerList fingers = frame.fingers();
for(Finger finger : fingers){
Vector tip = finger.tipPosition();
// Calculate the slope of the tip position
float hSlope = -(tip.getX() + cameraOffset * (2 * image.id() - 1))/tip.getY();
float vSlope = tip.getZ()/tip.getY();
// Get the pixel location using the tip slope
Vector pixelLocation = image.warp(new Vector(hSlope, vSlope, 0f));
//Draw ellipse at the specified pixel over the raw image (uses Processing API)
fill(color(127, 0, 255));
int originX = 640 * image.id();
ellipse(pixelLocation.getX() + originX, pixelLocation.getY(), 10, 10);
}
}
}
More details in here:
https://developer-archive.leapmotion.com/documentation/java/devguide/Leap_Images.html7

Best Regards,