Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // label hands
- _hlf->setInput(&ibSegmentedImage);
- _hlf->setOutput(&ibFingerImage);
- _hlf->process(1000,100000);
- // identify fingers
- if(_hlf->boxes().size() > 0)
- {
- // get palm location using distance transform
- _dtf->setInput(&ibFingerImage);
- _dtf->setBoxes(&_hlf->boxes());
- _dtf->setOutput(&ibFingerImage);
- _dtf->process();
- // trace through fingers and find curvature
- _fid->setInput(&ibFingerImage);
- _fid->setBoxes(&_hlf->boxes());
- _fid->setOutput(&ibFingerImage);
- _fid->process();
- // clean up first
- [_detectedFingertips removeAllObjects];
- for(int i=0; i<_hlf->boxes().size(); ++i)
- {
- const std::vector<FingerPoint *> & fingerPoints = _hlf->boxes()[i]->fingerPoints();
- for(int j=0; j<fingerPoints.size(); ++j)
- {
- FingerPoint * p = fingerPoints[j];
- // determine location
- NSPoint nsCamPoint = NSMakePoint(p->normalizedCamPoint().x, 1-p->normalizedCamPoint().y);
- NSPoint nsScreenPoint = [_cameraToScreenMapper applyTo: nsCamPoint];
- //NSLog(@"found finger at (%f,%f)", p->normalizedCamPoint().x, p->normalizedCamPoint().y);
- // determine fingertip id
- int finger_id = p->fingerNumber();
- // TODO: uncomment lines below once the hand detection works reliably.
- // switch(p->parentBox()->handType())
- // {
- // case LEFT_HAND: finger_id *= -1; break;
- // case RIGHT_HAND: finger_id *= +1; break;
- // case UNDEFINED_HAND: finger_id = 0; break;
- // }
- MtFingertip * fingertip = [[[MtFingertip alloc]
- initFromCamPosition: nsCamPoint
- AndScreenPosition: nsScreenPoint
- AndFingerId: finger_id]
- autorelease];
- [_detectedFingertips addObject: fingertip];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement