Created
May 1, 2014 12:51
-
-
Save jayrambhia/87a50054bfa189bc319d to your computer and use it in GitHub Desktop.
JNI code for the blogpost - http://jayrambhia.com/blog/android-camerapreview-opencv/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <jni.h> | |
| #include <opencv2/core/core.hpp> | |
| #include <opencv2/highgui/highgui.hpp> | |
| #include <opencv2/imgproc/imgproc.hpp> | |
| #include <android/log.h> | |
| #define APPNAME "Exposure jni" | |
| #define LOGD(TAG) __android_log_print(ANDROID_LOG_DEBUG , APPNAME,TAG); | |
| using namespace std; | |
| using namespace cv; | |
| extern "C" | |
| jboolean | |
| Java_my_project_MyRealTimeImageProcessing_CameraPreview_ImageProcessing( | |
| JNIEnv* env, jobject thiz, | |
| jint width, jint height, | |
| jbyteArray NV21FrameData, jintArray outPixels) | |
| { | |
| jbyte * pNV21FrameData = env->GetByteArrayElements(NV21FrameData, 0); | |
| jint * poutPixels = env->GetIntArrayElements(outPixels, 0); | |
| Mat mGray(height + height/2, width, CV_8UC1, (unsigned char *)pNV21FrameData); | |
| Mat blur; | |
| Mat mResult(height, width, CV_8UC4, (unsigned char *)poutPixels); | |
| cvtColor(mGray, blur, CV_YUV2BGR_NV21); | |
| GaussianBlur(blur, blur, Size(5, 5), 5, 0); | |
| cvtColor(blur, mResult, CV_RGB2RGBA); // somehow this seems to work instead of CV_BGR2RGBA | |
| env->ReleaseByteArrayElements(NV21FrameData, pNV21FrameData, 0); | |
| env->ReleaseIntArrayElements(outPixels, poutPixels, 0); | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment