在我的项目中,我需要应用图像的SLIC分割。我从here下载了有贡献的opencv SDK
。我的代码无法正常工作,甚至在我的代码或我下载的opencv_contrib
中也无法分辨出问题出在哪里。
测试我的代码后,我得到此错误:
E / Android运行时:致命异常:主要 程序:com.example。***。test_contrib,PID:10052 java.lang.UnsatisfiedLinkError:长期未找到实现 org.opencv.ximgproc.Ximgproc.createSuperpixelSLIC_0(long,int,int, 浮动)(尝试 Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10和 Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10__JIIF)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
imageView = findViewById(R.id.image);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!OpenCVLoader.initDebug()) {
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_4_0, getApplicationContext(), baseLoaderCallback);
} else {
baseLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
});
}
final BaseLoaderCallback baseLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
super.onManagerConnected(status);
if (status == LoaderCallbackInterface.SUCCESS) {
try {
OpenCVLoader.initDebug();
newImage = new Mat();
newMat = new Mat();
x = new Mat();
newImage = Utils.loadResource(getApplicationContext(), R.drawable.retinalimage, CvType.CV_32FC3);
newMat=new Mat();
SuperpixelSLIC x= Ximgproc.createSuperpixelSLIC(newImage, Ximgproc.SLIC,50,(float)0.001);
x.iterate(20);
if (50>0)
x.enforceLabelConnectivity(50);
Mat mask=new Mat();
x.getLabelContourMask(mask,true);
newMat.setTo( new Scalar(0,0,255),mask);
showImage(newMat);
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
void showImage (Mat y){
Bitmap bm = Bitmap.createBitmap(y.width(), y.height(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(y, bm);
imageView.setImageBitmap(bm);
}
}