Set Camera View

This step-by-step process will help you setup the camera view.

Important: Grant Camera and storage Permission.

import AccuraOCR
import AVFoundation
var accuraCameraWrapper: AccuraCameraWrapper? = nil
override func viewDidLoad() {
	super.viewDidLoad()
    // initialize Camera for OCR,MRZ,DLplate and BankCard
    accuraCameraWrapper = AccuraCameraWrapper.init(delegate: self, andImageView: /*setImageView*/ _imageView, andLabelMsg: */setLable*/ lblOCRMsg, andurl: */your PathForDirectories*/ NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String, cardId: /*setCardId*/ Int32(cardid!), countryID: /*setcountryid*/ Int32(countryid!), isScanOCR:/*Bool*/ isCheckScanOCR, andcardName:/*string*/  docName, andcardType: Int32(cardType/*2 = DLPlate And 3 = bankCard*/), andMRZDocType: /*SetMRZDocumentType*/ Int32(MRZDocType!/*0 = AllMRZ, 1 = PassportMRZ, 2 = IDMRZ, 3 = VisaMRZ*/))
        
    // initialize Camera for Barcode and PDF417 driving license
    accuraCameraWrapper = AccuraCameraWrapper.init(delegate: self, andImageView: imageView, andLabelMsg: lblBottamMsg, andurl: 1, isBarcodeEnable: isBarcodeEnabled/*set true for barcode and false for PDF417 driving license*/, countryID: Int32(self.countryid!), setBarcodeType: .all/*set barcode types*/)
        
	//Set min frame for qatar ID card
	//call this function before start camera
	accuraCameraWrapper?.setMinFrameForValidate(3) // Supports only odd number values
}

override func viewDidAppear(_ animated: Bool) {
	super.viewDidAppear(animated)
	accuraCameraWrapper?.startCamera()
}

override func viewWillDisappear(_ animated: Bool) {
	accuraCameraWrapper?.stopCamera()
	accuraCameraWrapper?.closeOCR()
	accuraCameraWrapper = nil
	super.viewWillDisappear(animated)
}

extension ViewController: VideoCameraWrapperDelegate{
	//it sets ViewLayer border according to card image
	func  onUpdateLayout(_ frameSize: CGSize, borderRatio: Float) {
	frameSize:- get layer frame size
	borderRatio:- get layer ratio
	}
    
    func isBothSideAvailable(_ isBothAvailable: Bool) {
        accuraCameraWrapper?.cardSide(.FRONT_CARD_SCAN)
    }
	
	//it calls when scan barcode an PDF417 Driving license
    func recognizeSucceedBarcode(_ message: String!, back BackSideImage: UIImage!, frontImage FrontImage: UIImage!, face FaceImage: UIImage!) {
          //message :- Barcode Data
          //BackSideImage :- back image of Document
          //FrontImage :- front image of Document
          //FaceImage :- Face image of document
          if(isBarcodeEnabled) {
              //display result of barcode
          } else {
               if(BackSideImage == nil) {
                    self.accuraCameraWrapper?.cardSide(.BACK_CARD_SCAN)
                    self.flipAnimation()
              } else if (FrontImage == nil) {
                  self.accuraCameraWrapper?.cardSide(.FRONT_CARD_SCAN)
                  self.flipAnimation()
              }else {
                  //Display Result
              }
         }

	//  it calls continues when detect frame from camera
	func processedImage(_ image: UIImage!) {
		image:- get camara image.
	}

	// it call when license key wrong or didnt get key.license file
	func recognizeFailed(_ message: String!) {
		message:- message is a set alert message.
	}

	// it calls when get MRZ data

	func recognizeSucceed(_ scanedInfo: NSMutableDictionary!, recType: RecType, bRecDone: Bool, bFaceReplace: Bool, bMrzFirst: Bool, photoImage: UIImage, docFrontImage: UIImage!, docbackImage: UIImage!) {
		scanedInfo :- get MRZ data.
		photoImage:- get a document face Image.
		docFrontImage:- get document frontside image.
		docbackImage:- get document backside image.
	}

	// it calls when get front or back side image
	func matchedItem(_ image: UIImage!, isCardSide1 cs: Bool, isBack b: Bool, isFront f: Bool, imagePhoto imgp: UIImage!, imageResult: UIImage!) {
		if f == true to set frontside document Image.
		if f == false to set backside document Image.
	}

	//  it calls when get OCR data
	func resultData(_ resultmodel: ResultModel!) {
        if isbothSideAvailable {
            accuraCameraWrapper?.cardSide(.BACK_CARD_SCAN)
            if(resultmodel.arrayocrBackSideDataKey.count > 0) {
                //Display Result
            }
        } else {
            //Display result
        }
    }

	//  it calls when detect vehicle numberplate
	func dlPlateNumber(_ plateNumber: String!, andImageNumberPlate imageNumberPlate: UIImage!) {
		plateNumber:- get data of numberplate
		imageNumberPlate:- get image of numberplate
	}

	//it calls when get Bank Card data
	func recognizSuccessBankCard(cardDetail: NSMutableDictionary!, andBankCardImage bankCardImage: UIImage!) {
		cardDetail["card_type"] :- get bank card type
		cardDetail["card_number"] :- get bank card number
		cardDetail["expiration_month"] :- get bank card expiry month
		cardDetail["expiration_year"] :- get bank card expiry year
	}

	// it calls when recieve error message
	func reco_msg(_ messageCode: String!) {
		var message = String()
		if messageCode == ACCURA_ERROR_CODE_MOTION {
			message = "Keep Document Steady";
		} else if(messageCode == ACCURA_ERROR_CODE_DOCUMENT_IN_FRAME) {
			message = "Keep document in frame";
		} else if(messageCode == ACCURA_ERROR_CODE_BRING_DOCUMENT_IN_FRAME) {
			message = "Bring card near to frame";
		} else if(messageCode == ACCURA_ERROR_CODE_PROCESSING) {
			message = "Processing...";
		} else if(messageCode == ACCURA_ERROR_CODE_BLUR_DOCUMENT) {
			message = "Blur detect in document";
		} else if(messageCode == ACCURA_ERROR_CODE_FACE_BLUR) {
			message = "Blur detected over face";
		} else if(messageCode == ACCURA_ERROR_CODE_GLARE_DOCUMENT) {
			message = "Glare detect in document";
		} else if(messageCode == ACCURA_ERROR_CODE_HOLOGRAM) {
			message = "Hologram Detected";
		} else if(messageCode == ACCURA_ERROR_CODE_DARK_DOCUMENT) {
			message = "Low lighting detected";
		} else if(messageCode == ACCURA_ERROR_CODE_PHOTO_COPY_DOCUMENT) {
			message = "Can not accept Photo Copy Document";
		} else if(messageCode == ACCURA_ERROR_CODE_FACE) {
			message = "Face not detected";
		} else if(messageCode == ACCURA_ERROR_CODE_MRZ) {
			message = "MRZ not detected";
		} else if(messageCode == ACCURA_ERROR_CODE_PASSPORT_MRZ) {
			message = "Passport MRZ not detected";
		} else if(messageCode == ACCURA_ERROR_CODE_ID_MRZ) {
			message = "ID MRZ not detected"
		} else if(messageCode == ACCURA_ERROR_CODE_VISA_MRZ) {
			message = "Visa MRZ not detected"
		}else if(messageCode == ACCURA_ERROR_CODE_UPSIDE_DOWN_SIDE) {
			message = "Document is upside down. Place it properly"
		}else if(messageCode == ACCURA_ERROR_CODE_WRONG_SIDE) {
			message = "Scanning wrong side of Document"
		}else {
			message = message;
		}
		print(message)
	}
}


// it calls when update title messages
func reco_titleMessage(_ messageCode: Int32) {
    var msg: String = ""
    switch messageCode {
        case SCAN_TITLE_OCR_FRONT:
            var frontMsg = "Scan Front side of ";
            frontMsg = frontMsg.appending(docName)
            msg = frontMsg
            break
        case SCAN_TITLE_OCR_BACK:
            var backMsg = "Scan Back side of ";
            backMsg = backMsg.appending(docName)
            msg = backMsg
            break
        case  SCAN_TITLE_OCR:
            var backMsg = "Scan ";
            backMsg = backMsg.appending(docName)
            msg = backMsg
            break
        case SCAN_TITLE_MRZ_PDF417_FRONT:
            msg = "Scan Front Side of Document"
            break
        case SCAN_TITLE_MRZ_PDF417_BACK:
            msg = "Scan Back Side of Document"
            break
        case SCAN_TITLE_DLPLATE:
            msg = "Scan Number plate"
            break
        case SCAN_TITLE_BARCODE:
            msg = "Scan Barcode"
            break
        case SCAN_TITLE_BANKCARD:
            msg = "Scan BankCard"
            break
        default:
            break
    }
    print(msg)
}

Last updated