casvanluijtelaar

bugfixes

... ... @@ -143,12 +143,20 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:
val imageWidth = inputImage.getWidth();
val imageHeight = inputImage.getHeight();
println(inputImage.getWidth())
println(inputImage.getHeight())
println(barcodeBoundingBox)
val left = (scanWindow[0] * imageWidth).roundToInt()
val top = (scanWindow[1] * imageHeight).roundToInt()
val right = (scanWindow[2] * imageWidth).roundToInt()
val bottom = (scanWindow[3] * imageHeight).roundToInt()
val scaledScanWindow = Rect(left, top, right, bottom)
println(scaledScanWindow)
println("-------------------------")
return scaledScanWindow.contains(barcodeBoundingBox)
}
... ... @@ -227,6 +235,8 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:
val analysisSize = analysis.resolutionInfo?.resolution ?: Size(0, 0)
val previewSize = preview!!.resolutionInfo?.resolution ?: Size(0, 0)
Log.i("LOG", "Analyzer: $analysisSize")
Log.i("LOG", "Preview: $previewSize")
... ...
... ... @@ -18,6 +18,12 @@ class _BarcodeScannerWithScanWindowState
void initState() {
super.initState();
controller = MobileScannerController();
restart();
}
Future<void> restart() async {
await controller.stop();
await controller.start();
}
@override
... ...
... ... @@ -89,6 +89,7 @@ class _MobileScannerState extends State<MobileScanner>
Size textureSize,
Size widgetSize,
) {
/// map the texture size to get its new size after fitted to screen
final fittedSizes = applyBoxFit(fit, textureSize, widgetSize);
final fittedTextureSize = fittedSizes.destination;
... ... @@ -103,6 +104,7 @@ class _MobileScannerState extends State<MobileScanner>
/// create a new scan window and with only the area of the rect intersecting the texture window
final scanWindowInTexture = scanWindow.intersect(textureWindow);
/// update the scanWindow left and top to be relative to the texture not the widget
final newLeft = scanWindowInTexture.left - textureWindow.left;
final newTop = scanWindowInTexture.top - textureWindow.top;
... ... @@ -112,17 +114,26 @@ class _MobileScannerState extends State<MobileScanner>
/// new scanWindow that is adapted to the boxfit and relative to the texture
final windowInTexture = Rect.fromLTWH(newLeft, newTop, newWidth, newHeight);
print(windowInTexture);
/// get the scanWindow as a percentage of the texture
final percentageLeft = windowInTexture.left / fittedTextureSize.width;
final percentageTop = windowInTexture.top / fittedTextureSize.height;
final percentageRight = windowInTexture.right / fittedTextureSize.width;
final percentagebottom = windowInTexture.bottom / fittedTextureSize.height;
print(Rect.fromLTRB(
percentageLeft,
percentageTop,
percentageRight,
percentagebottom,
));
/// this rectangle can be send to native code and used to cut out a rectangle of the scan image
return Rect.fromLTRB(
percentageLeft,
percentageRight,
percentageTop,
percentageRight,
percentagebottom,
);
}
... ...
... ... @@ -294,7 +294,7 @@ class MobileScannerController {
/// updates the native scanwindow
Future<void> updateScanWindow(Rect window) async {
final data = [window.left, window.right, window.top, window.bottom];
final data = [window.left, window.top, window.right, window.bottom];
await methodChannel.invokeMethod('updateScanWindow', {'rect': data});
}
}
... ...