Android opencv new mat error



下面是我要执行的代码

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    InputStream is = this.getResources().openRawResource(R.drawable.cat); 
    Bitmap footbm = BitmapFactory.decodeStream(is);
    temp = new Mat (footbm.getHeight(),footbm.getWidth() , CvType.CV_8UC1);
    Utils.bitmapToMat(footbm, temp);  
    Imgproc.cvtColor(temp, temp, Imgproc.COLOR_RGB2GRAY);  
    Bitmap grayBmp = Bitmap.createBitmap(footbm.getWidth(), footbm.getHeight(), Config.RGB_565);  
    Utils.matToBitmap(temp, grayBmp);  
    ImageView iv = (ImageView) findViewById(R.id.imageView1);
    iv.setImageBitmap(grayBmp); 
}

给出如下所示的错误

没有找到长org. openv .core. mat的实现。n_Mat (int, int,int)(尝试Java_org_opencv_core_Mat_n_1Mat和Java_org_opencv_core_Mat_n_1Mat__III)编译成功。

我猜这个错误是由这个语句引起的。

temp = new Mat (footbm.getWidth(),footbm.getHeight() , CvType.CV_8UC1);

请建议如何进行。

Execute your code in BaseLoaderCallback
======================================================================
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
        case LoaderCallbackInterface.SUCCESS: {
             //your code
        }
            break;
        default: {
            super.onManagerConnected(status);
        }
            break;
        }
    }
};
======================================================================
put this line in your onCreate
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2,
                    MainActivity.this, mOpenCVCallBack)) {
                Log.e("TEST", "Cannot connect to OpenCV Manager");
            }

您不能在onCreate()中执行任何opencv代码,因为本机so尚未加载

将代码移动到onCameraViewStarted();

相关内容

  • 没有找到相关文章

最新更新