-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
197 additions
and
51 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,4 @@ private byte[] toYBuffer(ImageProxy image) { | |
} | ||
return mYBuffer; | ||
} | ||
|
||
|
||
|
||
} |
59 changes: 59 additions & 0 deletions
59
CameraXQRDecoder/src/main/java/com/kongzue/cameraxqrdecoder/util/TextRecognitionImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.kongzue.cameraxqrdecoder.util; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.media.Image; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.camera.core.ImageAnalysis; | ||
import androidx.camera.core.ImageProxy; | ||
|
||
import com.google.android.gms.tasks.OnCompleteListener; | ||
import com.google.android.gms.tasks.OnFailureListener; | ||
import com.google.android.gms.tasks.OnSuccessListener; | ||
import com.google.android.gms.tasks.Task; | ||
import com.google.mlkit.vision.common.InputImage; | ||
import com.google.mlkit.vision.text.Text; | ||
import com.google.mlkit.vision.text.TextRecognition; | ||
import com.google.mlkit.vision.text.TextRecognizer; | ||
import com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions; | ||
import com.kongzue.cameraxqrdecoder.interfaces.OnWorkFinish; | ||
|
||
public class TextRecognitionImpl implements ImageAnalysis.Analyzer { | ||
|
||
OnWorkFinish<String> onWorkFinish; | ||
|
||
public TextRecognitionImpl(OnWorkFinish<String> onWorkFinish) { | ||
this.onWorkFinish = onWorkFinish; | ||
} | ||
|
||
@Override | ||
@SuppressLint("UnsafeOptInUsageError") | ||
public void analyze(@NonNull ImageProxy imageProxy) { | ||
Image image = imageProxy.getImage(); | ||
if (image == null) return; | ||
InputImage inputImage = InputImage.fromMediaImage(image, imageProxy.getImageInfo().getRotationDegrees()); | ||
TextRecognizer recognizer = TextRecognition.getClient(new ChineseTextRecognizerOptions.Builder().build()); | ||
recognizer.process(inputImage) | ||
.addOnSuccessListener(new OnSuccessListener<Text>() { | ||
@Override | ||
public void onSuccess(Text text) { | ||
if (onWorkFinish != null) { | ||
onWorkFinish.finish(text.getText()); | ||
} | ||
} | ||
}) | ||
.addOnCompleteListener(new OnCompleteListener<Text>() { | ||
@Override | ||
public void onComplete(@NonNull Task<Text> task) { | ||
imageProxy.close(); | ||
} | ||
}) | ||
.addOnFailureListener(new OnFailureListener() { | ||
@Override | ||
public void onFailure(@NonNull Exception e) { | ||
imageProxy.close(); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.