Adding optimization for brief and android using NEON SIMD intrinsics

This commit is contained in:
Ethan Rublee 2010-11-28 05:41:50 +00:00
parent 91d8b2aaac
commit 64f9f7f23c
8 changed files with 81 additions and 23 deletions

View File

@ -4,6 +4,10 @@ include $(CLEAR_VARS)
LOCAL_MODULE := ${android_module_name} LOCAL_MODULE := ${android_module_name}
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_ARM_NEON := true
endif
LOCAL_SRC_FILES := ${android_srcs} LOCAL_SRC_FILES := ${android_srcs}
LOCAL_CFLAGS := ${android_defs} LOCAL_CFLAGS := ${android_defs}

View File

@ -16,7 +16,16 @@ LOCAL_C_INCLUDES += $(OPENCV_INCLUDES)
LOCAL_MODULE := android-opencv LOCAL_MODULE := android-opencv
LOCAL_SRC_FILES := gen/android_cv_wrap.cpp image_pool.cpp \ LOCAL_SRC_FILES := gen/android_cv_wrap.cpp image_pool.cpp \
yuv420sp2rgb.c gl_code.cpp Calibration.cpp gl_code.cpp Calibration.cpp
#ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
# LOCAL_CFLAGS := -DHAVE_NEON=1
# LOCAL_SRC_FILES += yuv2rgb_neon.c.neon
#else
LOCAL_SRC_FILES += yuv420sp2rgb.c
#endif
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)

View File

@ -18,9 +18,9 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
return JNI_VERSION_1_4; return JNI_VERSION_1_4;
} }
JNIEXPORT void JNICALL Java_com_opencv_jni_opencvJNI_addYUVtoPool(JNIEnv * env, JNIEXPORT void JNICALL Java_com_opencv_jni_opencvJNI_addYUVtoPool(JNIEnv * env, jclass thiz, jlong ppool,
jclass thiz, jlong ppool, jobject _jpool, jbyteArray jbuffer, jobject _jpool, jbyteArray jbuffer, jint jidx,
jint jidx, jint jwidth, jint jheight, jboolean jgrey) jint jwidth, jint jheight, jboolean jgrey)
{ {
int buff_height = jheight + (jheight / 2); int buff_height = jheight + (jheight / 2);
Size buff_size(jwidth, buff_height); Size buff_size(jwidth, buff_height);
@ -51,8 +51,7 @@ JNIEXPORT void JNICALL Java_com_opencv_jni_opencvJNI_addYUVtoPool(JNIEnv * env,
} }
//doesn't work unfortunately.. //doesn't work unfortunately..
//TODO cvtColor(mat,color, CV_YCrCb2RGB); //TODO cvtColor(mat,color, CV_YCrCb2RGB);
color_convert_common(buff, buff + jwidth * jheight, jwidth, jheight, color_convert_common(buff, buff + jwidth * jheight, jwidth, jheight, color.ptr<uchar> (0), false);
color.ptr<uchar> (0), false);
} }
if (jgrey) if (jgrey)
@ -99,3 +98,19 @@ void image_pool::addImage(int i, Mat mat)
imagesmap[i] = mat; imagesmap[i] = mat;
} }
void image_pool::convertYUVtoColor(int i, cv::Mat& out)
{
Mat yuv = getYUV(i);
if (yuv.empty())
return;
int width = yuv.cols;
int height = yuv.rows * (2.0f / 3);
out.create(height, width, CV_8UC3);
const unsigned char* buff = yuv.ptr<unsigned char> (0);
unsigned char* out_buff = out.ptr<unsigned char> (0);
//doesn't work unfortunately..
//TODO cvtColor(mat,color, CV_YCrCb2RGB);
color_convert_common(buff, buff + width * height, width, height, out_buff, false);
}

View File

@ -53,6 +53,8 @@ public:
*/ */
void addYUVMat(int i, cv::Mat mat); void addYUVMat(int i, cv::Mat mat);
void convertYUVtoColor(int i, cv::Mat& out);
// int addYUV(uchar* buffer, int size, int width, int height, bool grey,int idx); // int addYUV(uchar* buffer, int size, int width, int height, bool grey,int idx);
// //
// void getBitmap(int * outintarray, int size, int idx); // void getBitmap(int * outintarray, int size, int idx);

View File

@ -25,7 +25,7 @@
#endif #endif
const int bytes_per_pixel = 2; const int bytes_per_pixel = 2;
void color_convert_common(unsigned char *pY, unsigned char *pUV, int width, int height, unsigned char *buffer, int grey) void color_convert_common(const unsigned char *pY, const unsigned char *pUV, int width, int height, unsigned char *buffer, int grey)
{ {
int i, j; int i, j;

View File

@ -7,7 +7,7 @@ extern "C" {
#endif #endif
void color_convert_common( void color_convert_common(
unsigned char *pY, unsigned char *pUV, const unsigned char *pY, const unsigned char *pUV,
int width, int height, unsigned char *buffer, int width, int height, unsigned char *buffer,
int grey); int grey);

View File

@ -24,7 +24,7 @@ public class CameraConfig extends Activity {
// Restore preferences // Restore preferences
SharedPreferences settings = ctx.getSharedPreferences(CAMERA_SETTINGS, SharedPreferences settings = ctx.getSharedPreferences(CAMERA_SETTINGS,
0); 0);
int mode = settings.getInt(CAMERA_MODE, CAMERA_MODE_COLOR); int mode = settings.getInt(CAMERA_MODE, CAMERA_MODE_BW);
return mode; return mode;
} }

View File

@ -44,6 +44,11 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#if ANDROID && HAVE_NEON
#include <cpu-features.h>
#include <arm_neon.h>
#endif
using namespace cv; using namespace cv;
inline int smoothedSum(const Mat& sum, const KeyPoint& pt, int y, int x) inline int smoothedSum(const Mat& sum, const KeyPoint& pt, int y, int x)
@ -107,6 +112,29 @@ Hamming::ResultType Hamming::operator()(const unsigned char* a, const unsigned c
{ {
#if __GNUC__ #if __GNUC__
ResultType result = 0; ResultType result = 0;
#if ANDROID && HAVE_NEON
static uint64_t features = android_getCpuFeatures();
if ((features & ANDROID_CPU_ARM_FEATURE_NEON))
{
for (int i = 0; i < size; i += 16)
{
uint8x16_t A_vec = vld1q_u8 (a + i);
uint8x16_t B_vec = vld1q_u8 (b + i);
//uint8x16_t veorq_u8 (uint8x16_t, uint8x16_t)
uint8x16_t AxorB = veorq_u8 (A_vec, B_vec);
uint8x16_t bitsSet += vcntq_u8 (AxorB);
//uint16x8_t vpadalq_u8 (uint16x8_t, uint8x16_t)
uint16x8_t bitSet8 = vpaddlq_u8 (bitsSet);
uint32x4_t bitSet4 = vpaddlq_u16 (bitSet8);
uint64x2_t bitSet2 = vpaddlq_u32 (bitSet4);
result += vgetq_lane_u64 (bitSet2,0);
result += vgetq_lane_u64 (bitSet2,1);
}
}
else
#endif
for (int i = 0; i < size; i += sizeof(unsigned long)) for (int i = 0; i < size; i += sizeof(unsigned long))
{ {
unsigned long a2 = *reinterpret_cast<const unsigned long*> (a + i); unsigned long a2 = *reinterpret_cast<const unsigned long*> (a + i);