android opencv 3.0的问题

时间:2015-07-20 10:14:04

标签: java android opencv

我有这个代码在opencv 2.4.10上的工作非常好

 package org.opencv.samples.tutorial1;

import java.util.List;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;

import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceView;
import android.view.WindowManager;
import android.widget.Toast;

public class Tutorial1Activity extends Activity implements CvCameraViewListener2 {
    private static final String TAG = "OCVSample::Activity";
private CameraBridgeViewBase mOpenCvCameraView;
private boolean              mIsJavaCamera = true;
private MenuItem             mItemSwitchCamera = null;
Mat gray = new Mat();
Mat cany = new Mat();


//private List<MatOfPoint> contours;

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");
                mOpenCvCameraView.enableView();
            } break;
            default:
            {
                super.onManagerConnected(status);
            } break;
        }
    }
};

public Tutorial1Activity() {
    Log.i(TAG, "Instantiated new " + this.getClass());
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.tutorial1_surface_view);

    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view);

    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);

    mOpenCvCameraView.setCvCameraViewListener(this);
}

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

@Override
public void onResume()
{
    super.onResume();
    if (!OpenCVLoader.initDebug()) {
        Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
    } else {
        Log.d(TAG, "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }
}

public void onDestroy() {
    super.onDestroy();
    if (mOpenCvCameraView != null)
        mOpenCvCameraView.disableView();
}

public void onCameraViewStarted(int width, int height) {



}

public void onCameraViewStopped() {
}

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {



    gray = inputFrame.gray(); 

    Imgproc.Canny(gray, cany, 225, 250, 3, true); 









    return cany;




    }
}

当我将opencv库更改为3.0时,它的stopp工作它给我 不幸的是,projectName Preview已停止

和adb错误

 07-20 13:11:14.198: W/dalvikvm(3977): No implementation found for native Lorg/opencv/core/Mat;.n_Mat:()J
07-20 13:11:14.198: D/AndroidRuntime(3977): Shutting down VM
07-20 13:11:14.198: W/dalvikvm(3977): threadid=1: thread exiting with uncaught exception (group=0x40fb2930)
07-20 13:11:14.208: E/AndroidRuntime(3977): FATAL EXCEPTION: main
07-20 13:11:14.208: E/AndroidRuntime(3977): java.lang.UnsatisfiedLinkError: Native method not found: org.opencv.core.Mat.n_Mat:()J
07-20 13:11:14.208: E/AndroidRuntime(3977):     at org.opencv.core.Mat.n_Mat(Native Method)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at org.opencv.core.Mat.<init>(Mat.java:24)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at org.opencv.samples.tutorial1.Tutorial1Activity.<init>(Tutorial1Activity.java:32)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at java.lang.Class.newInstanceImpl(Native Method)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at java.lang.Class.newInstance(Class.java:1319)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at android.app.ActivityThread.access$700(ActivityThread.java:157)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at android.os.Looper.loop(Looper.java:176)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at android.app.ActivityThread.main(ActivityThread.java:5317)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at java.lang.reflect.Method.invokeNative(Native Method)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at java.lang.reflect.Method.invoke(Method.java:511)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-20 13:11:14.208: E/AndroidRuntime(3977):     at dalvik.system.NativeStart.main(Native Method)

如果我这样做,它在3.0上的工作

    gray = inputFrame.gray(); 

    Imgproc.Canny(gray, cany, 225, 250, 3, true); 

    return cany;

将其更改为

    gray = inputFrame.gray(); 

    return gray;

任何帮助

1 个答案:

答案 0 :(得分:0)

只为输入Mat和输出创建大小和类型 相机启动时 像这样

public void onCameraViewStarted(int width, int height) {
cany= new Mat(height, width, CvType.CV_8UC4);
}

public void onCameraViewStopped() {
    cany.release();
}

// OnCameraFrame

  Imgproc.Canny(inputFrame.gray(), cany, 220, 250);
  return cany;