@@ -74,96 +74,96 @@ public void onClick(View view) {
74
74
return root ;
75
75
}
76
76
77
- private FirebaseVisionImage imageFromBitmap (Bitmap bitmap ) {
78
- // [START image_from_bitmap]
79
- Image image = (Image ) bitmap ;
80
- int rotation = getRotationCompensation (
81
- CameraCharacteristics .LENS_FACING_FRONT , MainActivity .this , this );
82
- return FirebaseVisionImage .fromMediaImage (image , rotation );
83
- // [END image_from_bitmap]
84
- }
85
-
86
- @ Override
87
- public void onActivityResult (int requestCode , int resultCode , Intent data ) {
88
- if (requestCode == 1 && resultCode == -1 && data != null ){
89
- Log .d ("check" , "in onActivityResult" );
90
- Bundle extras = data .getExtras ();
91
- if (extras != null ) {
92
- Bitmap bm = (Bitmap ) extras .get ("data" );
93
- this .mImageView .setImageBitmap (bm );
94
-
95
- FirebaseVisionImage image = imageFromBitmap (bm );
96
-
97
-
98
- Task <FirebaseVisionText > result = mDetector .processImage (image )
99
- .addOnSuccessListener (new OnSuccessListener <FirebaseVisionText >() {
100
- @ Override
101
- public void onSuccess (FirebaseVisionText result ) {
102
- String resultText = result .getText ();
103
- Log .d ("result" , resultText );
104
- }
105
- })
106
- .addOnFailureListener (new OnFailureListener () {
107
- @ Override
108
- public void onFailure (@ NonNull Exception e ) {
109
- e .printStackTrace ();
110
- }
111
- });
112
-
113
- }
114
- }
115
- }
116
- private static final SparseIntArray ORIENTATIONS = new SparseIntArray ();
117
- static {
118
- ORIENTATIONS .append (Surface .ROTATION_0 , 90 );
119
- ORIENTATIONS .append (Surface .ROTATION_90 , 0 );
120
- ORIENTATIONS .append (Surface .ROTATION_180 , 270 );
121
- ORIENTATIONS .append (Surface .ROTATION_270 , 180 );
122
- }
123
-
124
- /**
125
- * Get the angle by which an image must be rotated given the device's current
126
- * orientation.
127
- */
128
- @ RequiresApi (api = Build .VERSION_CODES .LOLLIPOP )
129
- private int getRotationCompensation (String cameraId , Activity activity , Context context )
130
- throws CameraAccessException {
131
- // Get the device's current rotation relative to its "native" orientation.
132
- // Then, from the ORIENTATIONS table, look up the angle the image must be
133
- // rotated to compensate for the device's rotation.
134
- int deviceRotation = activity .getWindowManager ().getDefaultDisplay ().getRotation ();
135
- int rotationCompensation = ORIENTATIONS .get (deviceRotation );
136
-
137
- // On most devices, the sensor orientation is 90 degrees, but for some
138
- // devices it is 270 degrees. For devices with a sensor orientation of
139
- // 270, rotate the image an additional 180 ((270 + 270) % 360) degrees.
140
- CameraManager cameraManager = (CameraManager ) context .getSystemService (Context .CAMERA_SERVICE );
141
- int sensorOrientation = cameraManager
142
- .getCameraCharacteristics (cameraId )
143
- .get (CameraCharacteristics .SENSOR_ORIENTATION );
144
- rotationCompensation = (rotationCompensation + sensorOrientation + 270 ) % 360 ;
145
-
146
- // Return the corresponding FirebaseVisionImageMetadata rotation value.
147
- int result ;
148
- switch (rotationCompensation ) {
149
- case 0 :
150
- result = FirebaseVisionImageMetadata .ROTATION_0 ;
151
- break ;
152
- case 90 :
153
- result = FirebaseVisionImageMetadata .ROTATION_90 ;
154
- break ;
155
- case 180 :
156
- result = FirebaseVisionImageMetadata .ROTATION_180 ;
157
- break ;
158
- case 270 :
159
- result = FirebaseVisionImageMetadata .ROTATION_270 ;
160
- break ;
161
- default :
162
- result = FirebaseVisionImageMetadata .ROTATION_0 ;
163
- Log .e ("Rotation" , "Bad rotation value: " + rotationCompensation );
164
- }
165
- return result ;
166
- }
77
+ // private FirebaseVisionImage imageFromBitmap(Bitmap bitmap) {
78
+ // // [START image_from_bitmap]
79
+ // Image image = (Image) bitmap;
80
+ // int rotation = getRotationCompensation(
81
+ // CameraCharacteristics.LENS_FACING_FRONT, MainActivity.this, this);
82
+ // return FirebaseVisionImage.fromMediaImage(image, rotation);
83
+ // // [END image_from_bitmap]
84
+ // }
85
+ //
86
+ // @Override
87
+ // public void onActivityResult(int requestCode, int resultCode, Intent data) {
88
+ // if(requestCode == 1 && resultCode == -1 && data != null){
89
+ // Log.d("check", "in onActivityResult");
90
+ // Bundle extras = data.getExtras();
91
+ // if(extras != null) {
92
+ // Bitmap bm = (Bitmap) extras.get("data");
93
+ // this.mImageView.setImageBitmap(bm);
94
+ //
95
+ // FirebaseVisionImage image = imageFromBitmap(bm);
96
+ //
97
+ //
98
+ // Task<FirebaseVisionText> result = mDetector.processImage(image)
99
+ // .addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
100
+ // @Override
101
+ // public void onSuccess(FirebaseVisionText result) {
102
+ // String resultText = result.getText();
103
+ // Log.d("result", resultText);
104
+ // }
105
+ // })
106
+ // .addOnFailureListener(new OnFailureListener() {
107
+ // @Override
108
+ // public void onFailure(@NonNull Exception e) {
109
+ // e.printStackTrace();
110
+ // }
111
+ // });
112
+ //
113
+ // }
114
+ // }
115
+ // }
116
+ // private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
117
+ // static {
118
+ // ORIENTATIONS.append(Surface.ROTATION_0, 90);
119
+ // ORIENTATIONS.append(Surface.ROTATION_90, 0);
120
+ // ORIENTATIONS.append(Surface.ROTATION_180, 270);
121
+ // ORIENTATIONS.append(Surface.ROTATION_270, 180);
122
+ // }
123
+ //
124
+ // /**
125
+ // * Get the angle by which an image must be rotated given the device's current
126
+ // * orientation.
127
+ // */
128
+ // @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
129
+ // private int getRotationCompensation(String cameraId, Activity activity, Context context)
130
+ // throws CameraAccessException {
131
+ // // Get the device's current rotation relative to its "native" orientation.
132
+ // // Then, from the ORIENTATIONS table, look up the angle the image must be
133
+ // // rotated to compensate for the device's rotation.
134
+ // int deviceRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
135
+ // int rotationCompensation = ORIENTATIONS.get(deviceRotation);
136
+ //
137
+ // // On most devices, the sensor orientation is 90 degrees, but for some
138
+ // // devices it is 270 degrees. For devices with a sensor orientation of
139
+ // // 270, rotate the image an additional 180 ((270 + 270) % 360) degrees.
140
+ // CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
141
+ // int sensorOrientation = cameraManager
142
+ // .getCameraCharacteristics(cameraId)
143
+ // .get(CameraCharacteristics.SENSOR_ORIENTATION);
144
+ // rotationCompensation = (rotationCompensation + sensorOrientation + 270) % 360;
145
+ //
146
+ // // Return the corresponding FirebaseVisionImageMetadata rotation value.
147
+ // int result;
148
+ // switch (rotationCompensation) {
149
+ // case 0:
150
+ // result = FirebaseVisionImageMetadata.ROTATION_0;
151
+ // break;
152
+ // case 90:
153
+ // result = FirebaseVisionImageMetadata.ROTATION_90;
154
+ // break;
155
+ // case 180:
156
+ // result = FirebaseVisionImageMetadata.ROTATION_180;
157
+ // break;
158
+ // case 270:
159
+ // result = FirebaseVisionImageMetadata.ROTATION_270;
160
+ // break;
161
+ // default:
162
+ // result = FirebaseVisionImageMetadata.ROTATION_0;
163
+ // Log.e("Rotation", "Bad rotation value: " + rotationCompensation);
164
+ // }
165
+ // return result;
166
+ // }
167
167
168
168
169
169
}
0 commit comments