DynamsoftCameraEnhancer Class
The main class of DynamsoftCameraEnhancer. It contains APIs that enable user to:
- Implement basic camera control like open, close, change resolution, etc.
- Get frames from the video streaming.
- Enable advanced features including:
- Frame filtering by sharpness
- Frame filtering by sensor
- Enhanced focus
- Frame cropping
- Auto zoom
- Smart torch control
- Objective-C
- Swift
@interface DynamsoftCameraEnhancer:NSObject<ImageSource>class DynamsoftCameraEnhancer : NSObject, ImageSource
Initialization Methods Summary
| Method | Description |
|---|---|
initWithView |
Initialize the camera enhancer with the camera view |
getVersion |
Get the SDK version. |
cameraView |
Bind a DCECameraView to the camera enhancer. |
Basic Camera Control Methods Summary
| Method | Description |
|---|---|
getAllCameras |
Get all available cameras. This method returns a list of available camera IDs. |
selectCameraWithPosition |
Select whether to use front-facing camera or back-facing camera. |
getCameraPosition |
Returns whether the front-facing camera or back-facing camera is selected. |
selectCamera |
Select a camera from the camera list with the camera ID. |
getSelectedCamera |
Get the camera ID of the current selected camera. |
getCameraState |
Get the state of the current selected camera. |
open |
Turn on the current selected camera. |
close |
Turn off the current selected camera. |
turnOnTorch |
Turn on the torch. |
turnOffTorch |
Turn off the torch. |
getFrameRate |
Get the current frame rate. |
setResolution |
Set the resolution to the input value (if the input value is available for the device). |
getResolution |
Get the current resolution. |
setZoom |
Set the zoom factor. Once setZoom is triggered and approved, the zoom factor of the activated camera will immediately become the input value. |
autoZoomRange |
The property for getting/setting the range of auto zoom. |
getMaxZoomFactor |
Get the maximum available zoom factor. |
setFocus |
Set the focus position (value range from 0.0f to 1.0f) and trigger a focus at the configured position. |
setFocus(subsequentFocusMode) |
Trigger a focus at the targeting point and set the subsequent focus mode after focused. |
setScanRegion |
Set the scanRegion with a iRegionDefinition value. The frame will be cropped according to the scan region. |
getScanRegion |
Get the scan region. |
scanRegionVisible |
Set whether to display the scanRegion on the UI. |
setCameraStateListener |
Add a DCECameraStateListener to receive notification when the camera state changes. |
Frame Acquiring Methods Summary
| Method | Description |
|---|---|
getFrameFromBuffer |
Get the latest frame from the buffer. The boolean value determines whether the fetched frame will be removed from the buffer. |
addListener |
Add a listener to the camera enhancer instance. |
removeListener |
Remove a previously added listener from the camera enhancer instance. |
Enhanced Features Methods Summary
| Method | Description |
|---|---|
enableFeatures |
Enable camera enhancer features by inputting EnumEnhancerFeatures values. |
disableFeatures |
Disable camera enhancer features by inputting EnumEnhancerFeatures values. |
isFeatureEnabled |
Check whether the input features are enabled. |
Advanced Camera Control Methods Summary
| Method | Description |
|---|---|
updateAdvancedSettingsFromFile |
Update the advanced camera controlling and video streaming processing parameters. This method enables you to update settings via a JSON file from the storage. |
updateAdvancedSettingsFromString |
Update the advanced camera controlling and video streaming processing parameters. This method enables you to update settings via a JSON string. |
Initialization Methods Details
initWithView
Initialize the camera enhancer with the DCECameraView.
- Objective-C
- Swift
- (instancetype)initWithView:(DCECameraView *)view;init(view: DCECameraView) -> DynamsoftCameraEnhancer
Return Value
The instance of DynamsoftCameraEnhancer.
Code Snippet
- Objective-C
- Swift
_dce = [[DynamsoftCameraEnhancer alloc] initWithView:_dceView];let dce = DynamsoftCameraEnhancer.init(view: dceCameraView)
getVersion
Get the SDK version of Dynamsoft Camera Enhancer.
- Objective-C
- Swift
+ (NSString*)getVersion;class func getVersion() -> String
Return Value
A string value that indicates the version of DynamsoftCameraEnhancer SDK.
Code Snippet
- Objective-C
- Swift
NSString* version = [DynamsoftCameraEnhancer getVersion];let version = DynamsoftCameraEnhancer.getVersion()
cameraView
Bind a DCECameraView to the camera enhancer.
- Objective-C
- Swift
@property (strong, nonatomic) DCECameraView *dceCameraView;var dceCameraView: DCECameraView { get set }
Code Snippet
- Objective-C
- Swift
_dceView = [[DCECameraView alloc] initWithFrame:self.view.bounds] [_dce setCameraView:_dceView];let dceView = DCECameraView.init(frame self.view.bounds) dce.cameraView = dceView
Basic Camera Control Methods Details
getAllCameras
Get the IDs of all available cameras.
- Objective-C
- Swift
- (NSArray*)getAllCameras;func getAllCameras() -> [String]
Return Value
An NSArray that includes all available cameras. Users can clearly read whether the camera is front-facing, back-facing, or external from the cameraID.
Code Snippet
- Objective-C
- Swift
NSArray<NSString*>* allCameras = [_dce getAllCameras];let allCameraList = dce.getAllCameras()
selectCameraWithPosition
Select the camera position (front-facing or back-facing).
- Objective-C
- Swift
- (void)selectCameraWithPosition:(EnumCameraPosition)position error:(NSError * _Nullable * _Nullable)error;func selectCameraWithPosition(_ position: EnumCameraPosition) throws
Parameters
cameraPosition: An EnumCameraPosition value that indicates front-facing or back-facing camera.
Code Snippet
- Objective-C
- Swift
[_dce selectCameraWithPosition:EnumCameraPositionBack error: &error];do{ try dce.selectCameraWithPosition(EnumCameraPosition.back) }catch{ // Add your code to deal with the exceptions. }
getCameraPosition
Returns whether the front-facing camera or back-facing camera is selected.
- Objective-C
- Swift
- (EnumCameraPosition) getCameraPosition;func getCameraPosition() -> EnumCameraPosition
Return Value
An EnumCameraPosition value that indicates front-facing or back-facing camera.
Code Snippet
- Objective-C
- Swift
EnumCameraPosition cameraPosition = [_dce getCameraPosition];let cameraPosition = dce.getCameraPosition()
selectCamera
Select camera by cameraID. The camera will be selected and further camera control settings will be applied to this camera. When the selected camera is changed via this method, the settings will be inherited by the newly selected camera.
- Objective-C
- Swift
- (void)selectCamera:(NSString*)cameraId error:(NSError * _Nullable * _Nullable)error;func selectCamera(_ cameraId: String) throws
Parameters
cameraID: A String value that listed in the cameraIDList returned by getAllCameras. The method will have no effects if the input value does not exist in the cameraIDList.
Code Snippet
- Objective-C
- Swift
[_dce selectCamera:@"BACK_FACING_CAMERA" error: &error];do{ try dce.selectCamera("BACK_FACING_CAMERA") }catch{ // Add your code to deal with the exceptions. }
Remarks
- There is always a back-facing camera be defined as a default camera. If the user doesn’t select any camera via
selectCamera, the default camera will be considered as the selected camera. - If there is no opened camera, the method
selectCamerawill not open any camera. - If there is an opened camera and the opened camera’s ID exactly equals the input ID, the method
selectCamerawill make no changes. - If there is an opened camera and the opened camera’s ID is different from the input ID, the method
selectCamerawill close the currently opened camera and then open a new camera by the input ID.
getSelectedCamera
Get the ID of the currently selected camera.
- Objective-C
- Swift
- (NSString*)getSelectedCamera;func getSelectedCamera() -> String
Return Value
The ID of the current selected camera.
Code Snippet
- Objective-C
- Swift
NSString* cameraID = [_dce getSelectedCamera];let selectedCamera = dce.getSelectedCamera()
getCameraState
Get the state of the currently selected camera.
- Objective-C
- Swift
- (EnumCameraState*)getCameraState;func getCameraState() -> EnumCameraState
Return Value
One of the preset camera state in Enumeration EnumCameraState.
Code Snippet
- Objective-C
- Swift
EnumCameraState state = [_dce getCameraState];let cameraState = dce.getCameraState()
open
- Turn on the selected camera if a camera has been selected via
selectCamera. - Turn on the default camera if no camera is selected via
selectCamera.
- Objective-C
- Swift
- (void)open;func open()
Code Snippet
- Objective-C
- Swift
[_dce open];dce.open()
close
- Turn off the selected camera if a camera has been selected via
selectCamera. - Turn off the default camera if no camera is selected via
selectCamera.
- Objective-C
- Swift
- (void)close;func close()
Code Snippet
- Objective-C
- Swift
[_dce close];dce.close()
turnOnTorch
Turn on the torch (if the torch of the mobile device is available).
- Objective-C
- Swift
- (void)turnOnTorch;func turnOnTorch()
Code Snippet
- Objective-C
- Swift
[_dce turnOnTorch];dce.turnOnTorch()
turnOffTorch
Turn off the torch.
- Objective-C
- Swift
- (void)turnOffTorch;func turnOffTorch()
Code Snippet
- Objective-C
- Swift
[_dce turnOffTorch];dce.turnOffTorch()
getFrameRate
Get the current frame rate.
- Objective-C
- Swift
- (NSInteger)getFrameRate;func getFrameRate() -> Int32
Return Value
The current frame rate.
Code Snippet
- Objective-C
- Swift
NSInteger frameRate = [_dce getFrameRate];let frameRate = dce.getFrameRate()
setResolution
Input one of the preset resolution value in Enumeration Resolution. The camera enhancer will try to set the resolution to the target value or the closest available value below the target value.
- Objective-C
- Swift
- (void)setResolution:(EnumResolution)resolution;func setResolution(_ resolution: EnumResolution)
Parameters
resolution: One of the int value that preset in Enumeration EnumResolution.
Code Snippet
- Objective-C
- Swift
[_dce setResolution:EnumRESOLUTION_1080P];dce.setResolution(EnumResolution.EnumRESOLUTION_1080P)
getResolution
Get the current resolution.
- Objective-C
- Swift
- (NSString*)getResolution;func getResolution() -> String
Return Value
The size of the current resolution.
Code Snippet
- Objective-C
- Swift
NSString* resolution = [_dce getResolution];let resolution = dce.getResolution()
setZoom
Set the zoom factor. Once setZoom is triggered and approved, the zoom factor of the activated camera will immediately become the input value.
- Objective-C
- Swift
- (void)setZoom:(CGFloat)factorfunc setZoom(_ factor: CGFloat)
Parameters
factor: The target zoom factor.
Code Snippet
- Objective-C
- Swift
[_dce setZoom:3.0f];dce.setZoom(3.0)
autoZoomRange
The property for getting/setting the range of auto zoom.
- Objective-C
- Swift
@property (nonatomic, assign) UIFloatRange autoZoomRange;var autoZoomRange: UIFloatRange { get set }
Code Snippet
- Objective-C
- Swift
[_dce setAutoZoomRange:UIFloatRangeMake(1.5,4)]; UIFloatRange currentZoomRange = [_dce autoZoomRange];dce.autoZoomRange = UIFloatRange(minimum:1.5, maximum: 4) let currentZoomRange = dce.autoZoomRange()
getMaxZoomFactor
Get the maximum available zoom factor.
- Objective-C
- Swift
- (CGFloat)getMaxZoomFactor;func getMaxZoomFactor() -> CGFloat
Return Value
A CGFloat value that indicates the maximum available zoom factor of the device.
Code Snippet
- Objective-C
- Swift
CGFloat maxZoomFactor = [_dce getMaxZoomFactor];let maxZoomFactor = dce.getMaxZoomFactor()
setFocus
Set the focus position (value range from 0.0f to 1.0f) and trigger a focus at the configured position.
- Objective-C
- Swift
- (void)setFocus:(CGPoint)point;func setFocus(_ point: CGPoint)
Parameters
focusPosition: A CGPoint that stores the x and y coordinate of the targeting focus position.
Code Snippet
- Objective-C
- Swift
CGPoint focusPoint = {0.4, 0.5}; [_dce setFocus:focusPoint];let focusPoint = CGPoint(x:0.4, y:0.5) dce.setFocus(focusPoint)
setFocus(subsequentFocusMode)
Trigger a focus at the targeting point and set the subsequent focus mode after focused.
- Objective-C
- Swift
- (void)setFocus:(CGPoint)focusPoint subsequentFocusMode:(EnumFocusMode)subsequentFocusMode;func setFocus(_ focusPoint: CGPoint, focusMode subsequentFocusMode: EnumFocusMode)
Parameters
[in] focusPosition: A CGPoint indicates the interest area.
[in] subsequentFocusMode: If you set the focus mode to FM_LOCKED, the focallength will be lock after the focus. Otherwise, the continuous auto focus that control by the hardware is still enabled.
Code Snippet
- Objective-C
- Swift
CGPoint focusPoint = {0.4, 0.5}; [_dce setFocus:focusPoint subsequentFocusMode:EnumFocusMode.FM_LOCKED];let focusPoint = CGPoint(x:0.4, y:0.5) dce.setFocus(focusPoint, subsequentFocusMode:EnumFocusMode.FM_LOCKEDD)
setScanRegion
Specify the scanRegion. The DCEFrames will be cropped according to the scanRegion before they are stored in the video buffer.
- Objective-C
- Swift
- (void)setScanRegion:(RegionDefinition)scanRegion error:(NSError * _Nullable)error;func setScanRegion(_ scanRegion: iRegionDefinition?) throws
Parameters
scanRegion: Use a iRegionDefinition value to specify the scan region. The parameter will be optimized to the maximum or minimum available value if the input parameter is out of range. For more information, please view iRegionDefinition.
Code Snippet
- Objective-C
- Swift
iRegionDefinition* scanRegion = [[iRegionDefinition alloc] init]; scanRegion.regionTop = 25; scanRegion.regionBottom = 75; scanRegion.regionLeft = 25; scanRegion.regionRight = 75; scanRegion.regionMeasuredByPercentage = 1 [_dce setScanRegion:scanRegion error: &error];let scanRegion = iRegionDefinition() scanRegion.regionTop = 25 scanRegion.regionBottom = 75 scanRegion.regionLeft = 25 scanRegion.regionRight = 75 scanRegion.regionMeasuredByPercentage = 1 do{ try dce.setScanRegion(scanRegion) }catch{ // Add your code to deal with the exceptions. }
Remarks
- The region definition defines the region on the camera view. For each value of the class
iRegionDefinition:- The
regionTopis the distance between the top of the scan region and the top of the video frame. - The
regionBottomis the distance between the bottom of the scan region and the top of the video frame. - The
regionLeftis the distance between the left of the scan region and the left of the video frame. - The
regionRightis the distance between the right of the scan region and the left of the video frame.
- The
- When you trigger
setScanRegion, the enhancer featureEF_FAST_MODEwill be disabled. - You will still get the original
DCEFramefromFrameOutputCallbackand croppedDCEFramefromgetFrameFromBuffer. ThecropRegionofDCEFramewill be configured based on the scanRegion whensetScanRegionis triggered. - When you trigger
setScanRegion, thescanRegionVisiblewill be set to true automatically. If you don’t want to display the scanRegion on the UI, please set thescanRegionVisibleto false manually.
getScanRegion
Get the current scan region settings.
- Objective-C
- Swift
- (iRegionDefinition) getScanRegionfunc getScanRegion() -> iRegionDefinition?
Return Value
The return value of getScanRegion is always the actual parameter of the scanRegion, which might be different from the user input parameter. If scanRegion is not configured or the method setScanRegion is not approved, the return value will be null.
Code Snippet
- Objective-C
- Swift
iRegionDefinition* myScanRegion = [[iRegionDefinition alloc] init]; myScanRegion = [_dce getScanRegion];let scanRegion = iRegionDefinition() scanRegion = dce.getScanRegion()
scanRegionVisible
Set whether to display the scanRegion on the UI. The default value of the property is false. When the property value is set to true, the scan region will be drawn on the UI. The scanRegion will not be displayed if its value is null.
- Objective-C
- Swift
@property (assign, nonatomic) BOOL scanRegionVisible;var scanRegionVisible: Bool { get set }
setCameraStateListener
Set a DCECameraStateListener to receive notifications when the camera state changes.
- Objective-C
- Swift
- (void) setCameraStateListener:(nonnull id<DCECameraStateListener>)listener;func setCameraStateListener(_ listener: DCECameraStateListener?)
Parameters
[in] listener: A DCECameraStateListener object.
Code Snippet
- Objective-C
- Swift
@interface ViewController ()<DCECameraStateListener> - (void)configurationDCE{ [_dce setCameraStateListener:self]; } - (void)stateChangeCallback:(EnumCameraState)state{ // Add your code to do when camera state changes. }class ViewController: UIViewController,DCECameraStateListener{ func configurationDCE(){ dce.setCameraStateListener(self) } func stateChangeCallback(EnumCameraState currentState){ // Add your code to do when camera state changes. } }
Frame Acquiring Methods Details
getFrameFromBuffer
Get the latest frame from the buffer. The boolean value determines whether the fetched frame will be removed from the buffer.
- Objective-C
- Swift
- (DCEFrame*)getFrameFromBuffer:(BOOL)keep;func getFrameFromBuffer(_ iskeep: Bool) -> DCEFrame
Parameters
Keep: If set to true, the frame will be kept in the video buffer. Otherwise, it will be removed from the video buffer.
Return Value
The latest frame in the video buffer.
Code Snippet
- Objective-C
- Swift
dceFrame = [_dce getFrameFromBuffer:true];let dceFrame = dce.getFrameFromBuffer()
addListener
Add a listener to the CameraEnhancer instance. This method will have no effect if the same listener is already added.
- Objective-C
- Swift
- (void)addListener:(nonnull id<DCEFrameListener>)listener;func addListener(_ listener: DCEFrameListener)
Parameters
listener: An object of DCEFrameListener. Its callback method frameOutputCallback will be available for users to make further operations on the captured video frame.
Code Snippet
- Objective-C
- Swift
[_dce addListener:self];dce.addListener(self)
removeListener
Remove a previously added listener from the CameraEnhancer instance. This method will have no effect if there is no listener exists in CameraEnhancer instance.
- Objective-C
- Swift
- (void)removeListener:(nonnull id<DCEFrameListener>)listener;func removeListener(_ listener: DCEFrameListener)
Parameters
listener: The input listener will be removed from the Camera Enhancer instance.
Code Snippet
- Objective-C
- Swift
[_dce removeListener:self];dce.removeListener(self)
Enhanced Features Methods Details
enableFeatures
Enable camera enhancer features by inputting EnumEnhancerFeatures value.
The EnumEnhancerFeatures members:
| Members | Value |
|---|---|
EnumFRAME_FILTER |
0x01 |
EnumSENSOR_CONTROL |
0x02 |
EnumENHANCED_FOCUS |
0x04 |
EnumFAST_MODE |
0x08 |
EnumAUTO_ZOOM |
0x10 |
EnumSMART_TORCH |
0x20 |
- Objective-C
- Swift
- (void)enableFeatures:(EnumEnhancerFeatures)features error:(NSError * _Nullable * _Nullable)error;func enableFeatures(_ enumEnhancerFeatures: Int) throws
Parameters
enhancerFeatures: The combined value of EnumEnhancerFeatures.
Code Snippet
- Objective-C
- Swift
[_dce enableFeatures:EnumFRAME_FILTER error: &error];do{ try dce.enableFeatures(EnumEnhancerFeature.EnumFRAME_FILTER.rawValue) }catch{ // Add your code to deal with the exceptions. }
Remarks
The enable action will not be approved if the license is invalid. If your input values include the features that have been already enabled, these features will keep the enabled status.
disableFeatures
Disable camera enhancer features by inputting EnumEnhancerFeatures values.
- Objective-C
- Swift
- (void)disableFeatures:(EnumEnhancerFeatures)features;func disableFeatures(_ enumEnhancerFeatures: Int)
Parameters
enhancerFeatures: The combined value of EnumEnhancerFeatures.
Code Snippet
- Objective-C
- Swift
[_dce disableFeatures:EnumFRAME_FILTER];dce.disableFeatures(EnumEnhancerFeature.EnumFRAME_FILTER.rawValue)
Remarks
You can still disable the features even if the license is invalid. If your input values include the features that are not enabled, these features will keep the disabled status.
isFeatureEnabled
Check whether the input features are enabled.
- Objective-C
- Swift
- (BOOL)isFeatureEnabled:(EnumEnhancerFeatures)features;func isFeatureEnabled(_ enumEnhancerFeatures: Int) -> Bool
Parameters
enhancerFeatures: The combined value of EnumEnhancerFeatures.
Return Value
A BOOL value refers to whether all the features you input are enabled.
True: All the features you input are enabled.False: There is at least one feature is not enabled among your input values.
Code Snippet
- Objective-C
- Swift
BOOL featureEnabled = [_dce isFeatureEnabled:EnumFRAME_FILTER];let featureEnabled = dce.isFeatureEnabled(EnumEnhancerFeature.EnumFRAME_FILTER.rawValue)
Remarks
If the features you input are all enabled but don’t cover all the enabled features, this method will still return true.
Advanced Camera Control Methods Details
updateAdvancedSettingsFromFile
Update the advanced camera controlling and video streaming processing parameters. This method enables you to update settings via a JSON file from the storage.
- Objective-C
- Swift
- (BOOL)updateAdvancedSettingsFromFile:(NSString*)filePath error:(NSError * _Nullable * _Nullable)error NS_SWIFT_NAME(updateAdvancedSettingsFromFile(_:));func updateAdvancedSettingsFromFile(_ filePath: String) throws
Parameters
filePath: The file path of the JSON file.
Code Snippet
- Objective-C
- Swift
[_dce updateAdvancedSettingsFromFile:@"Put your JSON file path here." error: &error];do{ try dce.updateAdvancedSettingsFromFile("Put your JSON file path here.") }catch{ // Add your code to deal with the exceptions. }
Remarks
You might need permission authority to enable the Camera Enhancer to read the file in your mobile storage.
updateAdvancedSettingsFromString
Update the advanced camera controlling and video streaming processing parameters. This method enables you to update settings via a JSON string.
- Objective-C
- Swift
- (BOOL)updateAdvancedSettingsFromString:(NSString*)JsonString error:(NSError * _Nullable * _Nullable)error;func updateAdvancedSettingsFromString(_ JsonString: String) throws
Parameters
jsonString: A stringified JSON data.
Code Snippet
- Objective-C
- Swift
[_dce updateAdvancedSettingsFromString:@"Put your stringified JSON data here." error: &error];do{ try dce.updateAdvancedSettingsFromString("Put your stringified JSON data here.") }catch{ // Add your code to deal with the exceptions. }