Anda di halaman 1dari 5

08/09/2016

ConnectingtheLeapMotioncontrollertoMathematicaUsingJLinkOnlineTechnicalDiscussionGroupsWolframCommunity

ConnectingtheLeapMotioncontrollertoMathematicaUsingJLink
GROUPS:

SotheLeapMotioncontrollerhasjustbeenreleasedandIthoughtImightaswellpostsomecodethatToddGayleyandIwroteto
connecttheLeapMotionandallofitsfunctionalitytoMathematica!

10

Herearethesetupinstructions:

Votes

1.(Ifyouhaven'talready)downloadandinstalltheleapmotion
softwarefromleapmotion.com/setup
2.DownloadtheleapmotionSDKofftheirdeveloperpage.
3.ConnecttheLeapMotiontoyourcomputer.
4.Findthefile"LeapJava.jar"insideoftheLeapSDK(Itshouldbeunderlib.)
5.OpenMathematicaandpastethisin:
Needs["JLink`"]
ReinstallJava[CommandLine>"java",
JVMArguments>
"Djava.library.path=[pathtodirectoryCONTAININGLeapJava.jar]"]

Nowputthepathto"LeapJava.jar"intheindicatedposition,andrememberthisisthepathtothedirectorycontainingLeapJava.jar,not
thepathtoLeapJava.jaritselfandrunthecode.
6.Nowpastethisin:
AddToClassPath["[pathtoLeapJava.jar]"]

ReplacetheindicatedareawiththepathtoLeapJava.jaritselfandrunit.
7.Tosetupthecontroller,runthis:
controller=JavaNew["com.leapmotion.leap.Controller"]

Youshouldnowbefullyconnectedandreadytogo!Toseeifitisworkingyoucanrun:
Methods[controller]

anditshouldreturnalistofallthemethodsunderthecontroller.
Themainmethodyouwanttolookatisframe[]whichcontainsalloftheinformationaboutwhatisgoingon.
Toseethemethodsunderframe[]runthis:
Methods[controller@frame[]]

Fromhereyoushouldbeabletofigurethingsoutlikethis:
controller@frame[]@fingers@count[]

http://community.wolfram.com/groups//m/t/90931

1/5

08/09/2016

ConnectingtheLeapMotioncontrollertoMathematicaUsingJLinkOnlineTechnicalDiscussionGroupsWolframCommunity
whichshouldcountthevisiblefingersinthescene.
AlsoinafinalnoteIwantmentionthatIwashavingproblemsaccessingthefingerswiththis:
controller@frame[]@finger[fingernumber]

andsoyoumaywanttotry:
controller@frame[]@fingers[]@get[fingernumber]

instead.Thesamegoesforpalms.
Well,ifyouwriteanythingcoolusingthispleasepostitbackupherealongwithanyquestionsyouhave.
(IamgoingtotrytopostsomeofthecodeIhavewrittenwiththissoon

POSTEDBY:ChristopherWolfram 3yearsago

8Replies

Flat

Votes

Nested

TryingthisoutonOSX,Mm9.0.1.0,Igetthefollowingerrorwhensettingupthecontroller:
Java::excptn:AJavaexceptionoccurred:java.lang.ExceptionInInitializerError
atcom.leapmotion.leap.Controller.(Controller.java:39)
atsun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)
atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
atjava.lang.reflect.Constructor.newInstance(Constructor.java:513)
Causedby:java.lang.SecurityException:
J/LinkdoesnotallowcodecalledfromMathematicatocallSystem.exit().
atjava.lang.Runtime.exit(Runtime.java:88)
atjava.lang.System.exit(System.java:921)
atcom.leapmotion.leap.LeapJNI.(LeapJNI.java:18)
...11more.
JavaNew::fail:"Errorcallingconstructorforclass\!\(\"com.leapmotion.leap.Controller\"\)."
Ipresumethisisapermissionsissue,butIhaven'tbeenabletofigureoutwhatfileorfilespermissionsneedtobechangedandtowhat.
I'mrunningMathematicafromanaccountwithAdminprivleges.
Anysuggestions?
Thanks,
Mike

POSTEDBY:MichaelBurns 3yearsago

Areyousurethatthefilepathineitheroftheearlierlineswereright?Andthatyoudidn'tmoveanyfilesaroundinsidetheleapSDK
includingfilesotherthanLeapJava.jar?AlsoyoumightwanttocheckthatyouinstalledtheprogramfromtheLeapMotionsetuppage
and(Iamnotsurethisisreallynecessary)haveitrunning.

POSTEDBY:ChristopherWolfram 3yearsago

http://community.wolfram.com/groups//m/t/90931

2/5

08/09/2016

ConnectingtheLeapMotioncontrollertoMathematicaUsingJLinkOnlineTechnicalDiscussionGroupsWolframCommunity

Idoublecheckedthefilepathsfirstreferenceistodirectoryandsecondistothe.jarfileitself.I'mprettysureIdidn'tmoveanyofthe
filesaroundinsidetheSDKfolderwhichisoneleveldeeponmydesktop.I'mrunningtheLeapappanditconnectsautomaticallywith
otherLeapprograms.IcansuccessfullycompileandruntheLeapjavaSampleappfromtheterminal,soallseemswellthereandworking
nominally.
Thanksforthesuggestions.I'llkeeppokingaroundandseeifIcanfigureoutwhatmyproblemis.

POSTEDBY:MichaelBurns 3yearsago

Edit:Foundthesolution!
OnWindows(x64),LeapJava.dllfromLeapDeveloperKit\LeapSDK\lib\x64needstobeinthesamedirectoryasyourLeapJava.jar.This
shouldletyourunJavaNewaccordingtotheinstructionsintheoriginalpost.

1
Vote

Disregardbelow
LoadingtheJavaclassinsteadofJavaNewworkedforme:
controller=LoadJavaClass["com.leapmotion.leap.Controller"]

Insteadof:
controller=JavaNew["com.leapmotion.leap.Controller"]

Butthisonlyletsyouviewthemethods,anddoesnotcreateanobjectoftheclass.

POSTEDBY:FrankZhao 3yearsago

FormethisworksfineonWindows(x64),nocopyingaroundofdll's:

1
Vote

Needs["JLink`"]
With[{
(*thelocationofthedeveloperkit:*)
lmlib="C:\\leapmotion\\LeapDeveloperKit_release_win_1.0.8+7665\\LeapDeveloperKit\\LeapSDK\\lib"
},
(*for64bitWindows:*)
AddToClassPath[lmlib,FileNameJoin[{lmlib,"x64"}]]
]
(*nowstartJava*)
InstallJava[]
(*andthingswork*)
controller=JavaNew["com.leapmotion.leap.Controller"]
Dynamic[controller[frame[][fingers[][count[]]]],UpdateInterval>0.1]

POSTEDBY:RolfMertig 3yearsago

AsmallifcrudeexampleofdatafromLeapMotion,whenthecontrollerisinitializedlikeinthisthread:

1
Vote

http://community.wolfram.com/groups//m/t/90931

3/5

08/09/2016

ConnectingtheLeapMotioncontrollertoMathematicaUsingJLinkOnlineTechnicalDiscussionGroupsWolframCommunity
getFrameData=
Module[{getFrame,getFingerList,getVector,makeRule,fun},
getFrame[controller_]:=controller@frame[]
getFingerList[frame_]:=
With[{f=frame@fingers[]},
Table[f@get[finger],{finger,0,f@count[]1}]]
getVector[v_]:={v@getX[],v@getY[],v@getZ[]}
makeRule[finger_,map_,method_]:=method>map[finger@method[]]
fun[controller_]:=
With[{fr=getFrame[controller]},
{makeRule[fr,#/1000000.&,timestamp],
fingers>
({makeRule[#,Identity,length],
makeRule[#,getVector,direction],
makeRule[#,getVector,tipPosition],
makeRule[#,getVector,tipVelocity],
makeRule[#,getVector,stabilizedTipPosition]}&/@
getFingerList[fr])}]
fun]

ThisfunctionreturnssomeofdataavailableintheAPI
(https://developer.leapmotion.com/documentation/Languages/Java/API/annotated.html)inMathematicastylemanner:
getFrameData[controller]

(*
{timestamp>15370.,
fingers>{{length>65.1096,
direction>{0.0140035,0.33028,0.943779},
tipPosition>{24.4047,179.213,115.658},
tipVelocity>{0.199876,0.767241,4.08685},
stabilizedTipPosition>{26.4247,178.62,116.503}},
...,
{length>41.934,
direction>{0.71685,0.00299873,0.697221},
tipPosition>{58.0986,148.038,0.762505},
tipVelocity>{2.57099,0.732685,3.28637},
stabilizedTipPosition>{57.0482,145.986,4.76263}}}}
*)

Startingpointforvisualizationofthisdatamightbethis,showingfingertips(correctingcoordinatedirectionsmakesitabitmessy
oneliner):
Graphics3D[
Dynamic[Sphere[{1,1,1}#[[{1,3,2}]],15]&/@
((tipPosition/.#)&/@(fingers/.getFrameData[controller])),UpdateInterval>0.05],
PlotRange>{{150,150},{150,150},{0,300}}]

http://community.wolfram.com/groups//m/t/90931

4/5

08/09/2016

ConnectingtheLeapMotioncontrollertoMathematicaUsingJLinkOnlineTechnicalDiscussionGroupsWolframCommunity

POSTEDBY:JariKirma 3yearsago

HowcouldIimprovetheswipedetectionrobustness?ShouldIchangetheframerate?OristheresomeotherparameterIshouldchange?
Thisatleastdoesonlyworksometimes:

1
Vote

(*thisisthedirectorywhereLeapSDKis*)
leapdir = FileN ameJoin[$UserBaseDirectory, " Applications ", " LeapDeveloperK it "] I f [FileExistsQ[leapdir],
Needs["JLink`"]
Block[{nativelibs},
With[{(*thelocationofthedeveloperkit:*)
lmlib=FileNameJoin[{

leapdir,"LeapSDK","lib"}]},nativelibs=FileNameJoin[{lmlib,Switch[$SystemID,"Windowsx8664","x64","

Type"]
If[Not[controller@isGestureEnabled[Gesture TypeTYPEUSWI PE]], controller@enableGesture[Gesture Type`TYPEUSWIPE]
]
controller@isGestureEnabled[Gesture$Type`TYPEUSWIPE]
gesturePrint[controller_]:=Module[{gesture},
gesture=controller@frame[]@gestures[]@get[0]
If[(gesture@type[]@name[])==="TYPE_SWIPE",
swipe=JavaNew["com.leapmotion.leap.SwipeGesture",gesture]
{swipe@state[]@toString[],
(swipe@position[]@#)&/@{getX[],getY[],getZ[]},
(swipe@direction[]@#)&/@{getX[],getY[],getZ[]},
swipe@speed[]
}]]
ud=.05
Dynamic[gesturePrint[controller],UpdateInterval>0.1]

POSTEDBY:RolfMertig 3yearsago

HelloChristopher,
WehadaquickdiscussionaboutLeapMotionattheComputerBasedMathConference.Ithinkyouhavesomemore
codeexamplesofLeapMotion...wouldyoumindsharingtheexamples?Thanks,Craig

http://community.wolfram.com/groups//m/t/90931

5/5

Anda mungkin juga menyukai