Showing
4 changed files
with
29 additions
and
2 deletions
| @@ -143,12 +143,20 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | @@ -143,12 +143,20 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | ||
| 143 | val imageWidth = inputImage.getWidth(); | 143 | val imageWidth = inputImage.getWidth(); |
| 144 | val imageHeight = inputImage.getHeight(); | 144 | val imageHeight = inputImage.getHeight(); |
| 145 | 145 | ||
| 146 | + println(inputImage.getWidth()) | ||
| 147 | + println(inputImage.getHeight()) | ||
| 148 | + | ||
| 149 | + println(barcodeBoundingBox) | ||
| 150 | + | ||
| 146 | val left = (scanWindow[0] * imageWidth).roundToInt() | 151 | val left = (scanWindow[0] * imageWidth).roundToInt() |
| 147 | val top = (scanWindow[1] * imageHeight).roundToInt() | 152 | val top = (scanWindow[1] * imageHeight).roundToInt() |
| 148 | val right = (scanWindow[2] * imageWidth).roundToInt() | 153 | val right = (scanWindow[2] * imageWidth).roundToInt() |
| 149 | val bottom = (scanWindow[3] * imageHeight).roundToInt() | 154 | val bottom = (scanWindow[3] * imageHeight).roundToInt() |
| 150 | 155 | ||
| 151 | val scaledScanWindow = Rect(left, top, right, bottom) | 156 | val scaledScanWindow = Rect(left, top, right, bottom) |
| 157 | + println(scaledScanWindow) | ||
| 158 | + | ||
| 159 | + println("-------------------------") | ||
| 152 | return scaledScanWindow.contains(barcodeBoundingBox) | 160 | return scaledScanWindow.contains(barcodeBoundingBox) |
| 153 | } | 161 | } |
| 154 | 162 | ||
| @@ -227,6 +235,8 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | @@ -227,6 +235,8 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | ||
| 227 | 235 | ||
| 228 | val analysisSize = analysis.resolutionInfo?.resolution ?: Size(0, 0) | 236 | val analysisSize = analysis.resolutionInfo?.resolution ?: Size(0, 0) |
| 229 | val previewSize = preview!!.resolutionInfo?.resolution ?: Size(0, 0) | 237 | val previewSize = preview!!.resolutionInfo?.resolution ?: Size(0, 0) |
| 238 | + | ||
| 239 | + | ||
| 230 | Log.i("LOG", "Analyzer: $analysisSize") | 240 | Log.i("LOG", "Analyzer: $analysisSize") |
| 231 | Log.i("LOG", "Preview: $previewSize") | 241 | Log.i("LOG", "Preview: $previewSize") |
| 232 | 242 |
| @@ -18,6 +18,12 @@ class _BarcodeScannerWithScanWindowState | @@ -18,6 +18,12 @@ class _BarcodeScannerWithScanWindowState | ||
| 18 | void initState() { | 18 | void initState() { |
| 19 | super.initState(); | 19 | super.initState(); |
| 20 | controller = MobileScannerController(); | 20 | controller = MobileScannerController(); |
| 21 | + restart(); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + Future<void> restart() async { | ||
| 25 | + await controller.stop(); | ||
| 26 | + await controller.start(); | ||
| 21 | } | 27 | } |
| 22 | 28 | ||
| 23 | @override | 29 | @override |
| @@ -89,6 +89,7 @@ class _MobileScannerState extends State<MobileScanner> | @@ -89,6 +89,7 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 89 | Size textureSize, | 89 | Size textureSize, |
| 90 | Size widgetSize, | 90 | Size widgetSize, |
| 91 | ) { | 91 | ) { |
| 92 | + | ||
| 92 | /// map the texture size to get its new size after fitted to screen | 93 | /// map the texture size to get its new size after fitted to screen |
| 93 | final fittedSizes = applyBoxFit(fit, textureSize, widgetSize); | 94 | final fittedSizes = applyBoxFit(fit, textureSize, widgetSize); |
| 94 | final fittedTextureSize = fittedSizes.destination; | 95 | final fittedTextureSize = fittedSizes.destination; |
| @@ -103,6 +104,7 @@ class _MobileScannerState extends State<MobileScanner> | @@ -103,6 +104,7 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 103 | /// create a new scan window and with only the area of the rect intersecting the texture window | 104 | /// create a new scan window and with only the area of the rect intersecting the texture window |
| 104 | final scanWindowInTexture = scanWindow.intersect(textureWindow); | 105 | final scanWindowInTexture = scanWindow.intersect(textureWindow); |
| 105 | 106 | ||
| 107 | + | ||
| 106 | /// update the scanWindow left and top to be relative to the texture not the widget | 108 | /// update the scanWindow left and top to be relative to the texture not the widget |
| 107 | final newLeft = scanWindowInTexture.left - textureWindow.left; | 109 | final newLeft = scanWindowInTexture.left - textureWindow.left; |
| 108 | final newTop = scanWindowInTexture.top - textureWindow.top; | 110 | final newTop = scanWindowInTexture.top - textureWindow.top; |
| @@ -112,17 +114,26 @@ class _MobileScannerState extends State<MobileScanner> | @@ -112,17 +114,26 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 112 | /// new scanWindow that is adapted to the boxfit and relative to the texture | 114 | /// new scanWindow that is adapted to the boxfit and relative to the texture |
| 113 | final windowInTexture = Rect.fromLTWH(newLeft, newTop, newWidth, newHeight); | 115 | final windowInTexture = Rect.fromLTWH(newLeft, newTop, newWidth, newHeight); |
| 114 | 116 | ||
| 117 | + print(windowInTexture); | ||
| 118 | + | ||
| 115 | /// get the scanWindow as a percentage of the texture | 119 | /// get the scanWindow as a percentage of the texture |
| 116 | final percentageLeft = windowInTexture.left / fittedTextureSize.width; | 120 | final percentageLeft = windowInTexture.left / fittedTextureSize.width; |
| 117 | final percentageTop = windowInTexture.top / fittedTextureSize.height; | 121 | final percentageTop = windowInTexture.top / fittedTextureSize.height; |
| 118 | final percentageRight = windowInTexture.right / fittedTextureSize.width; | 122 | final percentageRight = windowInTexture.right / fittedTextureSize.width; |
| 119 | final percentagebottom = windowInTexture.bottom / fittedTextureSize.height; | 123 | final percentagebottom = windowInTexture.bottom / fittedTextureSize.height; |
| 120 | 124 | ||
| 125 | + print(Rect.fromLTRB( | ||
| 126 | + percentageLeft, | ||
| 127 | + percentageTop, | ||
| 128 | + percentageRight, | ||
| 129 | + percentagebottom, | ||
| 130 | + )); | ||
| 131 | + | ||
| 121 | /// this rectangle can be send to native code and used to cut out a rectangle of the scan image | 132 | /// this rectangle can be send to native code and used to cut out a rectangle of the scan image |
| 122 | return Rect.fromLTRB( | 133 | return Rect.fromLTRB( |
| 123 | percentageLeft, | 134 | percentageLeft, |
| 124 | - percentageRight, | ||
| 125 | percentageTop, | 135 | percentageTop, |
| 136 | + percentageRight, | ||
| 126 | percentagebottom, | 137 | percentagebottom, |
| 127 | ); | 138 | ); |
| 128 | } | 139 | } |
| @@ -294,7 +294,7 @@ class MobileScannerController { | @@ -294,7 +294,7 @@ class MobileScannerController { | ||
| 294 | 294 | ||
| 295 | /// updates the native scanwindow | 295 | /// updates the native scanwindow |
| 296 | Future<void> updateScanWindow(Rect window) async { | 296 | Future<void> updateScanWindow(Rect window) async { |
| 297 | - final data = [window.left, window.right, window.top, window.bottom]; | 297 | + final data = [window.left, window.top, window.right, window.bottom]; |
| 298 | await methodChannel.invokeMethod('updateScanWindow', {'rect': data}); | 298 | await methodChannel.invokeMethod('updateScanWindow', {'rect': data}); |
| 299 | } | 299 | } |
| 300 | } | 300 | } |
-
Please register or login to post a comment