###前提・実現したいこと
androidstudioでJavaとOpenCVを使い画像認識を使ったアプリを開発しています。
アプリを起動した際にCameraBrideViewbaseを使用しカメラを表示しているのですが、
全画面表示するために一度向きを横向きに回転させ
Manifestに
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"を記入したのですが全画面に表示できませんでした。
###発生している問題・エラーメッセージ
全画面表示をしたいが出来ていない。
カメラのview自体は端末の画面の端あたりに表示はされています。
エラーは出ておらずレイアウトの問題かもしれないです。
###該当のソースコード
カメラを表示するために関係しそうなコード
Java
1public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener { 2 private static final String TAG = "OCVSample::Activity"; 3 4 private CameraBridgeViewBase mOpenCvCameraView; 5 private boolean mIsJavaCamera = true; 6 private MenuItem mItemSwitchCamera = null; 7 int touId = 0; 8 private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { 9 @Override 10 public void onManagerConnected(int status) { 11 switch (status) { 12 case LoaderCallbackInterface.SUCCESS: { 13 Log.i(TAG, "OpenCV loaded successfully"); 14 mOpenCvCameraView.enableView(); 15 } 16 break; 17 default: { 18 super.onManagerConnected(status); 19 } 20 break; 21 } 22 } 23 }; 24 25 public MainActivity() { 26 Log.i(TAG, "Instantiated new" + this.getClass()); 27 } 28 /* Called when activity is first created */ 29 30 @Override //カメラの向きを縦に変えることに成功! 31 public void onCreate(Bundle savedInstanceState) { 32 Log.i(TAG, "called onCreate"); 33 super.onCreate(savedInstanceState); 34 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 35 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 36 setContentView(R.layout.activity_main); 37 mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view); 38 mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); 39 mOpenCvCameraView.setCvCameraViewListener(this); 40 } 41 42 43 @Override 44 public void onPause() { 45 super.onPause(); 46 if (mOpenCvCameraView != null) 47 mOpenCvCameraView.disableView(); 48 } 49 50 51 @Override 52 public void onResume() { 53 super.onResume(); 54 //エラーを直したら「if文」増えた? 55 if (!OpenCVLoader.initDebug()) { 56 Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization"); 57 OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback); 58 } else { 59 Log.d(TAG, "OpenCV library found inside package. Using it!"); 60 mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS); 61 } 62 } 63 64 public void onDestroy() { 65 super.onDestroy(); 66 if (mOpenCvCameraView != null) 67 mOpenCvCameraView.disableView(); 68 } 69 70 public void onCameraViewStarted(int width, int height) { 71 } 72 73 public void onCameraViewStopped() { 74 } 75 76 77 //38行目のエラーを直した時に追加された(下2行) 78 @Override 79 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 80 81 } 82
Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.janome.color2"> <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera2" android:required="false" /> <uses-feature android:name="android.hardware.camera2.autofocus" android:required="false" /> //themeを「@style/AppTheme」から変更 フルスクリーンへ <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SubActivity" android:label="@string/app_name"></activity> </application> </manifest>
mainactivityのXmlファイル
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" xmlns:opencv="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.janome.color2.MainActivity"> <!--<TextView--> android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <RelativeLayout android:layout_width="351dp" android:layout_height="565dp" android:keepScreenOn="true" tools:context=".MainActivity" tools:layout_editor_absoluteX="8dp" tools:layout_editor_absoluteY="8dp"> <org.opencv.android.JavaCameraView android:id="@+id/tutorial1_activity_java_surface_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="gone" opencv:camera_id="any" opencv:show_fps="true" /> </RelativeLayout> </android.support.constraint.ConstraintLayout>
###補足情報(言語/FW/ツール等のバージョンなど)
androidstudio 2.3.1
java
OpenCV 3.0.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/20 13:47
2018/01/25 01:41