Вылетает приложение. Следовал
этому гайду.
Вот MainActivity
package com.example.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceView;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.JavaCameraView;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
private static String TAG = "MainActivity";
JavaCameraView javaCameraView;
Mat mRgba;
BaseLoaderCallback mLoaderCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status)
{
switch (status){
case BaseLoaderCallback.SUCCESS:{
javaCameraView.enableView();
break;
}
default:{
super.onManagerConnected(status);
break;
}
}
super.onManagerConnected(status);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
javaCameraView = (JavaCameraView) findViewById(R.id.java_camera_view);
javaCameraView.setVisibility(SurfaceView. VISIBLE);
javaCameraView.setCvCameraViewListener(this);
}
@Override
protected void onPause(){
super.onPause();
if (javaCameraView!=null)
javaCameraView.disableView();
}
@Override
protected void onDestroy(){
super.onDestroy();
if (javaCameraView!=null)
javaCameraView.disableView();
}
@Override
protected void onResume(){
super.onResume();
if (OpenCVLoader.initDebug()){
Log.i(TAG, "OpenCv loaded successfully");
mLoaderCallBack.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
else{
Log.i(TAG, "OpenCv not loaded");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallBack);
}
}
@Override
public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(height, width, CvType.CV_8UC4);
}
@Override
public void onCameraViewStopped() {
mRgba.release();
}
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
return mRgba;
}
}
Манифест
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.CAMERA" />
<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="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
мой активити
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<org.opencv.android.JavaCameraView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id = "@+id/java_camera_view"
/>
</RelativeLayout>
Логи
16:36 Gradle sync started
16:36 Project setup started
16:36 Gradle sync finished in 1 s 460 ms (from cached state)
16:38 Executing tasks: [:app:assembleDebug]
16:38 Gradle build finished in 19 s 880 ms
16:40 Executing tasks: [:app:assembleDebug]
16:41 Gradle build finished in 10 s 769 ms
16:41 * daemon not running; starting now at tcp:5037
16:41 * daemon started successfully
16:41 Executing tasks: [:app:assembleDebug]
16:41 Gradle build finished in 13 s 966 ms
16:42 Executing tasks: [:app:assembleDebug]
16:42 Gradle build finished in 1 s 660 ms
16:42 Executing tasks: [:app:assembleDebug]
16:42 Gradle build finished in 4 s 285 ms
16:45 Executing tasks: [:app:assembleDebug]
16:45 Gradle build finished in 2 s 737 ms
17:11 Executing tasks: [:app:assembleDebug]
17:11 Gradle build finished in 1 s 296 ms
17:15 Executing tasks: [:app:assembleDebug]
17:15 Emulator: Couldn't statvfs() path: No such file or directory // Пишет, что тут ошибка
17:15 Gradle build finished in 1 s 519 ms
17:16 Emulator: Process finished with exit code 0