You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A detector that searches for Quick Response codes (a type of 2D barcode) in a still image or video, returning CIQRCodeFeature objects that provide information about detected barcodes.
In macOS 10.13, iOS 11, and tvOS 11 or later, the Vision framework replaces these classes for identifying and analyzing image features.
Using VNRequest, and particular VNDetectBarcodesRequest, we can detect barcodes in an image. It supports a bunch of code types, in form of VNBarcodeSymbology
func read(image:CGImage)async->VNBarcodeObservation?{awaitwithCheckedContinuation{ con indo{letrequest=VNDetectBarcodesRequest(completionHandler:{ request, error in
if let request = request as?VNDetectBarcodesRequest,let result = request.results?.first {
con.resume(returning: result)}else{
con.resume(returning:VNBarcodeObservation?.none)}})
request.symbologies =try request.supportedSymbologies()
request.revision = VNDetectBarcodesRequestRevision1
lethandler=VNImageRequestHandler(cgImage: image)try handler.perform([request])}catch{
con.resume(returning:VNBarcodeObservation?.none)}}}
Note we have to use VNDetectBarcodesRequestRevision1 for now since the default VNDetectBarcodesRequestRevision4 does not seem to work.
With VNBarcodeObservation, we can read payloadStringValue and symbology to get content and which code type it has detected
The text was updated successfully, but these errors were encountered:
It seems like other revisions except VNDetectBarcodesRequestRevision1 do not work on the simulator, the latestVNDetectBarcodesRequestRevision4 still works on real devices (tested on simulator iOS 17.2 and iPhone 11 Pro with iOS 17.5.1)
another issue related to this StackOverflow but this doesn't happen to me: https://stackoverflow.com/questions/73770477/vndetectbarcodesrequest-not-working-on-ios16
Before iOS 11, we used to use
CIDetector
andCIDetectorTypeQRCode
to detect QR codeCIDetector
CIDetectorTypeQRCode
In macOS 10.13, iOS 11, and tvOS 11 or later, the Vision framework replaces these classes for identifying and analyzing image features.
Using VNRequest, and particular
VNDetectBarcodesRequest
, we can detect barcodes in an image. It supports a bunch of code types, in form ofVNBarcodeSymbology
Note we have to use
VNDetectBarcodesRequestRevision1
for now since the defaultVNDetectBarcodesRequestRevision4
does not seem to work.With
VNBarcodeObservation
, we can readpayloadStringValue
andsymbology
to get content and which code type it has detectedThe text was updated successfully, but these errors were encountered: