How do I scan a QR Code using RealityKit?

I am building an iOS app using RealityKit. I would like to read a QR Code within ARView but cannot find any documentation/tutorials on it.

Any advice/guidance on doing this would be much appreciated! Thanks in advance.

Replies

RealityKit has no built-in QR code detector, but you can use the CoreImage or Vision framework to accomplish this task.

From within an ARKit session, you can access the current camera image as follows: arView.session.currentFrame.capturedImage.
Based on that image, you can then run the QR code detection.

If you use Vision, have a look at VNDetectBarcodesRequest (https://developer.apple.com/documentation/vision/vndetectbarcodesrequest). You can also find a sample project here: https://developer.apple.com/documentation/vision/detecting_objects_in_still_images.

If you prefer to use CoreImage, have a look at the CIDetector class (https://developer.apple.com/documentation/coreimage/cidetector) which you would initialize with the type CIDetectorTypeQRCode.
If I use ARKit will I be able to simultaneously load AR objects/images and read QR codes? I am hoping to do both within the same session/camera view.