Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
67fa8fd
Add a placeholder for the live preview screen.
dustin-graham Jul 7, 2018
c864974
WIP. basic barcode detection impl.
dustin-graham Jul 7, 2018
73f4fe2
WIP.
dustin-graham Jul 7, 2018
04395d8
rotate image on Android prior to creating the FirebaseVisionImage
dustin-graham Jul 9, 2018
cb953e7
Add a basic camera preview implementation
dustin-graham Jul 9, 2018
973b32c
resume camera preview
dustin-graham Jul 9, 2018
8689993
strip out picture taking and video recording from Android camera impl
dustin-graham Jul 9, 2018
beaaa5f
android: insert per-frame handling of preview images
dustin-graham Jul 9, 2018
1ad5ae7
android: pipe image frames to MLKit Barcode detector
dustin-graham Jul 9, 2018
76930fc
android: send count of recognized barcodes
dustin-graham Jul 10, 2018
a0a1b62
android: get barcode bounding boxes displaying in Flutter
dustin-graham Jul 10, 2018
56272e4
ios: Add basic barcode scanning.
dustin-graham Jul 10, 2018
4e10f44
ios: Add live view barcode scanning
dustin-graham Jul 11, 2018
1313564
WIP: live text detection
dustin-graham Jul 13, 2018
99196c3
WIP: android live text detection.
dustin-graham Jul 14, 2018
dacaccf
WIP: Android legacy camera detector impl. Min SDK on this lib is 16.
dustin-graham Jul 19, 2018
6054f37
Android: allow detector and resolution to be set
dustin-graham Jul 19, 2018
de93bc7
Working live detection implementation for Android and iOS
dustin-graham Jul 20, 2018
7c8cca4
Merge remote-tracking branch 'upstream/master' into live_preview
dustin-graham Jul 20, 2018
4c5bf21
update Android with latest from upstream.
dustin-graham Jul 20, 2018
2219e8e
update both Android and iOS live view to work with new detectors.
dustin-graham Jul 20, 2018
8477cf9
Merge remote-tracking branch 'upstream/master' into live_preview
dustin-graham Jul 20, 2018
d1d24e7
remove unused ExifInterface dependency
dustin-graham Jul 21, 2018
b85bdb8
resolve dart analysis warnings.
dustin-graham Jul 21, 2018
a86fe62
reformat code.
dustin-graham Jul 21, 2018
e688aef
fix barcode test
dustin-graham Jul 21, 2018
762b04b
revert accidental camera plugin changes
dustin-graham Jul 21, 2018
8190bff
clang-format iOS files
dustin-graham Jul 21, 2018
f98ce94
Clean up LiveView implementation and fix formatting issues.
dustin-graham Jul 26, 2018
9fdee7c
Merge remote-tracking branch 'upstream/master' into live_preview
dustin-graham Jul 26, 2018
d7e6b32
update to support new LabelDetector.
dustin-graham Jul 26, 2018
776294d
undo inadvertent formatting changes outside firebase_ml_vision.
dustin-graham Jul 26, 2018
ef72e0a
add camera plugin as a dependency to firebase_ml_vision
dustin-graham Jul 27, 2018
543b6d7
wIP: send detected data back to flutter from live feed.
dustin-graham Jul 27, 2018
22e10c2
fix formatting issues.
dustin-graham Jul 27, 2018
858b2aa
restore normal camera functionality.
dustin-graham Jul 27, 2018
5bbbcbc
Merge remote-tracking branch 'upstream/master' into live_preview_came…
dustin-graham Aug 9, 2018
e91181f
present detection boundaries in Flutter from camera plugin integration
dustin-graham Aug 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
android: insert per-frame handling of preview images
this is in preparation to integrate ML Kit recognition of frames.
  • Loading branch information
dustin-graham committed Jul 9, 2018
commit beaaa5fab7c71c0186888e6c526eff09ff07d2aa
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.TotalCaptureResult;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.Image;
import android.media.ImageReader;
import android.media.MediaRecorder;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.util.Size;
import android.view.Surface;

Expand Down Expand Up @@ -57,6 +62,9 @@ public class Camera {
private PluginRegistry.Registrar registrar;
private Activity activity;
private CameraManager cameraManager;
private HandlerThread mBackgroundThread;
private Handler mBackgroundHandler;
private Surface imageReaderSurface;

public Camera(PluginRegistry.Registrar registrar, final String cameraName, @NonNull final String resolutionPreset, @NonNull final MethodChannel.Result result) {

Expand Down Expand Up @@ -200,14 +208,53 @@ private void computeBestCaptureSize(StreamConfigurationMap streamConfigurationMa
new CompareSizesByArea());
}

/**
* Starts a background thread and its {@link Handler}.
*/
private void startBackgroundThread() {
mBackgroundThread = new HandlerThread("CameraBackground");
mBackgroundThread.start();
mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
}

/**
* Stops the background thread and its {@link Handler}.
*/
private void stopBackgroundThread() {
mBackgroundThread.quitSafely();
try {
mBackgroundThread.join();
mBackgroundThread = null;
mBackgroundHandler = null;
} catch (InterruptedException e) {
e.printStackTrace();
}
}

ImageReader.OnImageAvailableListener imageAvailable = new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
Image image = reader.acquireLatestImage();
if (image == null)
return;

Log.d("ML", "got an image from the image reader");

image.close();
}
};

public void open(@Nullable final MethodChannel.Result result) {
if (!hasCameraPermission()) {
if (result != null) result.error("cameraPermission", "Camera permission not granted", null);
} else {
try {
startBackgroundThread();
imageReader =
ImageReader.newInstance(
captureSize.getWidth(), captureSize.getHeight(), ImageFormat.JPEG, 2);
captureSize.getWidth(), captureSize.getHeight(), ImageFormat.YUV_420_888, 4);
imageReaderSurface = imageReader.getSurface();
imageReader.setOnImageAvailableListener(imageAvailable, mBackgroundHandler);
cameraManager.openCamera(
cameraName,
new CameraDevice.StateCallback() {
Expand Down Expand Up @@ -293,7 +340,8 @@ private void startPreview() throws CameraAccessException {
surfaces.add(previewSurface);
captureRequestBuilder.addTarget(previewSurface);

surfaces.add(imageReader.getSurface());
surfaces.add(imageReaderSurface);
captureRequestBuilder.addTarget(imageReaderSurface);

cameraDevice.createCaptureSession(
surfaces,
Expand Down Expand Up @@ -333,7 +381,9 @@ private void sendErrorEvent(String errorDescription) {
}

public void close() {

if (cameraCaptureSession != null) {
cameraCaptureSession.close();
}
if (cameraDevice != null) {
cameraDevice.close();
cameraDevice = null;
Expand All @@ -347,6 +397,7 @@ public void close() {
mediaRecorder.release();
mediaRecorder = null;
}
stopBackgroundThread();
}

public void dispose() {
Expand Down
7 changes: 7 additions & 0 deletions packages/firebase_ml_vision/example/lib/live_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class LivePreviewState extends State<LivePreview> {
}
}


@override
void dispose() {
super.dispose();
_readyLoadState?.controller.dispose();
}

@override
Widget build(BuildContext context) {
return new StreamBuilder<LiveViewCameraLoadState>(
Expand Down