Vision SDK
iOS
Barcode and QR Code scanner framework for iOS. VisionSDK provides a way to detect barcodes and qr codes. It also provides the functionality for information extraction from different kind of logistic labels like shipping labels, inventory labels, bill of ladings, receipts & invoices
Development Requirements
- iOS 13.0+
- Swift: 5.4.2+
- Xcode Version: 13.0+
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions,
visit their website. To integrate VisionSDK into your Xcode project using CocoaPods, specify it in your Podfile
:
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code
and is integrated into the swift
compiler.
Once you have your Swift package set up, add the VisionSDK as a dependency by adding it to the dependencies
value of your Package.swift
.
Manual Framework Integration
- In Xcode, move to "General > Build Phase > Linked Frameworks and Libraries"
- Add the VisionSDK.xcframework from to your project
- Mark it "Embed and Sign"
- Write Import statement on your source file
Usage
Update Info.plist
Add Privacy - Camera Usage Description
to Info.plist file
Initialization
In order to use the OCR API for information extraction, you have to set following parameters
Constants.apiKey
to your API key.Constants.apiEnvironment
you also need to specify the API environment that you have the API key for (sandbox or production).
Please note that these have to be set before using the API call. You can generate your own API key at cloud.packagex.io. You can find the instruction guide here.
Code Samples
You can find the sample code for using the vision-sdk on our github.
Functional Description
Configuration Method
Parameters
delegate
Should be the class that confirms to the CodeScannerViewDelegate
protocol
Input struct
Input struct defines the properties of scanner view. These properties are:
Input.focusImage
UIImage
Image to be displayed in the center of the view. If not provided, VisionSDK will use the default image. Note that focus rectangle frame is subject to change with respect to different scan modes.Input.focusImageRect
CGRECT
Custom rect for the focus image. You can provide your preferred rect or use.zero
for default. Note that default focus rectangle frame is subject to change with respect to different scan modes.Input.shouldDisplayFocusImage
Bool
settrue
if you need focused region to be drawn.Input.shouldScanInFocusImageRect
Bool
settrue
if you want to detect codes visible in focused region only. This will discard the codes detected to be outside of the focus image.Input.isTextIndicationOn
Bool
Setfalse
if you do not want to detect text in live camera feed. If set falsecodeScannerViewDidDetect(_ text: Bool, barCode: Bool, qrCode: Bool)
method will sendtext
parameter as false.Input.isBarCodeOrQRCodeIndicationOn
Bool
Set false if you do not want to detect bar codes or qrcodes in live camera feed. Using this property my be helpful in cases if you want to perform manual capture based on code detectionInput.sessionPreset
Session.Preset
You can set session preset as per your requirement. Default is.high
.Input.nthFrameToProcess
Int
This is the nth number of the frame that is processed for detection of text, barcodes, and qrcodes in live camera feed if enabled byisTextIndicationOn
orisBarCodeOrQRCodeIndicationOn
. Processing every single frame may be costly in terms of CPU usage and battery consumption. Default value is10
which means that from camera stream of usual 30 fps, every 10 frame is processed. Its value should be set between 1 - 30.Input.captureMode
Set it to.multiple
if you want to allow multiple results from scan. In.manual
case, you will have to manually trigger scanning usingcapturePhoto()
method.Input.captureType
Image to be displayed in the center of the view. If not provided, VisionSDK will use the default image. Note that focus rectangle frame is subject to change with respect to different scan modes.Input.scanMode
Defines the scan mode. It has following options.barCode
- Detects barcodes only in this mode.qrCode
- Detects qr codes only in this mode.ocr
- Use this mode to capture photos for later user in OCR API call..autoBarCodeOrQRCode
- Detects both bar codes and qr codes
Set Scan Mode
- Sets the scan mode to desired mode. i.e
- .barCode
- .qrcode
- .ocr
- .autoBarCodeOrQRCode
Set Capture Mode
- Sets the capture mode to desired mode. i.e
- .manual
- .auto
Set Capture Type
- Sets the capture type to desired type.
Start the scanning
- Needs
configure()
method to be called before it. It starts the camera session and scanning.
Stop the scanning
- Stops camera session and scanning.
Rerstart the camera & scanning
- Use this function to resume scanning
Deconfigure the configurations
- Removes all the configurations of scannerView and stops scanning.
Capture the photo/image
- Use this method to trigger code scan or photo capture when you are scanning for multiple codes, in manual capture or OCR mode.
Delegate Methods / Callbacks
- This method returns with the codes scanned after successful scan
- This method is called when text, barcode or qr code is detected in the camera stream. Values depend on whether text or code indication is enabled while configuring the scanner view.
- This method is called when
capturePhoto()
method is called in OCR Mode. It return with the captured image and all the detected codes in it.
- This method is called when an error occurs in any stage of initializing or capturing the codes when there is none detected.
OCR Method
- This method is called on the shared instance of
VisionAPIManager
. It can be accessed usingVisionAPIManager.shared
syntax. This method recieves the captured image and the API Key or AuthToken as parameters. It returns with the OCR Response from PackageX API Response.