i am doing a project using opencv on android. i am coding with c++ but want to implement the program on an android smartphone. i don't want to convert c++ codes to java just because android is in java, so im gonna use JNI. in my research, i have come across codes that really use the JNI coding style but i cannot understand how to transform my c++ codes to JNI codes. i found out that in tutorial 4 of android opencv samples, it uses just the c++ codes unlike in tutorial 3.. so what is really the difference between these two? im wondering if the JNI coding style will give me faster performance. as of now, i was able to use just the c++ and inegrate it with java but the app crashes.
From android opencv tutorial 3:
JNIEXPORT void JNICALL
Java_org_opencv_samples_tutorial3_Sample3View_FindFeatures(JNIEnv* env, jobject,
jint width, jint height, jbyteArray yuv, jintArray bgra)
{
jbyte* _yuv = env->GetByteArrayElements(yuv, 0);
jint* _bgra = env->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);
cvtColor(myuv, mbgra, CV_YUV420sp2BGR, 4);
vector<KeyPoint> v;
FastFeatureDetector detector(50);
detector.detect(mgray, v);
for( size_t i = 0; i < v.size(); i++ )
circle(mbgra, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(0,0,255,255));
env->ReleaseIntArrayElements(bgra, _bgra, 0);
env->ReleaseByteArrayElements(yuv, _yuv, 0);
}
From android opencv tutorial 4:
JNIEXPORT void JNICALL
Java_org_opencv_samples_tutorial4_Sample4View_FindFeatures(JNIEnv*, jobject, jlong
addrGray, jlong addrRgba)
{
Mat* pMatGr=(Mat*)addrGray;
Mat* pMatRgb=(Mat*)addrRgba;
vector<KeyPoint> v;
FastFeatureDetector detector(50);
detector.detect(*pMatGr, v);
for( size_t i = 0; i < v.size(); i++ )
circle(*pMatRgb, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(255,0,0,255));
}