|
| 1 | +--- |
| 2 | +layout: default-layout |
| 3 | +title: Camera Control - Dynamsoft Barcode Reader Android |
| 4 | +description: Learn how to control the camera for Dynamsoft Barcode Reader Android, including zoom, focus and other features. |
| 5 | +keywords: camera, Android, auto-zoom, zoom, auto-focus, focus, enhanced features |
| 6 | +needAutoGenerateSidebar: true |
| 7 | +needGenerateH3Content: true |
| 8 | +noTitleIndex: true |
| 9 | +--- |
| 10 | + |
| 11 | +# Camera Control |
| 12 | + |
| 13 | +This page introduces the main camera control features available in Dynamsoft Barcode Reader for Android. It explains how to manage focus behavior, configure zoom for small or distant barcodes, and enable additional camera enhancement features to improve scanning performance in specific scenarios. |
| 14 | + |
| 15 | +## Focus Control & Focus Modes |
| 16 | + |
| 17 | +In most cases, the camera automatically determines when focus is needed and adjusts the focal length accordingly. This behavior is called continuous auto-focus. In addition, the camera view supports tap-to-focus, which allows the user to trigger auto-focus manually. When these default focus behaviors do not meet your requirements, you can use the methods described in this page to control focus more precisely. |
| 18 | + |
| 19 | +### Trigger an Auto-Focus |
| 20 | + |
| 21 | +Use the following code to trigger auto-focus: |
| 22 | + |
| 23 | +<div class="sample-code-prefix"></div> |
| 24 | +>- Java |
| 25 | +>- Kotlin |
| 26 | +> |
| 27 | +>1. |
| 28 | +```java |
| 29 | +mCamera.setFocus(new PointF(0.5f,0.5f)); |
| 30 | +``` |
| 31 | +2. |
| 32 | +```kotlin |
| 33 | +cameraEnhancer.setFocus(PointF(0.5f,0.5f)) |
| 34 | +``` |
| 35 | + |
| 36 | +Optionally, you can specify the focus mode when triggering auto-focus. |
| 37 | + |
| 38 | +- FM_LOCKED: Lock the focal-length after this focus. |
| 39 | +- FM_CONTINUOUS_AUTO: Allow the camera to adjust the focal-length automatically after this focus. |
| 40 | + |
| 41 | +<div class="sample-code-prefix"></div> |
| 42 | +>- Java |
| 43 | +>- Kotlin |
| 44 | +> |
| 45 | +>1. |
| 46 | +```java |
| 47 | +mCamera.setFocus(new PointF(0.5f,0.5f), EnumFocusMode.FM_LOCKED); |
| 48 | +mCamera.setFocus(new PointF(0.5f,0.5f), EnumFocusMode.FM_CONTINUOUS_AUTO); |
| 49 | +``` |
| 50 | +2. |
| 51 | +```kotlin |
| 52 | +cameraEnhancer.setFocus(PointF(0.5f,0.5f), EnumFocusMode.FM_CONTINUOUS_AUTO) |
| 53 | +cameraEnhancer.setFocus(PointF(0.5f,0.5f), EnumFocusMode.FM_LOCKED) |
| 54 | +``` |
| 55 | + |
| 56 | +### Enhanced Focus |
| 57 | + |
| 58 | +Use this feature if your device has difficulty focusing. |
| 59 | + |
| 60 | +<div class="sample-code-prefix"></div> |
| 61 | +>- Java |
| 62 | +>- Kotlin |
| 63 | +> |
| 64 | +>1. |
| 65 | +```java |
| 66 | +CameraEnhancer mCamera = new CameraEnhancer(this); |
| 67 | +try { |
| 68 | + mCamera.enableEnhancedFeatures(EnumEnhancerFeatures.EF_ENHANCED_FOCUS); |
| 69 | +} catch (CameraEnhancerException e) { |
| 70 | + throw new RuntimeException(e); |
| 71 | +} |
| 72 | +``` |
| 73 | +2. |
| 74 | +```kotlin |
| 75 | +val mCamera = CameraEnhancer(this) |
| 76 | +mCamera.enableEnhancedFeatures(EnumEnhancerFeatures.EF_ENHANCED_FOCUS) |
| 77 | +``` |
| 78 | + |
| 79 | +**Related API** |
| 80 | + |
| 81 | +- [`enableEnhancedFeatures`]({{ site.dce_android }}primary-api/camera-enhancer.html#enableenhancedfeatures) |
| 82 | + |
| 83 | +## Auto-Zoom & Zoom Factor |
| 84 | + |
| 85 | +Zoom control is commonly used when processing small barcodes or scanning from a long distance. There are two zoom control features: |
| 86 | + |
| 87 | +- Auto-zoom: Lets the library determine whether to zoom in. |
| 88 | +- Zoom factor: Lets you set the zoom factor directly. This is commonly used when focusing on small barcodes. |
| 89 | + |
| 90 | +### Auto Zoom |
| 91 | + |
| 92 | +If your application mainly scans barcodes at a normal distance but also needs to recognize barcodes that are farther away, enabling auto-zoom is recommended. |
| 93 | + |
| 94 | +<div align="center"> |
| 95 | + <p><img src="../../../assets/auto-zoom.gif" width="30%" alt="auto-zoom"></p> |
| 96 | + <p>Auto Zoom</p> |
| 97 | +</div> |
| 98 | + |
| 99 | +<div class="sample-code-prefix"></div> |
| 100 | +>- Java |
| 101 | +>- Kotlin |
| 102 | +> |
| 103 | +>1. |
| 104 | +```java |
| 105 | +CameraEnhancer mCamera = new CameraEnhancer(this); |
| 106 | +try { |
| 107 | + mCamera.enableEnhancedFeatures(EnumEnhancerFeatures.EF_AUTO_ZOOM); |
| 108 | +} catch (CameraEnhancerException e) { |
| 109 | + throw new RuntimeException(e); |
| 110 | +} |
| 111 | +``` |
| 112 | +2. |
| 113 | +```kotlin |
| 114 | +val mCamera = CameraEnhancer(this) |
| 115 | +mCamera.enableEnhancedFeatures(EnumEnhancerFeatures.EF_AUTO_ZOOM) |
| 116 | +``` |
| 117 | + |
| 118 | +**Related API** |
| 119 | + |
| 120 | +- [`enableEnhancedFeatures`]({{ site.dce_android }}primary-api/camera-enhancer.html#enableenhancedfeatures) |
| 121 | + |
| 122 | +### Zoom Factor |
| 123 | + |
| 124 | +If your application mainly targets small barcodes or barcodes that are far from the camera, it is recommended to control the zoom factor directly. |
| 125 | + |
| 126 | +<div class="sample-code-prefix"></div> |
| 127 | +>- Java |
| 128 | +>- Kotlin |
| 129 | +> |
| 130 | +>1. |
| 131 | +```java |
| 132 | +CameraEnhancer mCamera = new CameraEnhancer(this); |
| 133 | +mCamera.setZoomFactor(2.0f); |
| 134 | +``` |
| 135 | +2. |
| 136 | +```kotlin |
| 137 | +val mCamera = CameraEnhancer(this) |
| 138 | +mCamera.zoomFactor = 2.0f |
| 139 | +``` |
| 140 | + |
| 141 | +**Related API** |
| 142 | + |
| 143 | +- [`setZoomFactor`]({{ site.dce_android }}primary-api/camera-enhancer.html#setzoomfactor) |
| 144 | + |
| 145 | +## Enhanced Features |
| 146 | + |
| 147 | +| Feature | Description | |
| 148 | +| ------- | ----------- | |
| 149 | +| EF_FRAME_FILTER | Filters blurry video frames using algorithm-based processing. It is usually unnecessary for standard barcode scanning unless you are facing significant accuracy issues. | |
| 150 | +| EF_SENSOR_CONTROL | Filters video frames captured while the device is moving based on sensor data. It is usually unnecessary for standard barcode scanning unless you are facing significant accuracy issues. | |
| 151 | +| EF_ENHANCED_FOCUS | Improves autofocus performance on older devices. If you enable this feature, it is recommended to use it only on older devices, as it may have a negative effect on cameras whose autofocus already works well. | |
| 152 | +| EF_AUTO_ZOOM | Automatically zooms in to recognize barcodes that are far from the camera. | |
| 153 | +| EF_SMART_TORCH | Provides a smart torch button prompt. When lighting conditions are poor, the torch button appears automatically. | |
0 commit comments