Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/Vision/Hand Test


Last modified Fri, 6th Aug 2026.

You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /MacFrameworks/Vision/Hand Test

Download this example: Hand Test.zip

Project "Hand Test.xojo_binary_project"
Class App Inherits DesktopApplication
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Opening() If VisionModuleMBS.available Then // okay Else MsgBox "Please run as 64-bit MacOS app on MacOS 10.13 or newer." End If End EventHandler
End Class
Class Window1 Inherits DesktopWindow
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub ExpandRow(row As Integer) End EventHandler
End Control
Control Output Inherits Canvas
ControlInstance Output Inherits Canvas
End Control
EventHandler Sub Opening() Dim f As FolderItem = FindFile("handDown.jpg") If f.Exists Then Dim image As Picture = Picture.Open(f) performVisionRequest image End If End EventHandler
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Sub Redraw() If pic <> Nil Then Dim OutputWidth As Integer = output.Width Dim OutputHeight As Integer = output.Height Dim p As New Picture(outputWidth, outputHeight) Dim faktor As Double = Min( OutputHeight / Pic.Height, OutputWidth / Pic.Width) // Calculate new size Dim w As Integer = Pic.Width * faktor Dim h As Integer = Pic.Height * faktor Dim g As Graphics = p.Graphics Dim x As Integer = (g.width - w)/2 Dim y As Integer = (g.height - h)/2 g.DrawPicture pic, x, y, w, h, 0, 0, pic.Width, pic.Height g.PenWidth = 1 g.PenHeight = 1 For Each Observation As Variant In Observations If Observation IsA VNHumanHandPoseObservationMBS Then Dim hhp As VNHumanHandPoseObservationMBS= Observation Dim e As NSErrorMBS List.AddRow("Human Handpose") g.ForeColor = &cFF00FF Dim Wrist As VNRecognizedPointMBS = hhp.recognizedPointForJointName(VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameWrist,e ) Dim wx As Double = x + (wrist.X * w) Dim wy As Double = y + h - (Wrist.Y * h) g.FillOval wX-4, wY-4, 8, 8 Dim blue As Color = &c1E90FF Dim green As Color = &c228B22 Dim yellow As Color = &cFFD700 Dim orange As Color = &cFF7F00 Dim newX As Double Dim newY As Double Dim oldX As Double Dim oldY As Double Dim current as VNRecognizedPointMBS oldX=wx oldY=wy List.AddRow("Wrist", oldX.ToString+"/"+oldY.ToString) //Thumb //1 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameThumbCMC , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = orange g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Thumb CMC", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //2 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameThumbMP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) g.ForeColor = yellow g.FillOval newX-4, newY-4, 8, 8 List.AddRow("Thumb MP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //3 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameThumbIP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = green g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Thumb IP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //4 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameThumbTip , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = blue g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Thumb Tip", newX.ToString+"/"+newY.ToString) //Index Finger oldX=wx oldY=wy //1 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameIndexMCP, e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = orange g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Index MCP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //2 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameIndexPIP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = yellow g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Index PIP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //3 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameIndexDIP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = green g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Index DIP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //4 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameIndexTip , e) newX = x + (current.x * w ) newY =y + h - (current.y * h ) g.ForeColor = blue g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Index Tip", newX.ToString+"/"+newY.ToString) //Middel Finger oldX=wx oldY=wy //1 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameMiddleMCP, e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = orange g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Middle MCP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //2 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameMiddlePIP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = yellow g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Middle PIP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //3 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameMiddleDIP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = green g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Middle DIP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //4 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameMiddleTip , e) newX = x + (current.x * w ) newY =y + h - (current.y * h ) g.ForeColor = blue g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Middle Tip", newX.ToString+"/"+newY.ToString) //Ring Finger oldX=wx oldY=wy //1 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameRingMCP, e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = orange g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Ring MCP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //2 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameRingPIP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = yellow g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Ring PIP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //3 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameRingDIP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = green g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Ring DIP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //4 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameRingTip , e) newX = x + (current.x * w ) newY =y + h - (current.y * h ) g.ForeColor = blue g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Ring Tip", newX.ToString+"/"+newY.ToString) //Little Finger oldX=wx oldY=wy //1 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameLittleMCP, e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = orange g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Little MCP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //2 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameLittlePIP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = yellow g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Little PIP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //3 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameLittleDIP , e) newX = x + (current.x * w ) newY = y + h - (current.y * h ) g.ForeColor = green g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Little DIP", newX.ToString+"/"+newY.ToString) oldX=newX oldY=newY //4 current = hhp.recognizedPointForJointName (VNDetectHumanHandPoseRequestMBS.VNHumanHandPoseObservationJointNameLittleTip , e) newX = x + (current.x * w ) newY =y + h - (current.y * h ) g.ForeColor = blue g.FillOval newX-4, newY-4, 8, 8 g.ForeColor = &cEBEBEB g.DrawLine(oldX, oldY, newX, newY) List.AddRow("Little Tip", newX.ToString+"/"+newY.ToString) End If Next 'Dim fi as FolderItem = SpecialFolder.Desktop.Child("handImage.jpg") output.Backdrop = p 'output.Backdrop.Save(fi, Picture.Formats.JPEG) Else output.Backdrop = Nil End If End Sub
Sub RequestCompleted(request as VNRequestMBS, error as NSErrorMBS, tag as Variant) If error <> Nil Then List.AddRow request.className+" failed" Else List.AddRow request.className+" succeeded" End If if request <> nil then Dim results() As VNObservationMBS = request.results If results.Ubound >= 0 Then For Each result As VNObservationMBS In results If result.Confidence > 0.5 Then Observations.Append result Else // ignore bad things like low level classifications End If Next Redraw End If end if End Sub
Function createVisionRequests() As VNRequestMBS() Dim requests() As VNRequestMBS Requests.Append New VNDetectHumanHandPoseRequestMBS(WeakAddressOf RequestCompleted) Return requests End Function
Sub performRequestsCompleted(Requests() as VNRequestMBS, result as boolean, error as NSErrorMBS, tag as Variant) If result Then list.AddRow "performRequests succeeded." Else list.AddRow "performRequests failed." End If If error <> Nil Then List.AddRow "Error", error.LocalizedDescription End If End Sub
Sub performVisionRequest(pic as Picture) Self.pic = pic Dim requests() As VNRequestMBS = createVisionRequests Dim imageRequestHandler As VNImageRequestHandlerMBS = VNImageRequestHandlerMBS.RequestWithPicture(pic) list.DeleteAllRows Redim Observations(-1) Dim error As NSErrorMBS list.AddRow "performRequests..." // store in property to avoid too early release currentRequests = requests If False Then // run async on background thread imageRequestHandler.performRequestsAsync(requests, WeakAddressOf performRequestsCompleted) else // sync Dim result As Boolean = imageRequestHandler.performRequests(requests, error) If result Then list.AddRow "performRequests succeeded." Else list.AddRow "performRequests failed." End If If error <> Nil Then List.AddRow "Error", error.LocalizedDescription End If End If End Sub
Property Observations() As VNObservationMBS
Property Pic As Picture
Property currentRequests As Variant
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
MenuItem WindowMenu = "Window"
MenuItem HelpMenu = "&Help"
End MenuBar
Sign
End Sign
End Project

Download this example: Hand Test.zip

The items on this page are in the following plugins: MBS MacFrameworks Plugin.


The biggest plugin in space...