Skip to content

Instantly share code, notes, and snippets.

@jayrambhia
Created May 1, 2014 12:51
Show Gist options
  • Select an option

  • Save jayrambhia/87a50054bfa189bc319d to your computer and use it in GitHub Desktop.

Select an option

Save jayrambhia/87a50054bfa189bc319d to your computer and use it in GitHub Desktop.
#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