Improve local recognition work:

-improve detect of rotation on android
-close recognize view after taking capture to pass correct image orientation
parent e3b2dd3f
......@@ -55,40 +55,44 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
// ignore: tried to stop a non-existent preview
}
try {
int rotation = ((Activity) getContext()).getWindowManager().getDefaultDisplay()
.getRotation();
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
mCamera.setDisplayOrientation(getCameraRotation(rotation));
android.hardware.Camera.getCameraInfo(findBackCameraId(), info);
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
int rotation = ((Activity)getContext()).getWindowManager().getDefaultDisplay()
.getRotation();
} catch (Exception e){
Log.d("Piktomir", "Error starting camera preview: " + e.getMessage());
}
}
int degrees = 0;
static public int getCameraRotation(int rotation) {
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break;
case Surface.ROTATION_90: degrees = 90; break;
case Surface.ROTATION_180: degrees = 180; break;
case Surface.ROTATION_270: degrees = 270; break;
}
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (info.orientation - degrees + 360) % 360;
}
android.hardware.Camera.getCameraInfo(findBackCameraId(), info);
mCamera.setDisplayOrientation(result);
int degrees = 0;
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break;
case Surface.ROTATION_90: degrees = 90; break;
case Surface.ROTATION_180: degrees = 180; break;
case Surface.ROTATION_270: degrees = 270; break;
}
} catch (Exception e){
Log.d("Piktomir", "Error starting camera preview: " + e.getMessage());
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (info.orientation - degrees + 360) % 360;
}
return result;
}
static public int findBackCameraId() {
......
......@@ -14,7 +14,7 @@ import java.nio.charset.Charset;
public class ProgramRecognizer {
private static final int REC_IMAGE_SIZE = 300;
private static final int REC_IMAGE_SIZE = 512;
private static final float MINIMUM_CONFIDENCE = 0.6f;
private static TFObjectDetection objectDetection;
......
......@@ -37,28 +37,9 @@ public class RecognizeActivity extends Activity {
int y = (height - croppedSize) / 2;
int rotation = getWindowManager().getDefaultDisplay().getRotation();
float angle;
switch (rotation) {
case Surface.ROTATION_0:
angle = 90;
break;
case Surface.ROTATION_90:
angle = 0;
break;
case Surface.ROTATION_180:
angle = 270;
break;
case Surface.ROTATION_270:
angle = 180;
break;
default:
angle = 90;
break;
}
Matrix matrix = new Matrix();
matrix.postRotate(angle);
matrix.postRotate(CameraPreview.getCameraRotation(rotation));
Bitmap cropped = Bitmap.createBitmap(bmp, x, y, croppedSize, croppedSize, matrix, true);
bmp.recycle();
......
......@@ -780,6 +780,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = A92275321517C094001B78AA;
......
......@@ -58,9 +58,8 @@ struct Prediction {
[[self sessionOutput] captureStillImageAsynchronouslyFromConnection: videoConnection
completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
[[RecognizeProcessor sharedInstance] recognizeBuffer: imageSampleBuffer pattern: self.pattern];
[self exit];
}];
[self exit];
}
- (void) viewDidLoad {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment