mirror of
https://github.com/status-im/react-native-camera.git
synced 2025-02-24 01:38:18 +00:00
move rotation to BarCodeScannerAsyncTask (#1667)
This commit is contained in:
parent
0b816adbfd
commit
236758147d
@ -107,26 +107,9 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] rotateImage(byte[] imageData, int height, int width) {
|
||||
byte[] rotated = new byte[imageData.length];
|
||||
for (int y = 0; y < width; y++) {
|
||||
for (int x = 0; x < height; x++) {
|
||||
int sourceIx = x + y * height;
|
||||
int destIx = x * width + width - y - 1;
|
||||
if (sourceIx >= 0 && sourceIx < imageData.length && destIx >= 0 && destIx < imageData.length) {
|
||||
rotated[destIx] = imageData[sourceIx];
|
||||
}
|
||||
}
|
||||
}
|
||||
return rotated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFramePreview(CameraView cameraView, byte[] data, int width, int height, int rotation) {
|
||||
int correctRotation = RNCameraViewHelper.getCorrectCameraRotation(rotation, getFacing());
|
||||
int correctWidth = width;
|
||||
int correctHeight = height;
|
||||
byte[] correctData = data;
|
||||
boolean willCallBarCodeTask = mShouldScanBarCodes && !barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate;
|
||||
boolean willCallFaceTask = mShouldDetectFaces && !faceDetectorTaskLock && cameraView instanceof FaceDetectorAsyncTaskDelegate;
|
||||
boolean willCallGoogleBarcodeTask = mShouldGoogleDetectBarcodes && !googleBarcodeDetectorTaskLock && cameraView instanceof BarcodeDetectorAsyncTaskDelegate;
|
||||
@ -135,33 +118,28 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
|
||||
return;
|
||||
}
|
||||
|
||||
if (correctRotation == 90) {
|
||||
correctWidth = height;
|
||||
correctHeight = width;
|
||||
correctData = rotateImage(data, correctHeight, correctWidth);
|
||||
}
|
||||
if (willCallBarCodeTask) {
|
||||
barCodeScannerTaskLock = true;
|
||||
BarCodeScannerAsyncTaskDelegate delegate = (BarCodeScannerAsyncTaskDelegate) cameraView;
|
||||
new BarCodeScannerAsyncTask(delegate, mMultiFormatReader, correctData, correctWidth, correctHeight).execute();
|
||||
new BarCodeScannerAsyncTask(delegate, mMultiFormatReader, data, width, height).execute();
|
||||
}
|
||||
|
||||
if (willCallFaceTask) {
|
||||
faceDetectorTaskLock = true;
|
||||
FaceDetectorAsyncTaskDelegate delegate = (FaceDetectorAsyncTaskDelegate) cameraView;
|
||||
new FaceDetectorAsyncTask(delegate, mFaceDetector, correctData, correctWidth, correctHeight, correctRotation).execute();
|
||||
new FaceDetectorAsyncTask(delegate, mFaceDetector, data, width, height, correctRotation).execute();
|
||||
}
|
||||
|
||||
if (willCallGoogleBarcodeTask) {
|
||||
googleBarcodeDetectorTaskLock = true;
|
||||
BarcodeDetectorAsyncTaskDelegate delegate = (BarcodeDetectorAsyncTaskDelegate) cameraView;
|
||||
new BarcodeDetectorAsyncTask(delegate, mGoogleBarcodeDetector, correctData, correctWidth, correctHeight, correctRotation).execute();
|
||||
new BarcodeDetectorAsyncTask(delegate, mGoogleBarcodeDetector, data, width, height, correctRotation).execute();
|
||||
}
|
||||
|
||||
if (willCallTextTask) {
|
||||
textRecognizerTaskLock = true;
|
||||
TextRecognizerAsyncTaskDelegate delegate = (TextRecognizerAsyncTaskDelegate) cameraView;
|
||||
new TextRecognizerAsyncTask(delegate, mTextRecognizer, correctData, correctWidth, correctHeight, correctRotation).execute();
|
||||
new TextRecognizerAsyncTask(delegate, mTextRecognizer, data, width, height, correctRotation).execute();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -41,14 +41,27 @@ public class BarCodeScannerAsyncTask extends android.os.AsyncTask<Void, Void, Re
|
||||
BinaryBitmap bitmap = generateBitmapFromImageData(mImageData, mWidth, mHeight);
|
||||
result = mMultiFormatReader.decodeWithState(bitmap);
|
||||
} catch (NotFoundException e) {
|
||||
// No barcode found, result is already null.
|
||||
BinaryBitmap bitmap = generateBitmapFromImageData(rotateImage(mImageData,mWidth, mHeight),mHeight,mWidth);
|
||||
try {
|
||||
result = mMultiFormatReader.decodeWithState(bitmap);
|
||||
} catch (NotFoundException e1) {
|
||||
//no barcode Found
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private byte[] rotateImage(byte[]imageData,int width, int height) {
|
||||
byte[] rotated = new byte[imageData.length];
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
rotated[x * height + height - y - 1] = imageData[x + y * width];
|
||||
}
|
||||
}
|
||||
return rotated;
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Result result) {
|
||||
super.onPostExecute(result);
|
||||
|
Loading…
x
Reference in New Issue
Block a user