Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
real time text added
Browse files Browse the repository at this point in the history
  • Loading branch information
lewix committed Feb 27, 2019
1 parent 1e1cfa5 commit 55049d1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 40 deletions.
14 changes: 8 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
112F0796A4F8072577410118 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DB0C642D2BB2F7CACD7D84C4 /* libPods-Runner.a */; };
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
2A635DE621ECEF6B000740CC /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2A635DE521ECEF6B000740CC /* GoogleService-Info.plist */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -42,13 +41,15 @@
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
1544A84EEDD3FE2692D8351A /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
2A635DE521ECEF6B000740CC /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
37FA54F11FE008D59265079B /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
936B475671D42A70375CE2EF /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -78,14 +79,16 @@
5E83B076CE5EC19B2F0CC48F /* Pods */ = {
isa = PBXGroup;
children = (
1544A84EEDD3FE2692D8351A /* Pods-Runner.debug.xcconfig */,
37FA54F11FE008D59265079B /* Pods-Runner.release.xcconfig */,
936B475671D42A70375CE2EF /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
Expand Down Expand Up @@ -216,7 +219,6 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
2A635DE621ECEF6B000740CC /* GoogleService-Info.plist in Resources */,
);
Expand Down Expand Up @@ -245,7 +247,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
Expand All @@ -254,7 +256,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
874244AB0939A70E051D0564 /* [CP] Check Pods Manifest.lock */ = {
Expand Down
77 changes: 45 additions & 32 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class CameraPage extends StatefulWidget {
class _CameraAppState extends State<CameraPage> {
CameraController controller;
bool _isScanBusy = false;
Timer _timer;
String _textDetected = "no text detected...";

@override
void initState() {
Expand All @@ -43,18 +45,14 @@ class _CameraAppState extends State<CameraPage> {
return;
}

// controller.startImageStream((CameraImage availableImage) {
// controller.stopImageStream();
// _scanText(availableImage);
// });

setState(() {});
});
}

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

Expand All @@ -65,36 +63,51 @@ class _CameraAppState extends State<CameraPage> {
}
return Column(children: [
Expanded(child: _cameraPreviewWidget()),
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[
MaterialButton(
child: Text("Start Scanning"),
textColor: Colors.white,
color: Colors.blue,
onPressed: () async {
await controller.startImageStream((CameraImage availableImage) async {
//controller.stopImageStream();
if (_isScanBusy) {
print("1.5 -------- isScanBusy, skipping...");
return;
}
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(_textDetected, style: TextStyle(fontStyle: FontStyle.italic,fontSize: 34),)
]),
Container(
height: 100,
child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[
MaterialButton(
child: Text("Start Scanning"),
textColor: Colors.white,
color: Colors.blue,
onPressed: () async {
_timer = Timer.periodic(Duration(seconds: 3), (currentTimer) async {
await controller.startImageStream((CameraImage availableImage) async {
if (_isScanBusy) {
print("1.5 -------- isScanBusy, skipping...");
return;
}

print("1 -------- isScanBusy = true");
_isScanBusy = true;

print("1 -------- isScanBusy = true");
_isScanBusy = true;
OcrManager.scanText(availableImage).then((textVision) {
setState(() {
_textDetected = textVision ?? "";
});

OcrManager.scanText(availableImage).then(
(dummy){
_isScanBusy = false;
}).catchError((error){
_isScanBusy = false;
_isScanBusy = false;
}).catchError((error) {
_isScanBusy = false;
});
});
});
});
}),
MaterialButton(
child: Text("Stop Scanning"),
textColor: Colors.white,
color: Colors.red,
onPressed: () async => await controller.stopImageStream())
])
}),
MaterialButton(
child: Text("Stop Scanning"),
textColor: Colors.white,
color: Colors.red,
onPressed: () async {
_timer?.cancel();
await controller.stopImageStream();
})
]),
),
]);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/ocr_engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter/foundation.dart';

class OcrManager {

static Future<dynamic> scanText(CameraImage availableImage) async {
static Future<String> scanText(CameraImage availableImage) async {

print("scanning!...");

Expand Down Expand Up @@ -48,7 +48,7 @@ class OcrManager {
}
}

return false;
return visionText?.text;
}

/*
Expand Down

0 comments on commit 55049d1

Please sign in to comment.