c++ - Why does my Hough circle detection in android not work? -
i have program, trying find circles in image. trying time now, achieved no result yet.
i debugging program , found problem in line: mat mat = new mat();
when run program, unfortunately stops. know why , how can fix it?
mainactivity.java package com.examp.filewithpic; import org.opencv.android.baseloadercallback; import org.opencv.android.camerabridgeviewbase.cvcameraviewframe; import org.opencv.android.loadercallbackinterface; import org.opencv.android.opencvloader; import org.opencv.android.utils; import org.opencv.core.core; import org.opencv.core.cvtype; import org.opencv.core.mat; import org.opencv.core.point; import org.opencv.core.scalar; import org.opencv.core.size; import org.opencv.imgproc.imgproc; import org.opencv.android.camerabridgeviewbase; import org.opencv.android.camerabridgeviewbase.cvcameraviewlistener2; import android.app.activity; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.graphics.drawable.drawable; import android.os.bundle; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.surfaceview; import android.view.windowmanager; import android.widget.imageview; import android.widget.toast; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); bitmap image = bitmapfactory.decoderesource(this.getresources(),r.drawable.aaa); // drawable drawable = this.getresources().getdrawable(r.drawable.aaa); imageview image1= (imageview) findviewbyid(r.id.iv1); imageview image2= (imageview) findviewbyid(r.id.iv2); image1.setimagebitmap(image); int w = image.getwidth(); int h = image.getheight(); toast.maketext(this,"height:"+h+" width:"+w,toast.length_long).show(); /**************/ /* mat mat = new mat(image.getwidth(), image.getheight(), cvtype.cv_8u); */ mat mat = new mat(); mat.create(new size(image.getwidth(), image.getheight()), cvtype.cv_8u); mat graymat = new mat(); graymat.create(new size(image.getwidth(), image.getheight()), cvtype.cv_8u); utils.bitmaptomat(image, mat,false); /* convert grayscale */ int colorchannels = (mat.channels() == 3) ? imgproc.color_bgr2gray : ((mat.channels() == 4) ? imgproc.color_bgra2gray : 1); imgproc.cvtcolor(mat, graymat, colorchannels); /* reduce noise avoid false circle detection */ imgproc.gaussianblur(graymat, graymat, new size(9, 9), 2, 2); // accumulator value double dp = 1.2d; // minimum distance between center coordinates of detected circles in pixels double mindist = 100; // min , max radii (set these values desire) int minradius = 0, maxradius = 12; // param1 = gradient value used handle edge detection // param2 = accumulator threshold value // cv2.cv_hough_gradient method. // smaller threshold is, more circles // detected (including false circles). // larger threshold is, more circles // potentially returned. double param1 = 70, param2 = 72; /* create mat object store circles detected */ mat circles = new mat(image.getwidth(), image.getheight(), cvtype.cv_8u); /* find circle in image */ imgproc.houghcircles(graymat, circles, imgproc.cv_hough_gradient, dp, mindist, param1, param2, minradius, maxradius); /* number of circles detected */ int numberofcircles = (circles.rows() == 0) ? 0 : circles.cols(); /* draw circles found on image */ (int i=0; i<numberofcircles; i++) { /* circle details, circlecoordinates[0, 1, 2] = (x,y,r) * (x,y) coordinates of circle's center */ double[] circlecoordinates = circles.get(0, i); int x = (int) circlecoordinates[0], y = (int) circlecoordinates[1]; point center = new point(x, y); int radius = (int) circlecoordinates[2]; /* circle's outline */ core.circle(mat, center, radius, new scalar(0, 255, 125), 4); /* circle's center outline */ core.rectangle(mat, new point(x - 5, y - 5), new point(x + 5, y + 5), new scalar(0, 128, 255), -1); } /* convert bitmap */ utils.mattobitmap(mat, image,false); } }
xml file :
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linearlayout2" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.examp.filewithpic.mainactivity" > <imageview android:id="@+id/iv1" android:layout_width="wrap_content" android:layout_height="60dp" /> <imageview android:id="@+id/iv2" android:layout_width="wrap_content" android:layout_height="58dp" /> </linearlayout>
log
enter code here 06-15 00:11:51.940: d/dalvikvm(1605): gc_for_alloc freed 75k, 27% free 2728k/3728k, paused 10ms, total 10ms 06-15 00:11:51.940: i/dalvikvm-heap(1605): grow heap (frag case) 3.660mb 1012012-byte allocation 06-15 00:11:51.950: d/dalvikvm(1605): gc_for_alloc freed <1k, 22% free 3716k/4720k, paused 10ms, total 10ms 06-15 00:11:51.970: w/dalvikvm(1605): no implementation found native lorg/opencv/core/mat;.n_mat:()j 06-15 00:11:51.970: d/androidruntime(1605): shutting down vm 06-15 00:11:51.970: w/dalvikvm(1605): threadid=1: thread exiting uncaught exception (group=0x95df5b20) 06-15 00:11:51.970: i/process(1605): sending signal. pid: 1605 sig: 9 06-15 00:11:51.970: d/androidruntime(1605): procname cmdline: com.example.vvvv 06-15 00:11:51.970: e/androidruntime(1605): in writecrashedappname, pkgname :com.example.vvvv 06-15 00:11:51.970: d/androidruntime(1605): file written content: com.example.vvvv stringbuffer : ;com.example.vvvv 06-15 00:11:51.970: e/androidruntime(1605): fatal exception: main 06-15 00:11:51.970: e/androidruntime(1605): process: com.example.vvvv, pid: 1605 06-15 00:11:51.970: e/androidruntime(1605): java.lang.unsatisfiedlinkerror: native method not found: org.opencv.core.mat.n_mat:()j 06-15 00:11:51.970: e/androidruntime(1605): @ org.opencv.core.mat.n_mat(native method) 06-15 00:11:51.970: e/androidruntime(1605): @ org.opencv.core.mat.<init>(mat.java:447) 06-15 00:11:51.970: e/androidruntime(1605): @ com.example.vvvv.mainactivity$1.onclick(mainactivity.java:37) 06-15 00:11:51.970: e/androidruntime(1605): @ android.view.view.performclick(view.java:4443) 06-15 00:11:51.970: e/androidruntime(1605): @ android.view.view$performclick.run(view.java:18433) 06-15 00:11:51.970: e/androidruntime(1605): @ android.os.handler.handlecallback(handler.java:733) 06-15 00:11:51.970: e/androidruntime(1605): @ android.os.handler.dispatchmessage(handler.java:95) 06-15 00:11:51.970: e/androidruntime(1605): @ android.os.looper.loop(looper.java:136) 06-15 00:11:51.970: e/androidruntime(1605): @ android.app.activitythread.main(activitythread.java:5021) 06-15 00:11:51.970: e/androidruntime(1605): @ java.lang.reflect.method.invokenative(native method) 06-15 00:11:51.970: e/androidruntime(1605): @ java.lang.reflect.method.invoke(method.java:515) 06-15 00:11:51.970: e/androidruntime(1605): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:827) 06-15 00:11:51.970: e/androidruntime(1605): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:643) 06-15 00:11:51.970: e/androidruntime(1605): @ dalvik.system.nativestart.main(native method)
Comments
Post a Comment