Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Zoom not working #10

Open
Raviteja11122 opened this issue Nov 12, 2024 · 10 comments
Open

Auto Zoom not working #10

Raviteja11122 opened this issue Nov 12, 2024 · 10 comments

Comments

@Raviteja11122
Copy link

I've enabled auto zoom feature by using below line but it's not working

await _cameraEnhancer?.enableEnhancedFeatures(EnumEnhancedFeatures.EF_AUTO_ZOOM);

@elementlo
Copy link
Contributor

Which platform do you run into? What do you mean by "not working"? Please describe your problem with more details.

@Raviteja11122
Copy link
Author

Both android and iOS. In recent v 1.3.0 we got new feature
to enable auto zoom by using this method enableEnhancedFeatures after doing this also it's not working.

@elementlo
Copy link
Contributor

The "auto-zoom" feature means when you get close to a barcode with your device camera, AND the barcode is not decoded, the SDK will try to zoom in the lens to make the barcode bigger then try it a second time.
So is there any unexpected situation in this scenario? If there is, please attach a recording video and your code.

@Raviteja11122
Copy link
Author

Expected

Screen_Recording_20241114_121958_Barcode.Scanner.X.1.1.mp4
class QRScannerScreen extends StatefulWidget {
  QRScannerScreen({Key? key}) : super(key: key);

  @override
  State<QRScannerScreen> createState() => _BarcodeScannerState();
}

class _BarcodeScannerState extends State<QRScannerScreen>
    with WidgetsBindingObserver {
  late final DCVCameraEnhancer _cameraEnhancer;
  late final DCVBarcodeReader _barcodeReader;

  final DCVCameraView _cameraView = DCVCameraView();

  List<BarcodeResult> decodeRes = [];
  String? resultText;
  String? base64ResultText;
  bool faceLens = false;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance?.addObserver(this);
    _sdkInit();
  }

  @override
  void dispose() {
    WidgetsBinding.instance?.removeObserver(this);
    _cameraEnhancer.close();
    _barcodeReader.stopScanning();
    super.dispose();
  }

  void _sdkInit() async {
    // Create a barcode reader instance.
    _barcodeReader = await DCVBarcodeReader.createInstance();
    _cameraEnhancer = await DCVCameraEnhancer.createInstance();

    // Get the current runtime settings of the barcode reader.
    DBRRuntimeSettings currentSettings =
    await _barcodeReader.getRuntimeSettings();
    // Set the barcode format to read.
    currentSettings.barcodeFormatIds = EnumBarcodeFormat.BF_ONED | EnumBarcodeFormat.BF_QR_CODE;

    await _cameraEnhancer?.enableEnhancedFeatures(EnumEnhancedFeatures.EF_AUTO_ZOOM);

    // currentSettings.minResultConfidence = 70;
    // currentSettings.minBarcodeTextLength = 50;

    // Set the expected barcode count to 0 when you are not sure how many barcodes you are scanning.
    // Set the expected barcode count to 1 can maximize the barcode decoding speed.
    currentSettings.expectedBarcodeCount = 0;
    // Apply the new runtime settings to the barcode reader.
    await _barcodeReader
        .updateRuntimeSettingsFromTemplate(EnumDBRPresetTemplate.DEFAULT);
    await _barcodeReader.updateRuntimeSettings(currentSettings);

    // Define the scan region.
    _cameraEnhancer.setScanRegion(Region(
        regionTop: 30,
        regionLeft: 15,
        regionBottom: 70,
        regionRight: 85,
        regionMeasuredByPercentage: 1));

    // Enable barcode overlay visiblity.
    _cameraView.overlayVisible = true;

    _cameraView.torchButton = TorchButton(
      visible: true,
    );

    await _barcodeReader.enableResultVerification(true);

    // Stream listener to handle callback when barcode result is returned.
    _barcodeReader.receiveResultStream().listen((List<BarcodeResult>? res) {
      if (mounted) {
        if (res != null && res.length > 0) {
          
        }

        setState(() {
          decodeRes = res ?? [];
        });
      }
    });

    await _cameraEnhancer.open();

    // Enable video barcode scanning.
    // If the camera is opened, the barcode reader will start the barcode decoding thread when you triggered the startScanning.
    // The barcode reader will scan the barcodes continuously before you trigger stopScanning.
    _barcodeReader.startScanning();
  }

  /// Get listItem
  Widget listItem(BuildContext context, int index) {
    BarcodeResult res = decodeRes[index];

    return ListTileTheme(
        textColor: Colors.white,
        // tileColor: Colors.green,
        child: ListTile(
          title: Text(res.barcodeFormatString),
          subtitle: Text(res.barcodeText),
        ));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Barcode Scanner'),
        ),
        body: Stack(
          children: [
            Container(
              child: _cameraView,
            ),
            Container(
              height: 100,
              child: ListView.builder(
                itemBuilder: listItem,
                itemCount: decodeRes.length,
              ),
            ),
            Positioned(
              top: 150,
              left: 25,
              child: GestureDetector(
                onTap: () {
                  faceLens = !faceLens;
                  _cameraEnhancer.selectCamera(faceLens
                      ? EnumCameraPosition.CP_FRONT
                      : EnumCameraPosition.CP_BACK);
                },
                child: Image.asset(
                  'assets/toggle_lens.png',
                  width: 48,
                  height: 48,
                ),
              ),
            ),
          ],
        ));
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);

    switch (state) {
      case AppLifecycleState.resumed:
        _barcodeReader.startScanning();
        _cameraEnhancer.open();
        break;
      case AppLifecycleState.inactive:
        _cameraEnhancer.close();
        _barcodeReader.stopScanning();
        break;
      case AppLifecycleState.detached:
      case AppLifecycleState.hidden:
      case AppLifecycleState.paused:
        break;
    }
  }
}

@Dynamsoft-Henry
Copy link
Collaborator

Hi @Raviteja11122

The auto-zoom feature is designed to zoom-in to close-up to the barcode zone. How to trigger the auto-zoom:

  1. There is a barcode in the camera.
  2. There is something looks like a barcode in the camera.

You might see the auto-zoom is triggered sometimes when there doesn't exist a barcode. That's because the algorithm might mis-localize something else as a barcode.

@Raviteja11122
Copy link
Author

Raviteja11122 commented Nov 14, 2024

@Dynamsoft-Henry ,

I've tried placing the barcode in the scan region even though it's not working.

Note: I tried dynamsoft mobile app from playstore. There is no need of the barcode in the camera to trigger auto zoom. You can try it out.

Is there anything else to add in code or anything to enable at license level?

@elementlo
Copy link
Contributor

I copied your code into a Flutter project and run. All things work fine. Be sure you are not using any API about "setAutoZoomRange()" or other controls of the camera zooming.

4_1731648637.mp4

@Raviteja11122
Copy link
Author

Raviteja11122 commented Nov 15, 2024

@elementlo ,

It is taking more than 10 secs to auto zoom. I'll try again placing the barcode in scan region.

Thankyou.

@Raviteja11122
Copy link
Author

@Dynamsoft-Henry ,

I tried all possible cases where the library could auto-zoom to the barcode. None of them worked. Definately the library algorithm needs improvement.

@Dynamsoft-Henry
Copy link
Collaborator

Hi @Raviteja11122
May I have a look of your license key? The auto-zoom feature requires a valid license to work. Since we can auto zoom on our devices, I guess there is something wrong with your key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants