From ccc356829c26ee1c48768b26f7f3abf342e01e1d Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Fri, 5 Aug 2011 15:46:13 +0000 Subject: [PATCH] Fixed color conversion bug --- samples/android/tutorial-3-native/jni/jni_part.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/samples/android/tutorial-3-native/jni/jni_part.cpp b/samples/android/tutorial-3-native/jni/jni_part.cpp index 3d6a6c6..1a2b53d 100644 --- a/samples/android/tutorial-3-native/jni/jni_part.cpp +++ b/samples/android/tutorial-3-native/jni/jni_part.cpp @@ -8,25 +8,27 @@ 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 rgba) +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->GetByteArrayElements(yuv, 0); - jint* _rgba = env->GetIntArrayElements(rgba, 0); + jint* _bgra = env->GetIntArrayElements(bgra, 0); Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv); - Mat mrgba(height, width, CV_8UC4, (unsigned char *)_rgba); + Mat mbgra(height, width, CV_8UC4, (unsigned char *)_bgra); Mat mgray(height, width, CV_8UC1, (unsigned char *)_yuv); - cvtColor(myuv, mrgba, CV_YUV420i2BGR, 4); + //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 v; FastFeatureDetector detector(50); detector.detect(mgray, v); for( size_t i = 0; i < v.size(); i++ ) - circle(mrgba, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(0,0,255,255)); + circle(mbgra, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(0,0,255,255)); - env->ReleaseIntArrayElements(rgba, _rgba, 0); + env->ReleaseIntArrayElements(bgra, _bgra, 0); env->ReleaseByteArrayElements(yuv, _yuv, 0); } -- 2.7.4