Reputation: 21
I am trying to run Tensorflow Lite object detection example on Android device. But I need to reconfigure this example to accommodate landscape screen orientation.
I have changed screen orientation parameter in AndroidManifest.xml to 'Landscape' but screen preview is keeping in portrait mode. The squared object detection has functioned correctly, but it seems camera view needs to be rotated.
Please see this screen capture https://ibb.co/Yftyk8P
<activity
android:name=".DetectorActivity"
android:label="@string/activity_name_detection"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Please help me how to fix this problem
Upvotes: 2
Views: 1143
Reputation: 21
I faced same issue on my smart glass which is always has landscape screen orientation. You don't necessarily need to change AndroidManifest.xml. I have changed followings to make it work:
1. Change rotation angle to 0 CameraActivity.java:200
Replace onPreviewSizeChosen(new Size(previewSize.width, previewSize.height), 90); with + onPreviewSizeChosen(new Size(previewSize.width, previewSize.height), 0);
2. Comment camera.setDisplayOrientation(90); from LegacyCameraConnectionFragment.java:88
3. Swap width and height in LegacyCameraConnectionFragment.java at line 97 and line 99
OLD:
camera.addCallbackBuffer(new byte[ImageUtils.getYUVByteSize(s.height, s.width)]); textureView.setAspectRatio(s.height, s.width);
NEW:
camera.addCallbackBuffer(new byte[ImageUtils.getYUVByteSize(s.width, s.height)]); textureView.setAspectRatio(s.width, s.height);
That's it. Now it will work on any landscape device.
Upvotes: 2