Closed SoundConception closed 2 years ago
It appears slower devices are more sensitive to this issue. Perhaps this suggests some sort of race condition is occuring?
Have confirmed the actual issue is the CameraController
CameraImage
stream, so will close the issue.
Determined this by converting the supplied YUV420 format CameraImage
to a png each time BarcodeScanner
detected a barcode, and displayed the image used next the the result.
Though you don't see it in the video recording, it looks like the very first frame delivered from the CameraController
CameraImage
stream when it is started, is often the same as the last frame delivered before the last time the stream was stopped. i.e. the stream is not always being cleared when it is restarted.
In case anyone else ever raises a similar issue:
_Always discarding the first frame delivered when calling _controller.startImageStream()
solves the issue._
@SoundConception - Thanks for sharing your observations!
Issue:
During repeated use the BarcodeScanner sometimes returns the last previously scanned barcode result while no barcodes are in CameraPreview. I have raised this issue on stackoverflow, but have received no practical responses to date.
At around 22 seconds into this Screen Recording you can see there is no barcode in the camera preview but the previous barcode result is then quickly shown as detected.
To Reproduce:
Minimal Test App:
pubspec.yaml dependencies used:
Physical Testing Procedure:
Observations:
BarcodeScanPage
.BarcodeScanPage
.Debugging Attempts:
Clear the image cache:
I have tried clearing the image cache between visits to the
BarcodeScanPage
with the following code, but it does not change the result:Check if same
CameraImage
is being served from stream:I have also tried adding a global
previousCameraImage
variable and compared the current image byte data to the previous image byte data to see if the same image is being served, by making the following code additions:NOTE: The
CameraImage
class does not implement an equality operator, so I believe the above is a reasonable alternative, but am happy to be corrected!When I run the test with this code change
isPreviousCameraImage
never resolves to true and the main issue still occurs.This result, combined with the fact that the Screen Recording shows that the camera is not pointing at a barcode when the second "barcode detection" occurs, would suggest that the issue may be with the
google_mlkit_barcode_scanning package
.