Last active
January 4, 2016 08:09
-
-
Save jayrambhia/8593232 to your computer and use it in GitHub Desktop.
JNI Example
This file contains 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 <jni.h> | |
#include "opencv2/core/core.hpp" | |
#include <opencv2/highgui/highgui.hpp> | |
#include <opencv2/imgproc/imgproc.hpp> | |
#include <stdio.h> | |
using namespace std; | |
using namespace cv; | |
int toGray(Mat img, Mat& gray); | |
extern "C" { | |
JNIEXPORT jint JNICALL Java_com_example_myapp_Opencvpart_convertNativeGray(JNIEnv*, jobject, jlong addrRgba, jlong addrGray); | |
JNIEXPORT jint JNICALL Java_com_example_myapp_Opencvpart_convertNativeGray(JNIEnv*, jobject, jlong addrRgba, jlong addrGray) { | |
Mat& mRgb = *(Mat*)addrRgba; | |
Mat& mGray = *(Mat*)addrGray; | |
int conv; | |
jint retVal; | |
conv = toGray(mRgb, mGray); | |
retVal = (jint)conv; | |
return retVal; | |
} | |
} | |
int toGray(Mat img, Mat& gray) | |
{ | |
cvtColor(img, gray, CV_RGBA2GRAY); // Assuming RGBA input | |
if (gray.rows == img.rows && gray.cols == img.cols) | |
{ | |
return (1); | |
} | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment