Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the OpenCV Tutorial code for Android. I remember that it took a while for me to understand the JNI convention. Just look into JNI code first </p> <pre><code>#include &lt;jni.h&gt; #include &lt;opencv2/core/core.hpp&gt; #include &lt;opencv2/imgproc/imgproc.hpp&gt; #include &lt;opencv2/features2d/features2d.hpp&gt; #include &lt;vector&gt; using namespace std; using namespace cv; extern "C" { JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3View_FindFeatures(JNIEnv* env, jobject thiz, jint width, jint height, jbyteArray yuv, jintArray bgra) { jbyte* _yuv = env-&gt;GetByteArrayElements(yuv, 0); jint* _bgra = env-&gt;GetIntArrayElements(bgra, 0); Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv); Mat mbgra(height, width, CV_8UC4, (unsigned char *)_bgra); Mat mgray(height, width, CV_8UC1, (unsigned char *)_yuv); //Please make attention about BGRA byte order //ARGB stored in java as int array becomes BGRA at native level cvtColor(myuv, mbgra, CV_YUV420sp2BGR, 4); vector&lt;KeyPoint&gt; v; FastFeatureDetector detector(50); detector.detect(mgray, v); for( size_t i = 0; i &lt; v.size(); i++ ) circle(mbgra, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(0,0,255,255)); env-&gt;ReleaseIntArrayElements(bgra, _bgra, 0); env-&gt;ReleaseByteArrayElements(yuv, _yuv, 0); } } </code></pre> <p>and then Java code</p> <pre><code>package org.opencv.samples.tutorial3; import android.content.Context; import android.graphics.Bitmap; class Sample3View extends SampleViewBase { public Sample3View(Context context) { super(context); } @Override protected Bitmap processFrame(byte[] data) { int frameSize = getFrameWidth() * getFrameHeight(); int[] rgba = new int[frameSize]; FindFeatures(getFrameWidth(), getFrameHeight(), data, rgba); Bitmap bmp = Bitmap.createBitmap(getFrameWidth(), getFrameHeight(), Bitmap.Config.ARGB_8888); bmp.setPixels(rgba, 0/* offset */, getFrameWidth() /* stride */, 0, 0, getFrameWidth(), getFrameHeight()); return bmp; } public native void FindFeatures(int width, int height, byte yuv[], int[] rgba); static { System.loadLibrary("native_sample"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload