cmake: Java/Android SDK refactoring

This commit is contained in:
Alexander Alekhin
2017-12-29 04:15:30 +00:00
parent 0cad2d2a83
commit 8533b45ce9
45 changed files with 914 additions and 847 deletions
+66 -66
View File
@@ -1,11 +1,12 @@
#define LOG_TAG "org.opencv.core.Mat"
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include <stdexcept>
#include <string>
#include "common.h"
#include "opencv2/core.hpp"
#define LOG_TAG "org.opencv.core.Mat"
#include "common.h"
using namespace cv;
/// throw java exception
@@ -1777,67 +1778,6 @@ JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1delete
delete (Mat*) self;
}
// unlike other nPut()-s this one (with double[]) should convert input values to correct type
#define PUT_ITEM(T, R, C) { T*dst = (T*)me->ptr(R, C); for(int ch=0; ch<me->channels() && count>0; count--,ch++,src++,dst++) *dst = cv::saturate_cast<T>(*src); }
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals);
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals)
{
static const char method_name[] = "Mat::nPutD()";
try {
LOGD("%s", method_name);
cv::Mat* me = (cv::Mat*) self;
if(!me || !me->data) return 0; // no native object behind
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
int rest = ((me->rows - row) * me->cols - col) * me->channels();
if(count>rest) count = rest;
int res = count;
double* values = (double*)env->GetPrimitiveArrayCritical(vals, 0);
double* src = values;
int r, c;
for(c=col; c<me->cols && count>0; c++)
{
switch(me->depth()) {
case CV_8U: PUT_ITEM(uchar, row, c); break;
case CV_8S: PUT_ITEM(schar, row, c); break;
case CV_16U: PUT_ITEM(ushort, row, c); break;
case CV_16S: PUT_ITEM(short, row, c); break;
case CV_32S: PUT_ITEM(int, row, c); break;
case CV_32F: PUT_ITEM(float, row, c); break;
case CV_64F: PUT_ITEM(double, row, c); break;
}
}
for(r=row+1; r<me->rows && count>0; r++)
for(c=0; c<me->cols && count>0; c++)
{
switch(me->depth()) {
case CV_8U: PUT_ITEM(uchar, r, c); break;
case CV_8S: PUT_ITEM(schar, r, c); break;
case CV_16U: PUT_ITEM(ushort, r, c); break;
case CV_16S: PUT_ITEM(short, r, c); break;
case CV_32S: PUT_ITEM(int, r, c); break;
case CV_32F: PUT_ITEM(float, r, c); break;
case CV_64F: PUT_ITEM(double, r, c); break;
}
}
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
} catch(const std::exception &e) {
throwJavaException(env, &e, method_name);
} catch (...) {
throwJavaException(env, 0, method_name);
}
return 0;
}
} // extern "C"
namespace {
@@ -1963,6 +1903,66 @@ JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutF
return java_mat_put(env, self, row, col, count, 0, vals);
}
// unlike other nPut()-s this one (with double[]) should convert input values to correct type
#define PUT_ITEM(T, R, C) { T*dst = (T*)me->ptr(R, C); for(int ch=0; ch<me->channels() && count>0; count--,ch++,src++,dst++) *dst = cv::saturate_cast<T>(*src); }
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals);
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals)
{
static const char* method_name = JavaOpenCVTrait<jdoubleArray>::put;
try {
LOGD("%s", method_name);
cv::Mat* me = (cv::Mat*) self;
if(!me || !me->data) return 0; // no native object behind
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
int rest = ((me->rows - row) * me->cols - col) * me->channels();
if(count>rest) count = rest;
int res = count;
double* values = (double*)env->GetPrimitiveArrayCritical(vals, 0);
double* src = values;
int r, c;
for(c=col; c<me->cols && count>0; c++)
{
switch(me->depth()) {
case CV_8U: PUT_ITEM(uchar, row, c); break;
case CV_8S: PUT_ITEM(schar, row, c); break;
case CV_16U: PUT_ITEM(ushort, row, c); break;
case CV_16S: PUT_ITEM(short, row, c); break;
case CV_32S: PUT_ITEM(int, row, c); break;
case CV_32F: PUT_ITEM(float, row, c); break;
case CV_64F: PUT_ITEM(double, row, c); break;
}
}
for(r=row+1; r<me->rows && count>0; r++)
for(c=0; c<me->cols && count>0; c++)
{
switch(me->depth()) {
case CV_8U: PUT_ITEM(uchar, r, c); break;
case CV_8S: PUT_ITEM(schar, r, c); break;
case CV_16U: PUT_ITEM(ushort, r, c); break;
case CV_16S: PUT_ITEM(short, r, c); break;
case CV_32S: PUT_ITEM(int, r, c); break;
case CV_32F: PUT_ITEM(float, r, c); break;
case CV_64F: PUT_ITEM(double, r, c); break;
}
}
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
} catch(const std::exception &e) {
throwJavaException(env, &e, method_name);
} catch (...) {
throwJavaException(env, 0, method_name);
}
return 0;
}
} // extern "C"
template<typename T> static int mat_get(cv::Mat* m, int row, int col, int count, char* buff)
+15 -4
View File
@@ -1,5 +1,14 @@
#ifndef __JAVA_COMMON_H__
#define __JAVA_COMMON_H__
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#ifndef __OPENCV_JAVA_COMMON_H__
#define __OPENCV_JAVA_COMMON_H__
#include <stdexcept>
#include <string>
extern "C" {
#if !defined(__ppc__)
// to suppress warning from jni.h on OS X
@@ -7,7 +16,9 @@
#endif
#include <jni.h>
#include "opencv2/java.hpp"
} // extern "C"
#include "opencv_java.hpp"
#include "opencv2/core/utility.hpp"
#include "converters.h"
@@ -17,4 +28,4 @@
# pragma warning(disable:4800 4244)
#endif
#endif //__JAVA_COMMON_H__
#endif //__OPENCV_JAVA_COMMON_H__
@@ -1,3 +1,7 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#define LOG_TAG "org.opencv.utils.Converters"
#include "common.h"
@@ -1,3 +1,7 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "opencv2/opencv_modules.hpp"
#include "opencv2/core.hpp"
@@ -1,3 +1,7 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "common.h"
#include "opencv2/opencv_modules.hpp"
@@ -0,0 +1,8 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "common.h"
// Include all generated JNI code
#include "opencv_jni.hpp"
+5 -16
View File
@@ -4,9 +4,8 @@
// Author: abratchik
#ifndef JAVA_HPP
#define JAVA_HPP
#undef LOGE
#undef LOGD
#ifdef __ANDROID__
# include <android/log.h>
# define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
@@ -20,6 +19,8 @@
# define LOGD(...)
#endif
#ifndef OPENCV_JAVA_HPP
#define OPENCV_JAVA_HPP
#define MATOFINT(ENV) static_cast<jclass>(ENV->NewGlobalRef(ENV->FindClass("org/opencv/core/MatOfInt")))
#define GETNATIVEOBJ(ENV, CLS, MAT) ENV->GetLongField(MAT, ENV->GetFieldID(CLS, "nativeObj", "J"))
@@ -34,16 +35,4 @@
#define CHECK_MAT(cond) if(!(cond)){ LOGD("FAILED: " #cond); return; }
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* JAVA_HPP */
#endif // OPENCV_JAVA_HPP
+6 -2
View File
@@ -1,5 +1,6 @@
#define LOG_TAG "org.opencv.android.Utils"
#include "common.h"
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
@@ -7,6 +8,9 @@
#ifdef __ANDROID__
#include <android/bitmap.h>
#define LOG_TAG "org.opencv.android.Utils"
#include "common.h"
using namespace cv;
extern "C" {
@@ -12,7 +12,7 @@ import java.util.logging.Logger;
public class OpenCVNativeLoader implements OpenCVInterface {
public void init() {
System.loadLibrary("opencv_java@LIB_NAME_SUFIX@");
System.loadLibrary("opencv_java@OPENCV_JAVA_LIB_NAME_SUFFIX@");
Logger.getLogger("org.opencv.osgi").log(Level.INFO, "Successfully loaded OpenCV native library.");
}
}