我只是使用opencv在可绘制图像上写文本。但是我遇到了错误。我尝试了所有SO答案,但是没有一个起作用。
错误:
java.lang.UnsatisfiedLinkError:找不到长org.opencv.core.Mat.n_Mat(int,int,int)的实现(尝试过Java_org_opencv_core_Mat_n_1Mat和Java_org_opencv_core_Mat_n_1Mat__III) 在org.opencv.core.Mat.n_Mat(本机方法)
public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
ImageView img;
Mat mat;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
Log.i("TAG", "OpenCV loaded Successfully");
mat=new Mat();
//mOpenCvCameraView.enableView();
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = findViewById(R.id.img);
mat = readImageFromResources();
Bitmap bm = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mat, bm);
img.setImageBitmap(bm);
}
private Mat readImageFromResources() {
Mat img = null;
try {
img = Utils.loadResource(this, R.drawable.ic_launcher);
Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2BGRA);
} catch (IOException e) {
//Log.e(TAG,Log.getStackTraceString(e));
}
return img;
}
public void m1() throws IOException {
Mat mat = Utils.loadResource(getApplicationContext(), R.mipmap.ic_launcher);//( image2mat( image ) );
String text = "Funny text inside the box";
int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
double fontScale = 2;
int thickness = 3;
Point point = new Point(10, 130);
//mat. putText( mat, text, textOrg, fontFace, fontScale, Scalar::all( 255 ), thickness, 8 );
//Imgproc.putText(mat, "Original Image", new Point(mat.cols() / 4, mat.rows() / 2), Core.FONT_HERSHEY_COMPLEX, 1, new Scalar(255, 255, 255));
Imgproc.putText(mat, "Video Mode", new Point(10, 50), 3, 1, new Scalar(255, 0, 0, 255), 2);
Bitmap resultbitmap = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mat, resultbitmap);
ImageView img = findViewById(R.id.img);
img.setImageBitmap(resultbitmap);
}
@Override
public void onCameraViewStarted(int width, int height) {
try {
m1();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onCameraViewStopped() {
}
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
return null;
}
public void onResume()
{
super.onResume();
if (!OpenCVLoader.initDebug()) {
Log.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
} else {
Log.d("OpenCV", "OpenCV library found inside package. Using it!");
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
}