How to Implement Image Capture Processing
Note: Before you begin, see How to Add the Library to Your Xcode Project.
To implement the image capture scenario, follow these steps:
- Implement a delegate conforming to the RTRImageCaptureServiceDelegate protocol. The delegate will handle messages from the image capture service. Here are the recommendations on what its methods should do:
- The onBufferProcessedWithStatus:result: method is where you work with the results, display them to the user, etc.
- The onError: method is for handling processing errors.
- The onWarning: method can optionally be used to show warnings to the user.
- Create an RTREngine object using the sharedEngineWithLicenseData: method. The method requires an NSData object containing your license data. For example, you can use dataWithContentsOfFile: to create a data object, then pass this object to the sharedEngineWithLicenseData: method.
- Use the createImageCaptureServiceWithDelegate: method of the RTREngine object to create a background image capture service. Only one instance of the service per application is necessary: multiple threads will be started internally.
- Implement a delegate that adopts the AVCaptureVideoDataOutputSampleBufferDelegate protocol. Instantiate an AVCaptureSession object, add video input and output and set the video output delegate. When the delegate receives a video frame via the captureOutput:didOutputSampleBuffer:fromConnection: method, pass this frame on to the image capture service by calling the addSampleBuffer: method.
We recommend using the AVCaptureSessionPreset1920x1080 preset for your AVCaptureSession.
Also note that your video output must be configured to use the kCVPixelFormatType_32BGRA video pixel format. - Process the messages sent by the service to the RTRImageCaptureServiceDelegate delegate object. The result will be delivered via the onBufferProcessedWithStatus:result: method. It also reports the result stability status, which indicates if the result is available and if it is likely to be improved by adding further frames (see the Status parameter).
- Process the delivered result using the RTRImagingCoreAPI functionality:
- load the captured image to an RTRCoreAPIImage protocol instance;
- crop it with the RTRCoreAPICropOperation in case the lens correction is required.
- Export the processed result to the server in one of available formats: JPG, JPG 2000, PNG or PDF. It is recommended to use the RTRCoreAPIExportCompressionNormalLevel compression mode for saving high quality while reducing image size.
- When pausing or quitting the application, call the stopTasks method to stop processing and clean up image buffers. The image capture service keeps its configuration settings and necessary resources. The processing will start automatically on the new call to the addSampleBuffer: method.
See the description of classes and methods in the API Reference section.
02.03.2022 12:59:15