{"id":13444294,"url":"https://github.com/hanleyweng/CoreML-in-ARKit","last_synced_at":"2025-03-20T18:32:00.458Z","repository":{"id":41070762,"uuid":"97212044","full_name":"hanleyweng/CoreML-in-ARKit","owner":"hanleyweng","description":"Simple project to detect objects and display 3D labels above them in AR. This serves as a basic Template for an ARKit project to use CoreML.","archived":false,"fork":false,"pushed_at":"2021-08-23T17:31:10.000Z","size":25091,"stargazers_count":1684,"open_issues_count":7,"forks_count":218,"subscribers_count":56,"default_branch":"master","last_synced_at":"2025-03-18T09:13:23.064Z","etag":null,"topics":["arkit","augmented-reality","coreml","deep-learning","ios","machine-learning"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hanleyweng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-14T08:33:22.000Z","updated_at":"2025-03-16T14:19:12.000Z","dependencies_parsed_at":"2022-08-10T01:35:07.639Z","dependency_job_id":null,"html_url":"https://github.com/hanleyweng/CoreML-in-ARKit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanleyweng%2FCoreML-in-ARKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanleyweng%2FCoreML-in-ARKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanleyweng%2FCoreML-in-ARKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanleyweng%2FCoreML-in-ARKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hanleyweng","download_url":"https://codeload.github.com/hanleyweng/CoreML-in-ARKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244670376,"owners_count":20490963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arkit","augmented-reality","coreml","deep-learning","ios","machine-learning"],"created_at":"2024-07-31T03:02:23.903Z","updated_at":"2025-03-20T18:32:00.453Z","avatar_url":"https://github.com/hanleyweng.png","language":"Swift","funding_links":[],"categories":["Swift","Projects","Core ML","Content","Libraries/Frameworks/Tools"],"sub_categories":["Repos","Label"],"readme":"# CoreML-in-ARKit\nThis simple project detects objects in Augmented Reality and displays 3D labels on top of them. This serves as a basic template for an ARKit project to use CoreML.\n\n![image of scene with 3d labels on objects](post-media/giphy.gif)\n\n[Demo Video - on Youtube](https://www.youtube.com/watch?v=RjIbiAC8cBk)\n\nModel: Inception V3\n\nLanguage: Swift 4.0\n\nWritten in: Xcode 9.0 GM (9A235) (Updated) ~~XCode 9 beta 3 (9M174d)~~\n\nContent Technology: SceneKit\n\nTested on iPhone 7 plus running iOS 11 beta 3 (15A5318g)\n\nNote: SceneKit can achieve a 60 FPS on iPhone7+ - though when it gets hot, it'll drop to 30 FPS.\n\n## Instructions\n\nYou'll have to download \"Inceptionv3.mlmodel\" from [Apple's Machine Learning page](https://developer.apple.com/machine-learning/), and copy it into your XCode project. (As depicted in the following gif)\n\n![Gif to show dragging and dropping of model into XCode](post-media/AddingMLModel.gif)\n\n[_(Gif via Atomic14)_](https://github.com/atomic14/VisionCoreMLSample)\n\nIf you're having issues, double check that the model is part of a target [(source: stackoverflow)](https://stackoverflow.com/questions/45884085/model-is-not-part-of-any-target-add-the-model-to-a-target-to-enable-generation).\n\n## Footnotes\n\n- SceneKit Text Labels are expensive to render. Too many polygons (too much text, smoothness, characters) - can cause crashes. In future, SpriteKit would be more efficient for text-labels.\n\n- Not entirely certain if the code is actually transferring RGB data to the Vision Model (as opposed to YUV). Proof-of-concept-wise, it appears to work just fine with the Inception V3 model for now.\n\n- Whilst ARKit's FPS , is displayed - CoreML's speed is not. However, it does appear sufficiently fast for real-time ARKit applications.\n\n- Placement of the label is simply determined by the raycast screen centre-point to a ARKit feature-point. This could be altered for more stable placement.\n\n## Building Blocks (Overview)\n\n### Get CoreML running in real time in ARKit\n\n- There are some good tutorials / sample projects for getting CoreML running. See: [[ 1 ]](https://github.com/atomic14/VisionCoreMLSample) [[ 2 ]](https://github.com/yulingtianxia/Core-ML-Sample) [[ 3 ]](http://www.stringcode.co.uk/mlcamera/)\n\n- What we do differently here is we're using ARKit's ARFrame as the image to be fed into CoreML.\n\n```\nlet pixbuff : CVPixelBuffer? = (sceneView.session.currentFrame?.capturedImage)\n```\n\n- We also use Threading to continuously run requests to CoreML in realtime, and without disturbing ARKit / SceneView\n\n```\nlet dispatchQueueML = DispatchQueue(label: \"com.hw.dispatchqueueml\")\n...\nloopCoreMLUpdate() // on viewLoad\n...\nfunc loopCoreMLUpdate() {\n    dispatchQueueML.async {\n        // 1. Run Update.\n        self.updateCoreML()\n        // 2. Loop this function.\n        self.loopCoreMLUpdate()\n    }\n}\n```\n\n### Add 3D Text\n\n- Add a Tap Gesture.\n- On Tap. Get the raycast centre point, translating it to appropriate coordinates.\n- Render 3D text at that location. Use the most likely object.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanleyweng%2FCoreML-in-ARKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhanleyweng%2FCoreML-in-ARKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanleyweng%2FCoreML-in-ARKit/lists"}