OSはLinux Debianを使用しており、Android Studio2.1.2にOpenCV3.1.0 を導入してプログラムを作成しています。
タイトル通り、Mat形式の変数にnew Mat()などのデータを代入すると実行エラーが発生し、プログラムが強制終了されてしまいます。
ただ、inputFrameを代入する場合は実行エラーは発生しません。
導入については
Fairu>New>Improt ModuleでOpenCVのJavaフォルダ選択して読み込み、OpenCVのbuild.gradleのcompileSdkVersionを24に変更しました。
様々なサイトを調べたのですが、1週間立っても答えにたどり着けませんでした。
デフォルトのプロジェクトにMatを代入するというとても簡単なプログラムでも発生します。
public class MainActivity extends AppCompatActivity {
private Mat tmpl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tmpl=new Mat();
}
このプログラムでのエラーは以下のとおりです
###発生している問題・エラーメッセージ
08-02 14:22:20.229 21215-21215/com.example.bisfate.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bisfate.myapplication, PID: 21215
java.lang.UnsatisfiedLinkError: Native method not found: org.opencv.core.Mat.n_Mat:()J
at org.opencv.core.Mat.n_Mat(Native Method)
at org.opencv.core.Mat.<init>(Mat.java:24)
at com.example.bisfate.myapplication.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
どこのサイトでも同じようにやっている代入方法でプログラムが落ちるので、非常に困っています。
原因がわかる方がいましたら、ご返答おねがいします。
追記
以下元々作っていたプログラムです。
設定がどれに当たるかわからなかったので、手を加えたxmlの追加分のみとjava全文を記述しました。
OpenCVのデフォルトプログラムをベースにタップした際にカメラから得た画像を処理した画像を表示するプログラム
javaのonCreate内のコメントアウトしてある行を戻すと実行エラーが起きます。
activity_main.xml
xml
1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="fill_parent" 5 android:layout_height="fill_parent" 6 android:orientation="vertical" 7 tools:context="com.example.bisfate.decood.MainActivity"> 8 9 <org.opencv.android.JavaCameraView 10 android:id="@+id/camera_view" 11 android:layout_width="fill_parent" 12 android:layout_height="fill_parent" 13 android:visibility="visible" /> 14 15</RelativeLayout> 16
AndroidManifest.xml
xml
1 <uses-permission android:name="android.permission.CAMERA" /> 2 <uses-feature android:name="android.hardware.camera"/> 3 <uses-feature android:name="android.hardware.camera.autofocus"/> 4 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
java
1MainActivity.java 2package com.example.bisfate.decood; 3import android.app.Activity; 4import android.graphics.Bitmap; 5import android.graphics.BitmapFactory; 6import android.os.Bundle; 7import android.util.Log; 8import android.view.MotionEvent; 9import org.opencv.android.BaseLoaderCallback; 10import org.opencv.android.CameraBridgeViewBase; 11import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; 12import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2; 13import org.opencv.android.LoaderCallbackInterface; 14import org.opencv.android.OpenCVLoader; 15import org.opencv.core.CvType; 16import org.opencv.core.Mat; 17import org.opencv.imgproc.Imgproc; 18public class MainActivity extends Activity implements CvCameraViewListener2 { 19 private CameraBridgeViewBase mCameraView; 20 private Mat mOutputFrame;//出力画像 21 private Mat mOutputFrame2;//画像保持用 22 private Mat mat; 23 private Mat tmpl;//テンプレート画像用Mat 24 private int touId=0;//フラグ変数 25 private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { 26 private String TAG = "decood"; 27 @Override 28 public void onManagerConnected(int status) { 29 switch (status) { 30 case LoaderCallbackInterface.SUCCESS: 31 Log.i(TAG, "OpenCV loaded successfully"); 32 mCameraView.enableView(); 33 break; 34 default: 35 super.onManagerConnected(status); 36 break; 37 } 38 } 39 }; 40 @Override 41 protected void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 Bitmap scr= BitmapFactory.decodeResource(getResources(),R.drawable.qrmark);//テンプレートJPG画像読み込み 44// mat=new Mat(); 45// mat=new Mat(new Size(85, 85), CvType.CV_8UC4); 46// tmpl= Utils.bitmapToMat(scr,mat); 47 setContentView(R.layout.activity_main); 48 mCameraView = (CameraBridgeViewBase)findViewById(R.id.camera_view); 49 mCameraView.setCvCameraViewListener(this); 50 } 51 52 @Override 53 public void onPause() { 54 if (mCameraView != null) { 55 mCameraView.disableView(); 56 } 57 super.onPause(); 58 } 59 60 @Override 61 protected void onResume() { 62 super.onResume(); 63 OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_10, this, mLoaderCallback); 64 } 65 66 @Override 67 public void onDestroy() { 68 super.onDestroy(); 69 if (mCameraView != null) { 70 mCameraView.disableView(); 71 } 72 } 73 74 @Override 75 public void onCameraViewStarted(int width, int height) { 76 mOutputFrame = new Mat(height, width, CvType.CV_8UC1); 77 } 78 79 @Override 80 public void onCameraViewStopped() { 81 mOutputFrame.release(); 82 } 83 84 @Override 85 public Mat onCameraFrame(CvCameraViewFrame inputFrame) { 86 switch (touId){ 87 case 0: 88 mOutputFrame=inputFrame.rgba(); 89 break; 90 case 1: 91 Imgproc.threshold(inputFrame.gray(), mOutputFrame, 127.0, 255.0, Imgproc.THRESH_BINARY);//二値化 92 mOutputFrame2=mOutputFrame; 93 touId=2; 94 break; 95 case 2: 96 mOutputFrame=mOutputFrame2; 97 break; 98 } 99 return mOutputFrame; 100 } 101 102 @Override 103 public boolean onTouchEvent(MotionEvent ev) { 104 switch (ev.getAction()) { 105 case MotionEvent.ACTION_DOWN: 106 //画面がタッチされたときの動作 107 if(touId==0){ 108 touId=1; 109 } 110 else if(touId==2){ 111 touId=0; 112 } 113 break; 114 case MotionEvent.ACTION_CANCEL: 115 //他の要因によってタッチがキャンセルされたときの動作 116 break; 117 } 118 return super.onTouchEvent(ev); 119 } 120}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/02 06:27
2016/08/02 06:47
2016/08/02 07:15
2016/08/02 07:29
2016/08/02 08:06
2016/08/02 08:12 編集
2016/08/02 08:12
2016/08/02 08:19
2016/08/02 08:22
2016/08/02 08:25
2016/08/02 08:28
2016/08/02 08:44
2016/08/02 09:22
2016/08/02 09:32
2016/08/02 09:35
2016/08/02 09:42
2016/08/02 09:52