【问题标题】:Code throws unsatisfiedLinkError代码抛出 unsatisfiedLinkError
【发布时间】:2014-06-15 22:55:25
【问题描述】:

这是一款将 RGB 图像转换为灰度图像并将其显示在屏幕上的 Android 应用。根据logcat,我收到了来自

unsatisfiedLinkError
Mat ImageMat = new Mat (image.getHeight(), image.getWidth(), CvType.CV_8U, new Scalar(4));

怎么了?


public class ImwriteActivity extends Activity /*implements OnClickListener*/{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_imwrite);
        ImageView img = (ImageView) findViewById(R.id.imageView1);

        //get image from sdcard
        File f = new File(Environment.getExternalStorageDirectory().getPath()+"/Test.jpg"); 
        Bitmap image = BitmapFactory.decodeFile(f.getAbsolutePath());

        //convert Bitmap to Mat
        Mat ImageMat = new Mat (image.getHeight(), image.getWidth(), CvType.CV_8U, new Scalar(4));
        Bitmap myBitmap32 = image.copy(Bitmap.Config.ARGB_8888, true);
        Utils.bitmapToMat(myBitmap32, ImageMat);

        //change the color
        Imgproc.cvtColor(ImageMat, ImageMat, Imgproc.COLOR_RGB2GRAY,4);

        //convert the processed Mat to Bitmap
        Bitmap resultBitmap = Bitmap.createBitmap(ImageMat.cols(),  ImageMat.rows(),Bitmap.Config.ARGB_8888);;
        Utils.matToBitmap(ImageMat, resultBitmap);

        //Set member to the Result Bitmap. This member is displayed in an ImageView
        img.setImageBitmap(resultBitmap);
    }

}

【问题讨论】:

  • 这篇文章可能对你有所帮助stackoverflow.com/questions/14693558/…
  • 告诉人们what you have tried 总是很重要的,包括任何失败的尝试,包括sn-ps,以便他们了解您错过了哪些途径。这很重要,因为它会激发人们回答问题,而且它很重要,因为它可以更容易提供高质量、相关的答案。就问题的当前状态而言,这还没有实现。如果您编辑问题,则可能会阻止问题被关闭,并且您获得的答案的数量、质量和清晰度也会有所提高。
  • 就像上面的链接一样, - 你不能调用任何 opencv 代码,除非 baseloader 完成加载 opencv dll(记住,你在那里调用本地代码)
  • 所以只需将答案标记为已解决

标签: java android opencv


【解决方案1】:

onCreate 是放置 opencv 代码的错误位置,因为它依赖于原生 c++ 代码。

首先你需要加载opencv so的:

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        if (status == LoaderCallbackInterface.SUCCESS ) {
            // now we can call opencv code !
        } else {
            super.onManagerConnected(status);
        }
    }
};

@Override
public void onResume() {;
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_5,this, mLoaderCallback);
    // you may be tempted, to do something here, but it's *async*, and may take some time,
    // so any opencv call here will lead to unresolved native errors.
}


@Override
public void onCameraViewStarted(int width, int height) {
     // probably the best place for your opencv code
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多