2
2
3
3
import cn .hutool .core .util .StrUtil ;
4
4
import cn .hutool .log .StaticLog ;
5
+ import com .luooqi .ocr .controller .ProcessController ;
5
6
import com .luooqi .ocr .model .StageInfo ;
6
7
import com .luooqi .ocr .snap .ScreenCapture ;
7
8
import com .luooqi .ocr .utils .CommUtils ;
8
9
import com .luooqi .ocr .utils .GlobalKeyListener ;
10
+ import com .luooqi .ocr .utils .OcrUtils ;
9
11
import javafx .application .Application ;
12
+ import javafx .application .Platform ;
10
13
import javafx .beans .property .SimpleStringProperty ;
11
14
import javafx .geometry .Insets ;
12
15
import javafx .scene .Scene ;
22
25
import org .jnativehook .GlobalScreen ;
23
26
24
27
import javax .swing .*;
28
+ import java .awt .image .BufferedImage ;
25
29
import java .lang .reflect .Method ;
26
30
import java .net .URL ;
27
31
import java .util .HashMap ;
@@ -41,15 +45,16 @@ public static void main(String[] args) {
41
45
public static Stage stage ;
42
46
private static Scene mainScene ;
43
47
private static ScreenCapture screenCapture ;
48
+ private static ProcessController processController ;
44
49
public static TextArea textArea ;
45
50
//private static boolean isSegment = true;
46
51
//private static String ocrText = "";
47
- //private static BooleanProperty isOcr = new SimpleBooleanProperty(false);
48
52
49
53
@ Override
50
54
public void start (Stage primaryStage ) {
51
55
stage = primaryStage ;
52
56
screenCapture = new ScreenCapture (stage );
57
+ processController = new ProcessController ();
53
58
initKeyHook ();
54
59
55
60
// ToggleGroup segmentGrp = new ToggleGroup();
@@ -77,6 +82,8 @@ public void start(Stage primaryStage) {
77
82
topBar .setPadding (new Insets (6 , 8 , 6 , 8 ));
78
83
79
84
textArea = new TextArea ();
85
+ textArea .setId ("ocrTextArea" );
86
+ textArea .setWrapText (false );
80
87
textArea .setFont (Font .font ("Arial" , FontPosture .REGULAR , 14 ));
81
88
82
89
ToolBar footerBar = new ToolBar ();
@@ -182,15 +189,35 @@ public static void cancelSnap() {
182
189
// textArea.setText(ocrText);
183
190
// }
184
191
185
- public static void restore () {
192
+ public static void doOcr (BufferedImage image ){
193
+ processController .show ();
194
+ Thread ocrThread = new Thread (()->{
195
+ byte [] bytes = CommUtils .imageToBytes (image );
196
+ String text = OcrUtils .sogouWebOcr (bytes );
197
+ Platform .runLater (()-> {
198
+ processController .close ();
199
+ stage .show ();
200
+ textArea .setText (text );
201
+ });
202
+ });
203
+ ocrThread .setDaemon (false );
204
+ ocrThread .start ();
205
+ }
206
+
207
+ public static void restore (boolean focus ) {
186
208
stage .setAlwaysOnTop (false );
187
209
stage .setScene (mainScene );
188
210
stage .setFullScreen (stageInfo .isFullScreenState ());
189
211
stage .setX (stageInfo .getX ());
190
212
stage .setY (stageInfo .getY ());
191
213
stage .setWidth (stageInfo .getWidth ());
192
214
stage .setHeight (stageInfo .getHeight ());
193
- stage .requestFocus ();
215
+ if (focus ){
216
+ stage .requestFocus ();
217
+ }
218
+ else {
219
+ stage .close ();
220
+ }
194
221
}
195
222
196
223
private static void initKeyHook (){
0 commit comments