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

detects there's no barcode #1211

Open
jameschristianw opened this issue Oct 10, 2024 · 5 comments
Open

detects there's no barcode #1211

jameschristianw opened this issue Oct 10, 2024 · 5 comments

Comments

@jameschristianw
Copy link

ondetect runs when there's a barcode. how to tell if there's no barcode?

@navaronbracke
Copy link
Collaborator

navaronbracke commented Oct 11, 2024

We could make onDetect return a nullable BarcodeCapture. The barcodes stream does also not report events when an image frame has no barcode I think. (because that would be expensive, you'd have to send events every frame)

I'm curious about your use case, though? How would you handle this with a continuous stream of images frames that all might not contain barcodes?

@jameschristianw
Copy link
Author

i agree that would be expensive.
to be fair, i still don't know how to handle the continuous stream of image
so what i'm doing right now is save detected barcode to a temp variable, pausing subscription, do something with the barcode, remove the detecte barcode from temp variable, resume subs

i have a suggestion, i don't know if this is feasible or not, can you add new function to controller to detect current frame

@navaronbracke
Copy link
Collaborator

Pausing the subscription when a barcode is received is the correct way to handle things here.

What do you mean with "detect current frame" ? The scanner continuously uses the frames as they come in for detection, so I do not see how that is different from "detect the current frame" ?

@Andrflor
Copy link

Andrflor commented Oct 29, 2024

We could make onDetect return a nullable BarcodeCapture. The barcodes stream does also not report events when an image frame has no barcode I think. (because that would be expensive, you'd have to send events every frame)

I'm curious about your use case, though? How would you handle this with a continuous stream of images frames that all might not contain barcodes?

The thing is that you may want to do continuous detection
For example overlay the barcodes detected with a rectangle and maybe also show some info or action either like android qrcode scanner or with augmented reality of some form.

To do that i use a workaround by adding an empty capture on timeout.

Stream<T> addTimeoutEvent<T>(
    Stream<T> stream, Duration timeout, T timeoutEvent) {
  final StreamController<T> controller = StreamController<T>();

  Timer? timer;
  void resetTimer() {
    timer?.cancel();
    timer = Timer(timeout, () {
      controller.add(timeoutEvent);
      resetTimer();
    });
  }

  stream.listen(
    (T event) {
      resetTimer();
      controller.add(event);
    },
    onError: controller.addError,
    onDone: controller.close,
  );

  return controller.stream;
}

@navaronbracke
Copy link
Collaborator

I think we will need to expose this in the plugin itself, as we now have an extra use-case:

In the upcoming version 7.0.0 of the plugin, we provided a widget that draws the barcode shapes on the screen.
However, that widget will need to know when there are no more barcodes in view, to clear the old shapes.

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