Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Load and show image using Opencv on Android Studio

I try to create simple android app that shows an image. I can show the image without opencv.

  1. I copy the image under src/drawable folder.
  2. Content of activity_main.xml file
<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"    tools:context=".MainActivity">
 <ImageView android:src="@drawable/logo"
 android:id="@+id/imageView1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" />
  </RelativeLayout>
  1. Content of onCreate method in MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
   }

But I want to do this work using opencv functions. I use below code in onCreate function. I run the code on virtual device and get unfortunately, application has stopped. What is the wrong on this code?

Code :

// make a mat and draw something
  Mat m = Mat.zeros(100,400, CvType.CV_8UC3);
Core.putText(m, "hello world", new Point(30,80), Core.FONT_HERSHEY_SCRIPT_SIMPLEX, 2.2, new Scalar(200,200,0),2);
// convert to bitmap:
Bitmap bm = Bitmap.createBitmap(m.cols(), m.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(m, bm);

// find the imageview and draw it!
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(bm);

My logcat message is here;

 No implementation found for long org.opencv.core.Mat.n_zeros(int, int, int) (tried       Java_org_opencv_core_Mat_n_1zeros and Java_org_opencv_core_Mat_n_1zeros__III)
    at org.opencv.core.Mat.n_zeros(Native Method)
    at org.opencv.core.Mat.zeros(Mat.java:2431)