First version.
This commit is contained in:
12
MINDdroidCV_MINDSTORMS/jni/Android.mk
Normal file
12
MINDdroidCV_MINDSTORMS/jni/Android.mk
Normal file
@@ -0,0 +1,12 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
OPENCV_CAMERA_MODULES:=off
|
||||
include /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/OpenCV.mk
|
||||
|
||||
LOCAL_MODULE := mixed_sample
|
||||
LOCAL_SRC_FILES := jni_part.cpp
|
||||
LOCAL_LDLIBS += -llog -ldl
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
3
MINDdroidCV_MINDSTORMS/jni/Application.mk
Normal file
3
MINDdroidCV_MINDSTORMS/jni/Application.mk
Normal file
@@ -0,0 +1,3 @@
|
||||
APP_STL := gnustl_static
|
||||
APP_CPPFLAGS := -frtti -fexceptions
|
||||
APP_ABI := armeabi
|
||||
1
MINDdroidCV_MINDSTORMS/jni/includeOpenCV.mk~
Normal file
1
MINDdroidCV_MINDSTORMS/jni/includeOpenCV.mk~
Normal file
@@ -0,0 +1 @@
|
||||
OPENCV_MK_PATH:=../../OpenCV-2.3.1/share/OpenCV/OpenCV.mk
|
||||
50
MINDdroidCV_MINDSTORMS/jni/jni_part.cpp
Normal file
50
MINDdroidCV_MINDSTORMS/jni/jni_part.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <jni.h>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_com_lego_minddroid_SampleView_FindLight(JNIEnv* env, jobject thiz, jint width, jint height, jbyteArray yuv, jintArray bgra, jdoubleArray array)
|
||||
{
|
||||
jbyte* _yuv = env->GetByteArrayElements(yuv, 0);
|
||||
jint* _bgra = env->GetIntArrayElements(bgra, 0);
|
||||
jdouble* _array = env->GetDoubleArrayElements(array, 0);
|
||||
|
||||
Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv);
|
||||
Mat mbgra(height, width, CV_8UC4, (unsigned char *)_bgra);
|
||||
|
||||
//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);
|
||||
|
||||
Mat mhsv = Mat(mbgra.rows,mbgra.cols,CV_8UC4);
|
||||
cvtColor(mbgra, mhsv, CV_BGR2HSV, 4);
|
||||
|
||||
vector<Mat> planes;
|
||||
Mat mdetect = Mat(mbgra.rows,mbgra.cols,CV_8UC1);
|
||||
|
||||
Scalar lightLower = Scalar(0, 0, 220);
|
||||
Scalar lightUpper = Scalar(255, 10, 255);
|
||||
|
||||
inRange(mhsv, lightLower, lightUpper, mdetect);
|
||||
|
||||
cvtColor(mdetect, mbgra, CV_GRAY2BGRA, 4);
|
||||
|
||||
Moments mm = moments(mdetect,true);
|
||||
_array[0] = mm.m00;
|
||||
_array[1] = mm.m10/mm.m00;
|
||||
_array[2] = mm.m01/mm.m00;
|
||||
|
||||
mhsv.release();
|
||||
mdetect.release();
|
||||
|
||||
env->ReleaseIntArrayElements(bgra, _bgra, 0);
|
||||
env->ReleaseByteArrayElements(yuv, _yuv, 0);
|
||||
env->ReleaseDoubleArrayElements(array, _array, 0);
|
||||
}
|
||||
|
||||
}
|
||||
45
MINDdroidCV_MINDSTORMS/jni/jni_part.cpp.orig
Normal file
45
MINDdroidCV_MINDSTORMS/jni/jni_part.cpp.orig
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <jni.h>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_com_lego_minddroid_SampleView_FindLight(JNIEnv* env, jobject thiz, jlong _imgInp, jlong _imgRes, jintArray array)
|
||||
{
|
||||
jint* _array = env->GetIntArrayElements(array, 0);
|
||||
|
||||
Mat* pMatInp=(Mat*)_imgInp;
|
||||
Mat* pMatRes=(Mat*)_imgRes;
|
||||
Mat m = Mat(pMatInp->rows,pMatInp->cols,CV_8UC4);
|
||||
vector<Mat> planes;
|
||||
//Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv);
|
||||
//Please make attention about BGRA byte order
|
||||
//ARGB stored in java as int array becomes BGRA at native level
|
||||
cvtColor(*pMatInp, m, CV_BGR2HSV, 4);
|
||||
|
||||
split(*pMatRes,planes);
|
||||
for(int i=0; i<4; ++i ){
|
||||
planes[i] = Mat::zeros(planes[i].rows,planes[i].cols, CV_8UC1); //Mat::eye(planes[i].rows,planes[i].cols, CV_8UC1)*255;
|
||||
}
|
||||
|
||||
Scalar lightLower = Scalar(0, 0, 220);
|
||||
Scalar lightUpper = Scalar(360, 10, 255);
|
||||
|
||||
//for(int i=0; i<4; ++i ){
|
||||
inRange(m, lightLower, lightUpper, planes[0]);
|
||||
//}
|
||||
|
||||
merge(planes,*pMatRes);
|
||||
|
||||
circle(*pMatRes, Point(100, 50), 10, Scalar(255,0,255,255));
|
||||
_array[1] = 2*_array[0];
|
||||
|
||||
env->ReleaseIntArrayElements(array, _array, 0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
50
MINDdroidCV_MINDSTORMS/jni/jni_part.cpp~
Normal file
50
MINDdroidCV_MINDSTORMS/jni/jni_part.cpp~
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <jni.h>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_com_lego_minddroid_SampleView_FindLight(JNIEnv* env, jobject thiz, jint width, jint height, jbyteArray yuv, jintArray bgra, jdoubleArray array)
|
||||
{
|
||||
jbyte* _yuv = env->GetByteArrayElements(yuv, 0);
|
||||
jint* _bgra = env->GetIntArrayElements(bgra, 0);
|
||||
jdouble* _array = env->GetDoubleArrayElements(array, 0);
|
||||
|
||||
Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv);
|
||||
Mat mbgra(height, width, CV_8UC4, (unsigned char *)_bgra);
|
||||
|
||||
//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);
|
||||
|
||||
Mat mhsv = Mat(mbgra.rows,mbgra.cols,CV_8UC4);
|
||||
cvtColor(mbgra, mhsv, CV_BGR2HSV, 4);
|
||||
|
||||
vector<Mat> planes;
|
||||
Mat mdetect = Mat(mbgra.rows,mbgra.cols,CV_8UC1);
|
||||
|
||||
Scalar lightLower = Scalar(0, 0, 220);
|
||||
Scalar lightUpper = Scalar(360, 10, 255);
|
||||
|
||||
inRange(mhsv, lightLower, lightUpper, mdetect);
|
||||
Moments mm = moments(mdetect,true);
|
||||
|
||||
cvtColor(mdetect, mbgra, CV_GRAY2BGRA, 4);
|
||||
|
||||
_array[0] = mm.m00;
|
||||
_array[1] = mm.m10/mm.m00;
|
||||
_array[2] = mm.m01/mm.m00;
|
||||
|
||||
mhsv.release();
|
||||
mdetect.release();
|
||||
|
||||
env->ReleaseIntArrayElements(bgra, _bgra, 0);
|
||||
env->ReleaseByteArrayElements(yuv, _yuv, 0);
|
||||
env->ReleaseDoubleArrayElements(array, _array, 0);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user