capawesome-team / capacitor-mlkit

⚡️ ML Kit plugins for Capacitor. Supports Android and iOS.
https://capawesome.io/plugins/mlkit/
Apache License 2.0
144 stars 40 forks source link

feat(barcode-scanning): zoom functionality #72

Closed Melynt3 closed 9 months ago

Melynt3 commented 1 year ago

Plugin(s)

Current problem

Hi,

I asked about this a few days ago in a different topic, but I would like to officially request a new feature, which is zoom functionality. It's a big challenge to work with small barcodes. I encountered a problem when scanning small CODE128 codes; basically, the scanner does not read them. I was able to hardcode a workaround in the library itself by adding a zoom of 1.6f during camera initialization, but this is only a temporary solution. It would be a great feature that would make the library even more attractive.

Preferred solution

Adding a zoom based on the google barcode scanner, which is implemented in the demo version either zoom by "enlarging the screen" or by adding a slider

Alternative options

While working on react library i occured this kind of zoom which was very intuitive and it was known to be there. 1 (3)

Additional context

No response

sephallen commented 12 months ago

Having the ability to set the zoom level on initialisation would be very useful.

I am also experiencing similar issues with small CODE39 barcodes, the library is not able to read the value unless you pinch to zoom around 200%.

Melynt3 commented 12 months ago

Yup, i occured the same error with different type.

i temporary fixed it by setting zoom lvl to 1.65 ratio in library from android studio, if u have more efficient way to manage it i would be greatful.

CameraControl cameraControl = camera.getCameraControl();
float zoomLevel = 1.65f;
cameraControl.setZoomRatio(zoomLevel);
robingenz commented 12 months ago

PRs are welcome. I propose these types:

  /**
   * Set the zoom ratio of the camera.
   * 
   * Only available on Android and iOS.
   */
  setZoomRatio(options: SetZoomRatioOptions): Promise<void>;
  /**
   * Get the zoom ratio of the camera.
   * 
   * Only available on Android and iOS.
   */
  getZoomRatio(): Promise<GetZoomRatioResult>;
  /**
   * Get the minimum zoom ratio of the camera.
   * 
   * Only available on Android and iOS.
   */
  getMinZoomRatio(): Promise<GetMinZoomRatioResult>;
  /**
   * Get the maximum zoom ratio of the camera.
   * 
   * Only available on Android and iOS.
   */
  getMaxZoomRatio(): Promise<GetMaxZoomRatioResult>;

Docs:

Edit:

vosecek commented 9 months ago

Hi, any chance this task could be implemented?

robingenz commented 9 months ago

@vosecek Sure, but there is no ETA yet. Here you can find information on how to speed up the process.

vosecek commented 9 months ago

@robingenz what is appropriate price/bounty for implementation?

robingenz commented 9 months ago

@vosecek You can set any amount. Just take care of the minimum and maximum amount (see FAQ).

vosecek commented 9 months ago

@robingenz Contribution 200$ sent https://opencollective.com/capawesome/contributions/720755

robingenz commented 9 months ago

@vosecek Thank you for your contribution! I will prioritize the issue.

robingenz commented 9 months ago

I’ve just published a dev version, see https://github.com/capawesome-team/capacitor-mlkit/pull/112#issuecomment-1865041507. Feel free to give it a try. I would appreciate any feedback.

vosecek commented 9 months ago

I’ve just published a dev version, see #112 (comment). Feel free to give it a try. I would appreciate any feedback.

Works great, thanks!

ion-range is not handy component for this, cause zoom is needed only 2x-4x, using sliding range is difficult to set useful zoom ratio.

My implementation for controls is

<ion-fab slot="fixed" horizontal="end" vertical="center">
        <ion-fab-button (click)="increaseZoom()" [disabled]="currentZoomRatio >= maxZoomRatio" class="ion-margin-bottom" [color]="'primary'">
            <ion-icon size="large" name="search-outline"></ion-icon>
        </ion-fab-button>
        <ion-fab-button (click)="decreaseZoom()" [disabled]="currentZoomRatio <= minZoomRatio" [color]="'dark'">
            <ion-icon size="small" name="search-outline"></ion-icon>
        </ion-fab-button>
    </ion-fab>
// set this.currentZoomRatio on init
increaseZoom() {
    // @ts-ignore
    this.setZoomRatio({detail: {value: this.currentZoomRatio + 1}});
  }

  decreaseZoom() {
    // @ts-ignore
    this.setZoomRatio({detail: {value: this.currentZoomRatio - 1}});
  }

public setZoomRatio(event: InputCustomEvent): void {
    if (!event.detail.value) {
      return;
    }
    BarcodeScanner.setZoomRatio({
      zoomRatio: parseInt(event.detail.value as any, 10),
    }).then(() => {
      BarcodeScanner.getZoomRatio().then(r => {
        this.currentZoomRatio = r.zoomRatio;
      });
    }, err => {
      console.log(err);
    });
  }

This is just my suggestion for demo code. Anyway, this is great and fulfil our needs.