<h4 dir="auto">System information (version)</h4>
<ul dir="auto">
<li>OpenCV =&gt; 3.1</li>
<li>Operating System / Platform =&gt; Windows 64 Bit</li>
<li>IDE =&gt; Android Studio</li>
</ul>
<h4 dir="auto">Description</h4>
<p dir="auto"><code class="notranslate">StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); int bestWidth = 0, bestHeight = 0; float aspect = (float) width / height; android.util.Size[] sizes = map.getOutputSizes(ImageReader.class);</code></p>
<p dir="auto">The problem is cause by the getOutputSizes return null. But I can't debug the StreamConfigurationMap Class. Is there anyone know how to solve it? Thanks in advance!</p>
<h4 dir="auto">Error Info</h4>
<p dir="auto">05-11 10:13:54.132 29590-29590/com.example.administrator.myapplication E/AndroidRuntime: FATAL EXCEPTION: main<br>
Process: com.example.administrator.myapplication, PID: 29590<br>
java.lang.RuntimeException: Interrupted while setCameraPreviewSize.<br>
at org.opencv.android.JavaCamera2View.connectCamera(JavaCamera2View.java:320)<br>
at org.opencv.android.CameraBridgeViewBase.onEnterStartedState(CameraBridgeViewBase.java:360)<br>
at org.opencv.android.CameraBridgeViewBase.processEnterState(CameraBridgeViewBase.java:321)<br>
at org.opencv.android.CameraBridgeViewBase.checkCurrentState(CameraBridgeViewBase.java:313)<br>
at org.opencv.android.CameraBridgeViewBase.surfaceChanged(CameraBridgeViewBase.java:198)<br>
at android.view.SurfaceView.updateWindow(SurfaceView.java:688)<br>
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:202)<br>
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)<br>
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2391)<br>
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1318)<br>
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6728)<br>
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:802)<br>
at android.view.Choreographer.doCallbacks(Choreographer.java:605)<br>
at android.view.Choreographer.doFrame(Choreographer.java:574)<br>
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:788)<br>
at android.os.Handler.handleCallback(Handler.java:815)<br>
at android.os.Handler.dispatchMessage(Handler.java:104)<br>
at android.os.Looper.loop(Looper.java:194)<br>
at android.app.ActivityThread.main(ActivityThread.java:5898)<br>
at java.lang.reflect.Method.invoke(Native Method)<br>
at java.lang.reflect.Method.invoke(Method.java:372)<br>
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1019)<br>
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:814)<br>
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0<br>
at org.opencv.android.JavaCamera2View.calcPreviewSize(JavaCamera2View.java:265)<br>
at org.opencv.android.JavaCamera2View.connectCamera(JavaCamera2View.java:300)</p>
<h4 dir="auto">Steps to reproduce</h4>
<h5 dir="auto">Activity</h5>
<p dir="auto">package com.example.administrator.myapplication;</p>
<p dir="auto">import android.content.Context;<br>
import android.support.v7.app.AppCompatActivity;<br>
import android.os.Bundle;<br>
import android.widget.TextView;<br>
import android.widget.Toast;</p>
<p dir="auto">import org.opencv.android.BaseLoaderCallback;<br>
import org.opencv.android.CameraBridgeViewBase;<br>
import org.opencv.android.InstallCallbackInterface;<br>
import org.opencv.android.JavaCamera2View;<br>
import org.opencv.android.LoaderCallbackInterface;<br>
import org.opencv.android.OpenCVLoader;<br>
import org.opencv.core.Core;<br>
import org.opencv.core.CvType;<br>
import org.opencv.core.Mat;<br>
import org.opencv.imgproc.Imgproc;</p>
<p dir="auto">public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Mat mat1, mat2, mat3;

CameraBridgeViewBase base;

BaseLoaderCallback callback;

// Used to load the 'native-lib' library on application startup.
static {
    System.loadLibrary(&quot;native-lib&quot;);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    base = findViewById(R.id.camera);
    base.setCvCameraViewListener(this);

    callback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            super.onManagerConnected(status);
            switch (status) {
                case BaseLoaderCallback.SUCCESS:
                    base.enableView();
                    toast(&quot;BaseLoaderCallback.SUCCESS&quot;);
                    break;
            }
        }

        @Override
        public void onPackageInstall(int operation, InstallCallbackInterface callback) {
            super.onPackageInstall(operation, callback);
        }
    };

}

private void toast(final String msg) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
        }
    });
}

/**
 * A native method that is implemented by the 'native-lib' native library,
 * which is packaged with this application.
 */
public native String stringFromJNI();

@Override
public void onCameraViewStarted(int width, int height) {
    Toast.makeText(this, &quot;onCameraViewStarted&quot;, Toast.LENGTH_LONG).show();
    mat1 = new Mat(width, height, CvType.CV_8UC4);
    mat2 = new Mat(width, height, CvType.CV_8UC4);
    mat3 = new Mat(width, height, CvType.CV_8UC4);
}

@Override
public void onCameraViewStopped() {
    Toast.makeText(this, &quot;onCameraViewStopped&quot;, Toast.LENGTH_LONG).show();
    mat1.release();
    mat2.release();
    mat3.release();
}

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    toast(&quot;onCameraFrame&quot;);
    mat1 = inputFrame.rgba();

    //Core.transpose(mat1, mat2);

    //Imgproc.resize(mat2, mat2, mat3.size(),0, 0,0 );

    //Core.flip(mat3, mat1, 1);


    return mat1;
}

@Override
protected void onPause() {
    super.onPause();
    if (base != null) {
        base.disableView();
    }
}

@Override
protected void onResume() {
    super.onResume();
    if (!OpenCVLoader.initDebug()) {
        Toast.makeText(this, &quot;Load Failed&quot;, Toast.LENGTH_LONG).show();
    } else {
        callback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
        Toast.makeText(this, &quot;Load Success&quot;, Toast.LENGTH_LONG).show();
    }
}"><pre class="notranslate"><code class="notranslate">Mat mat1, mat2, mat3;

CameraBridgeViewBase base;

BaseLoaderCallback callback;

// Used to load the 'native-lib' library on application startup.
static {
    System.loadLibrary("native-lib");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    base = findViewById(R.id.camera);
    base.setCvCameraViewListener(this);

    callback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            super.onManagerConnected(status);
            switch (status) {
                case BaseLoaderCallback.SUCCESS:
                    base.enableView();
                    toast("BaseLoaderCallback.SUCCESS");
                    break;
            }
        }

        @Override
        public void onPackageInstall(int operation, InstallCallbackInterface callback) {
            super.onPackageInstall(operation, callback);
        }
    };

}

private void toast(final String msg) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
        }
    });
}

/**
 * A native method that is implemented by the 'native-lib' native library,
 * which is packaged with this application.
 */
public native String stringFromJNI();

@Override
public void onCameraViewStarted(int width, int height) {
    Toast.makeText(this, "onCameraViewStarted", Toast.LENGTH_LONG).show();
    mat1 = new Mat(width, height, CvType.CV_8UC4);
    mat2 = new Mat(width, height, CvType.CV_8UC4);
    mat3 = new Mat(width, height, CvType.CV_8UC4);
}

@Override
public void onCameraViewStopped() {
    Toast.makeText(this, "onCameraViewStopped", Toast.LENGTH_LONG).show();
    mat1.release();
    mat2.release();
    mat3.release();
}

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    toast("onCameraFrame");
    mat1 = inputFrame.rgba();

    //Core.transpose(mat1, mat2);

    //Imgproc.resize(mat2, mat2, mat3.size(),0, 0,0 );

    //Core.flip(mat3, mat1, 1);


    return mat1;
}

@Override
protected void onPause() {
    super.onPause();
    if (base != null) {
        base.disableView();
    }
}

@Override
protected void onResume() {
    super.onResume();
    if (!OpenCVLoader.initDebug()) {
        Toast.makeText(this, "Load Failed", Toast.LENGTH_LONG).show();
    } else {
        callback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
        Toast.makeText(this, "Load Success", Toast.LENGTH_LONG).show();
    }
}
</code></pre></div>
<p dir="auto">}</p>
<h5 dir="auto">XML</h5>

<p dir="auto">&lt;android.support.constraint.ConstraintLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android" rel="nofollow">http://schemas.android.com/apk/res/android</a>"<br>
xmlns:app="<a href="http://schemas.android.com/apk/res-auto" rel="nofollow">http://schemas.android.com/apk/res-auto</a>"<br>
xmlns:tools="<a href="http://schemas.android.com/tools" rel="nofollow">http://schemas.android.com/tools</a>"<br>
android:layout_width="match_parent"<br>
android:layout_height="match_parent"<br>
tools:context="com.example.administrator.myapplication.MainActivity"&gt;</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;org.opencv.android.JavaCamera2View
    android:id=&quot;@+id/camera&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot; /&gt;"><pre class="notranslate"><code class="notranslate">&lt;org.opencv.android.JavaCamera2View
    android:id="@+id/camera"
    android:layout_width="match_parent"
    android:layout_height="match_parent" /&gt;
</code></pre></div>
<p dir="auto">&lt;/android.support.constraint.ConstraintLayout&gt;</p>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 3.4.1</li>
<li>Operating System / Platform =&gt; Android 5.0.1</li>
<li>Compiler =&gt; -/-</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">The Camera2 API Classes Camera2Renderer and JavaCamera2View are not functioning correctly. At least on my phone (Huawei P8, Android 5.0.1). JavaCamera2View crashes in Line 265 while accessing sizes[0] of the possible camera sizes with an IndexOutOfBoundsException 0 &gt;= 0, and Camera2Renderer, used through CameraGLSurfaceView results in a preview with a distorted aspect ratio. The Android Samples are using obsolete and outdated code that doesn't even compile with this version of openCV.</p>
<h5 dir="auto">Steps to reproduce</h5>
<h2 dir="auto">CameraGLSurfaceView</h2>
<h3 dir="auto">Minimal example</h3>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import org.opencv.android.CameraGLSurfaceView;

public class MainActivity extends Activity {
   static {
       System.loadLibrary(&quot;opencv_java3&quot;);
   }

   private CameraGLSurfaceView mView;

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       mView = new CameraGLSurfaceView(this, null);
       setContentView(mView);
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
           WindowManager.LayoutParams.FLAG_FULLSCREEN);
       getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

       View decorView = getWindow().getDecorView();

       int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
       decorView.setSystemUiVisibility(uiOptions);

   }

   @Override
   protected void onPause() {
       mView.onPause();
       super.onPause();
   }

   @Override
   protected void onResume() {
       super.onResume();
       mView.onResume();
   }
}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">android</span>.<span class="pl-s1">app</span>.<span class="pl-s1">Activity</span>;
<span class="pl-k">import</span> <span class="pl-s1">android</span>.<span class="pl-s1">os</span>.<span class="pl-s1">Bundle</span>;
<span class="pl-k">import</span> <span class="pl-s1">android</span>.<span class="pl-s1">view</span>.<span class="pl-s1">View</span>;
<span class="pl-k">import</span> <span class="pl-s1">android</span>.<span class="pl-s1">view</span>.<span class="pl-s1">WindowManager</span>;

<span class="pl-k">import</span> <span class="pl-s1">org</span>.<span class="pl-s1">opencv</span>.<span class="pl-s1">android</span>.<span class="pl-s1">CameraGLSurfaceView</span>;

<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">MainActivity</span> <span class="pl-k">extends</span> <span class="pl-smi">Activity</span> {
   <span class="pl-k">static</span> {
       <span class="pl-smi">System</span>.<span class="pl-en">loadLibrary</span>(<span class="pl-s">"opencv_java3"</span>);
   }

   <span class="pl-k">private</span> <span class="pl-smi">CameraGLSurfaceView</span> <span class="pl-s1">mView</span>;

   <span class="pl-c1">@</span><span class="pl-c1">Override</span>
   <span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-en">onCreate</span>(<span class="pl-smi">Bundle</span> <span class="pl-s1">savedInstanceState</span>) {
       <span class="pl-en">super</span>.<span class="pl-en">onCreate</span>(<span class="pl-s1">savedInstanceState</span>);

       <span class="pl-s1">mView</span> = <span class="pl-k">new</span> <span class="pl-smi">CameraGLSurfaceView</span>(<span class="pl-smi">this</span>, <span class="pl-c1">null</span>);
       <span class="pl-en">setContentView</span>(<span class="pl-s1">mView</span>);
       <span class="pl-en">getWindow</span>().<span class="pl-en">setFlags</span>(<span class="pl-smi">WindowManager</span>.<span class="pl-s1">LayoutParams</span>.<span class="pl-c1">FLAG_FULLSCREEN</span>,
           <span class="pl-smi">WindowManager</span>.<span class="pl-s1">LayoutParams</span>.<span class="pl-c1">FLAG_FULLSCREEN</span>);
       <span class="pl-en">getWindow</span>().<span class="pl-en">addFlags</span>(<span class="pl-smi">WindowManager</span>.<span class="pl-s1">LayoutParams</span>.<span class="pl-c1">FLAG_KEEP_SCREEN_ON</span>);

       <span class="pl-smi">View</span> <span class="pl-s1">decorView</span> = <span class="pl-en">getWindow</span>().<span class="pl-en">getDecorView</span>();

       <span class="pl-smi">int</span> <span class="pl-s1">uiOptions</span> = <span class="pl-smi">View</span>.<span class="pl-c1">SYSTEM_UI_FLAG_HIDE_NAVIGATION</span> | <span class="pl-smi">View</span>.<span class="pl-c1">SYSTEM_UI_FLAG_FULLSCREEN</span>;
       <span class="pl-s1">decorView</span>.<span class="pl-en">setSystemUiVisibility</span>(<span class="pl-s1">uiOptions</span>);

   }

   <span class="pl-c1">@</span><span class="pl-c1">Override</span>
   <span class="pl-k">protected</span> <span class="pl-smi">void</span> <span class="pl-en">onPause</span>() {
       <span class="pl-s1">mView</span>.<span class="pl-en">onPause</span>();
       <span class="pl-en">super</span>.<span class="pl-en">onPause</span>();
   }

   <span class="pl-c1">@</span><span class="pl-c1">Override</span>
   <span class="pl-k">protected</span> <span class="pl-smi">void</span> <span class="pl-en">onResume</span>() {
       <span class="pl-en">super</span>.<span class="pl-en">onResume</span>();
       <span class="pl-s1">mView</span>.<span class="pl-en">onResume</span>();
   }
}</pre></div>
<h3 dir="auto">Results</h3>
<p dir="auto">holding phone in landscape<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/2452821/38830923-144b0c50-41be-11e8-94e5-f4404837107a.png"><img src="https://user-images.githubusercontent.com/2452821/38830923-144b0c50-41be-11e8-94e5-f4404837107a.png" alt="screenshot_2018-04-16-21-32-49" style="max-width: 100%;"></a></p>
<p dir="auto">in portrait<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/2452821/38830927-16489d9c-41be-11e8-9235-11b7597c0ea3.png"><img src="https://user-images.githubusercontent.com/2452821/38830927-16489d9c-41be-11e8-9235-11b7597c0ea3.png" alt="screenshot_2018-04-16-21-32-37" style="max-width: 100%;"></a></p>
<h2 dir="auto">JavaCamera2View</h2>
<h3 dir="auto">Minimal example</h3>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import org.opencv.android.JavaCamera2View;

public class MainActivity extends Activity {
    static {
        System.loadLibrary(&quot;opencv_java3&quot;);
    }

    private JavaCamera2View mView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        mView = findViewById(R.id.camera);
        mView.enableView();

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        View decorView = getWindow().getDecorView();

        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);

    }
}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">android</span>.<span class="pl-s1">app</span>.<span class="pl-s1">Activity</span>;
<span class="pl-k">import</span> <span class="pl-s1">android</span>.<span class="pl-s1">os</span>.<span class="pl-s1">Bundle</span>;
<span class="pl-k">import</span> <span class="pl-s1">android</span>.<span class="pl-s1">view</span>.<span class="pl-s1">View</span>;
<span class="pl-k">import</span> <span class="pl-s1">android</span>.<span class="pl-s1">view</span>.<span class="pl-s1">WindowManager</span>;

<span class="pl-k">import</span> <span class="pl-s1">org</span>.<span class="pl-s1">opencv</span>.<span class="pl-s1">android</span>.<span class="pl-s1">JavaCamera2View</span>;

<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">MainActivity</span> <span class="pl-k">extends</span> <span class="pl-smi">Activity</span> {
    <span class="pl-k">static</span> {
        <span class="pl-smi">System</span>.<span class="pl-en">loadLibrary</span>(<span class="pl-s">"opencv_java3"</span>);
    }

    <span class="pl-k">private</span> <span class="pl-smi">JavaCamera2View</span> <span class="pl-s1">mView</span>;

    <span class="pl-c1">@</span><span class="pl-c1">Override</span>
    <span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-en">onCreate</span>(<span class="pl-smi">Bundle</span> <span class="pl-s1">savedInstanceState</span>) {
        <span class="pl-en">super</span>.<span class="pl-en">onCreate</span>(<span class="pl-s1">savedInstanceState</span>);

        <span class="pl-en">setContentView</span>(<span class="pl-smi">R</span>.<span class="pl-s1">layout</span>.<span class="pl-s1">activity_main</span>);

        <span class="pl-s1">mView</span> = <span class="pl-en">findViewById</span>(<span class="pl-smi">R</span>.<span class="pl-s1">id</span>.<span class="pl-s1">camera</span>);
        <span class="pl-s1">mView</span>.<span class="pl-en">enableView</span>();

        <span class="pl-en">getWindow</span>().<span class="pl-en">setFlags</span>(<span class="pl-smi">WindowManager</span>.<span class="pl-s1">LayoutParams</span>.<span class="pl-c1">FLAG_FULLSCREEN</span>,
            <span class="pl-smi">WindowManager</span>.<span class="pl-s1">LayoutParams</span>.<span class="pl-c1">FLAG_FULLSCREEN</span>);
        <span class="pl-en">getWindow</span>().<span class="pl-en">addFlags</span>(<span class="pl-smi">WindowManager</span>.<span class="pl-s1">LayoutParams</span>.<span class="pl-c1">FLAG_KEEP_SCREEN_ON</span>);

        <span class="pl-smi">View</span> <span class="pl-s1">decorView</span> = <span class="pl-en">getWindow</span>().<span class="pl-en">getDecorView</span>();

        <span class="pl-smi">int</span> <span class="pl-s1">uiOptions</span> = <span class="pl-smi">View</span>.<span class="pl-c1">SYSTEM_UI_FLAG_HIDE_NAVIGATION</span> | <span class="pl-smi">View</span>.<span class="pl-c1">SYSTEM_UI_FLAG_FULLSCREEN</span>;
        <span class="pl-s1">decorView</span>.<span class="pl-en">setSystemUiVisibility</span>(<span class="pl-s1">uiOptions</span>);

    }
}</pre></div>
<p dir="auto">layout/activity_main.xml</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout
    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:opencv=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    tools:context=&quot;.MainActivity&quot;&gt;

&lt;org.opencv.android.JavaCamera2View
    android:layout_width=&quot;match_parent&quot;
    android:id=&quot;@+id/camera&quot;
    android:layout_height=&quot;match_parent&quot;/&gt;

&lt;/LinearLayout&gt;"><pre class="notranslate">&lt;?<span class="pl-ent">xml</span><span class="pl-e"> version</span>=<span class="pl-s"><span class="pl-pds">"</span>1.0<span class="pl-pds">"</span></span><span class="pl-e"> encoding</span>=<span class="pl-s"><span class="pl-pds">"</span>utf-8<span class="pl-pds">"</span></span>?&gt;
&lt;<span class="pl-ent">LinearLayout</span>
    <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">android</span>=<span class="pl-s"><span class="pl-pds">"</span>http://schemas.android.com/apk/res/android<span class="pl-pds">"</span></span>
    <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">app</span>=<span class="pl-s"><span class="pl-pds">"</span>http://schemas.android.com/apk/res-auto<span class="pl-pds">"</span></span>
    <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">opencv</span>=<span class="pl-s"><span class="pl-pds">"</span>http://schemas.android.com/apk/res-auto<span class="pl-pds">"</span></span>
    <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">tools</span>=<span class="pl-s"><span class="pl-pds">"</span>http://schemas.android.com/tools<span class="pl-pds">"</span></span>
    <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_width</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>
    <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_height</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>
    <span class="pl-e">tools</span><span class="pl-e">:</span><span class="pl-e">context</span>=<span class="pl-s"><span class="pl-pds">"</span>.MainActivity<span class="pl-pds">"</span></span>&gt;

&lt;<span class="pl-ent">org</span>.opencv.android.JavaCamera2View
    <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_width</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>
    <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>@+id/camera<span class="pl-pds">"</span></span>
    <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_height</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>/&gt;

&lt;/<span class="pl-ent">LinearLayout</span>&gt;</pre></div>
<h3 dir="auto">Stacktrace</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    java.lang.RuntimeException: Interrupted while setCameraPreviewSize.
        at org.opencv.android.JavaCamera2View.connectCamera(JavaCamera2View.java:320)
        at org.opencv.android.CameraBridgeViewBase.onEnterStartedState(CameraBridgeViewBase.java:360)
        at org.opencv.android.CameraBridgeViewBase.processEnterState(CameraBridgeViewBase.java:321)
        at org.opencv.android.CameraBridgeViewBase.checkCurrentState(CameraBridgeViewBase.java:313)
        at org.opencv.android.CameraBridgeViewBase.surfaceChanged(CameraBridgeViewBase.java:198)
        at android.view.SurfaceView.updateWindow(SurfaceView.java:614)
        at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:187)
        at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2018)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1094)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6054)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:793)
        at android.view.Choreographer.doCallbacks(Choreographer.java:606)
        at android.view.Choreographer.doFrame(Choreographer.java:575)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:779)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5538)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:958)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:753)
     Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
        at org.opencv.android.JavaCamera2View.calcPreviewSize(JavaCamera2View.java:265)
        at org.opencv.android.JavaCamera2View.connectCamera(JavaCamera2View.java:300)
        at org.opencv.android.CameraBridgeViewBase.onEnterStartedState(CameraBridgeViewBase.java:360) 
        at org.opencv.android.CameraBridgeViewBase.processEnterState(CameraBridgeViewBase.java:321) 
        at org.opencv.android.CameraBridgeViewBase.checkCurrentState(CameraBridgeViewBase.java:313) 
        at org.opencv.android.CameraBridgeViewBase.surfaceChanged(CameraBridgeViewBase.java:198) 
        at android.view.SurfaceView.updateWindow(SurfaceView.java:614) 
        at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:187) 
        at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847) 
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2018) 
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1094) 
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6054) 
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:793) 
        at android.view.Choreographer.doCallbacks(Choreographer.java:606) 
        at android.view.Choreographer.doFrame(Choreographer.java:575) 
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:779) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5538) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:958) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:753)"><pre class="notranslate"><code class="notranslate">    java.lang.RuntimeException: Interrupted while setCameraPreviewSize.
        at org.opencv.android.JavaCamera2View.connectCamera(JavaCamera2View.java:320)
        at org.opencv.android.CameraBridgeViewBase.onEnterStartedState(CameraBridgeViewBase.java:360)
        at org.opencv.android.CameraBridgeViewBase.processEnterState(CameraBridgeViewBase.java:321)
        at org.opencv.android.CameraBridgeViewBase.checkCurrentState(CameraBridgeViewBase.java:313)
        at org.opencv.android.CameraBridgeViewBase.surfaceChanged(CameraBridgeViewBase.java:198)
        at android.view.SurfaceView.updateWindow(SurfaceView.java:614)
        at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:187)
        at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2018)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1094)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6054)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:793)
        at android.view.Choreographer.doCallbacks(Choreographer.java:606)
        at android.view.Choreographer.doFrame(Choreographer.java:575)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:779)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5538)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:958)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:753)
     Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
        at org.opencv.android.JavaCamera2View.calcPreviewSize(JavaCamera2View.java:265)
        at org.opencv.android.JavaCamera2View.connectCamera(JavaCamera2View.java:300)
        at org.opencv.android.CameraBridgeViewBase.onEnterStartedState(CameraBridgeViewBase.java:360) 
        at org.opencv.android.CameraBridgeViewBase.processEnterState(CameraBridgeViewBase.java:321) 
        at org.opencv.android.CameraBridgeViewBase.checkCurrentState(CameraBridgeViewBase.java:313) 
        at org.opencv.android.CameraBridgeViewBase.surfaceChanged(CameraBridgeViewBase.java:198) 
        at android.view.SurfaceView.updateWindow(SurfaceView.java:614) 
        at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:187) 
        at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847) 
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2018) 
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1094) 
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6054) 
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:793) 
        at android.view.Choreographer.doCallbacks(Choreographer.java:606) 
        at android.view.Choreographer.doFrame(Choreographer.java:575) 
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:779) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5538) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:958) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:753)
</code></pre></div>
<hr>
<p dir="auto">The only thing i got to work on my phone, is JavaCameraView, but only at low 15 FPS.</p>