changing 'java' module layout
This commit is contained in:
2577
modules/java/generator/src/cpp/Mat.cpp
Normal file
2577
modules/java/generator/src/cpp/Mat.cpp
Normal file
File diff suppressed because it is too large
Load Diff
482
modules/java/generator/src/cpp/VideoCapture.cpp
Normal file
482
modules/java/generator/src/cpp/VideoCapture.cpp
Normal file
@@ -0,0 +1,482 @@
|
||||
#include <jni.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <android/log.h>
|
||||
#define MODULE_LOG_TAG "OpenCV.highgui"
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
|
||||
#endif // DEBUG
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#ifdef HAVE_OPENCV_HIGHGUI
|
||||
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
using namespace cv;
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
//
|
||||
// VideoCapture::VideoCapture()
|
||||
//
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__
|
||||
(JNIEnv* env, jclass);
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__
|
||||
(JNIEnv* env, jclass)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__()");
|
||||
#endif // DEBUG
|
||||
|
||||
VideoCapture* _retval_ = new VideoCapture( );
|
||||
|
||||
return (jlong) _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// VideoCapture::VideoCapture(int device)
|
||||
//
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__I
|
||||
(JNIEnv* env, jclass, jint device);
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__I
|
||||
(JNIEnv* env, jclass, jint device)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__I()");
|
||||
#endif // DEBUG
|
||||
|
||||
VideoCapture* _retval_ = new VideoCapture( device );
|
||||
|
||||
return (jlong) _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__I() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__I() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__I()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// double VideoCapture::get(int propId)
|
||||
//
|
||||
|
||||
JNIEXPORT jdouble JNICALL Java_org_opencv_highgui_VideoCapture_n_1get
|
||||
(JNIEnv* env, jclass, jlong self, jint propId);
|
||||
|
||||
JNIEXPORT jdouble JNICALL Java_org_opencv_highgui_VideoCapture_n_1get
|
||||
(JNIEnv* env, jclass, jlong self, jint propId)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1get()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
double _retval_ = me->get( propId );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1get() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1get() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1get()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::grab()
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1grab
|
||||
(JNIEnv* env, jclass, jlong self);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1grab
|
||||
(JNIEnv* env, jclass, jlong self)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1grab()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
bool _retval_ = me->grab( );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1grab() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1grab() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1grab()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::isOpened()
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1isOpened
|
||||
(JNIEnv* env, jclass, jlong self);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1isOpened
|
||||
(JNIEnv* env, jclass, jlong self)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1isOpened()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
bool _retval_ = me->isOpened( );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1isOpened() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1isOpened() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1isOpened()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::open(int device)
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1open__JI
|
||||
(JNIEnv* env, jclass, jlong self, jint device);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1open__JI
|
||||
(JNIEnv* env, jclass, jlong self, jint device)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1open__JI()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
bool _retval_ = me->open( device );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1open__JI() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1open__JI() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1open__JI()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::read(Mat image)
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1read
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1read
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1read()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
Mat& image = *((Mat*)image_nativeObj);
|
||||
bool _retval_ = me->read( image );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1read() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1read() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1read()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// void VideoCapture::release()
|
||||
//
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1release
|
||||
(JNIEnv* env, jclass, jlong self);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1release
|
||||
(JNIEnv* env, jclass, jlong self)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1release()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
me->release( );
|
||||
|
||||
return;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1release() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1release() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1release()}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::retrieve(Mat image, int channel = 0)
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJI
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj, jint channel);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJI
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj, jint channel)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJI()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
Mat& image = *((Mat*)image_nativeObj);
|
||||
bool _retval_ = me->retrieve( image, channel );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJI() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJI() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1retrieve__JJI()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJ
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJ
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJ()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
Mat& image = *((Mat*)image_nativeObj);
|
||||
bool _retval_ = me->retrieve( image );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJ() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJ() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1retrieve__JJ()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::set(int propId, double value)
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1set
|
||||
(JNIEnv* env, jclass, jlong self, jint propId, jdouble value);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1set
|
||||
(JNIEnv* env, jclass, jlong self, jint propId, jdouble value)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1set()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
bool _retval_ = me->set( propId, value );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1set() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1set() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1set()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPreviewSizes
|
||||
(JNIEnv *env, jclass, jlong self);
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPreviewSizes
|
||||
(JNIEnv *env, jclass, jlong self)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1set()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
union {double prop; const char* name;} u;
|
||||
u.prop = me->get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING);
|
||||
return env->NewStringUTF(u.name);
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1getSupportedPreviewSizes() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return env->NewStringUTF("");
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1getSupportedPreviewSizes() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1getSupportedPreviewSizes()}");
|
||||
return env->NewStringUTF("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// native support for java finalize()
|
||||
// static void VideoCapture::n_delete( __int64 self )
|
||||
//
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1delete
|
||||
(JNIEnv*, jclass, jlong self);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1delete
|
||||
(JNIEnv*, jclass, jlong self)
|
||||
{
|
||||
delete (VideoCapture*) self;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
#endif // HAVE_OPENCV_HIGHGUI
|
442
modules/java/generator/src/cpp/converters.cpp
Normal file
442
modules/java/generator/src/cpp/converters.cpp
Normal file
@@ -0,0 +1,442 @@
|
||||
#include "converters.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <android/log.h>
|
||||
#define MODULE_LOG_TAG "OpenCV.converters"
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
|
||||
#else //DEBUG
|
||||
#define LOGD(...)
|
||||
#endif //DEBUG
|
||||
|
||||
using namespace cv;
|
||||
|
||||
#define CHECK_MAT(cond) if(!(cond)){ LOGD("FAILED: " #cond); return; }
|
||||
|
||||
|
||||
// vector_int
|
||||
|
||||
void Mat_to_vector_int(Mat& mat, vector<int>& v_int)
|
||||
{
|
||||
v_int.clear();
|
||||
CHECK_MAT(mat.type()==CV_32SC1 && mat.cols==1);
|
||||
v_int = (vector<int>) mat;
|
||||
}
|
||||
|
||||
void vector_int_to_Mat(vector<int>& v_int, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_int, true);
|
||||
}
|
||||
|
||||
|
||||
//vector_double
|
||||
|
||||
void Mat_to_vector_double(Mat& mat, vector<double>& v_double)
|
||||
{
|
||||
v_double.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC1 && mat.cols==1);
|
||||
v_double = (vector<double>) mat;
|
||||
}
|
||||
|
||||
void vector_double_to_Mat(vector<double>& v_double, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_double, true);
|
||||
}
|
||||
|
||||
|
||||
// vector_float
|
||||
|
||||
void Mat_to_vector_float(Mat& mat, vector<float>& v_float)
|
||||
{
|
||||
v_float.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC1 && mat.cols==1);
|
||||
v_float = (vector<float>) mat;
|
||||
}
|
||||
|
||||
void vector_float_to_Mat(vector<float>& v_float, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_float, true);
|
||||
}
|
||||
|
||||
|
||||
//vector_uchar
|
||||
|
||||
void Mat_to_vector_uchar(Mat& mat, vector<uchar>& v_uchar)
|
||||
{
|
||||
v_uchar.clear();
|
||||
CHECK_MAT(mat.type()==CV_8UC1 && mat.cols==1);
|
||||
v_uchar = (vector<uchar>) mat;
|
||||
}
|
||||
|
||||
void vector_uchar_to_Mat(vector<uchar>& v_uchar, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_uchar, true);
|
||||
}
|
||||
|
||||
void Mat_to_vector_char(Mat& mat, vector<char>& v_char)
|
||||
{
|
||||
v_char.clear();
|
||||
CHECK_MAT(mat.type()==CV_8SC1 && mat.cols==1);
|
||||
v_char = (vector<char>) mat;
|
||||
}
|
||||
|
||||
void vector_char_to_Mat(vector<char>& v_char, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_char, true);
|
||||
}
|
||||
|
||||
|
||||
//vector_Rect
|
||||
|
||||
void Mat_to_vector_Rect(Mat& mat, vector<Rect>& v_rect)
|
||||
{
|
||||
v_rect.clear();
|
||||
CHECK_MAT(mat.type()==CV_32SC4 && mat.cols==1);
|
||||
v_rect = (vector<Rect>) mat;
|
||||
}
|
||||
|
||||
void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_rect, true);
|
||||
}
|
||||
|
||||
|
||||
//vector_Point
|
||||
void Mat_to_vector_Point(Mat& mat, vector<Point>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32SC2 && mat.cols==1);
|
||||
v_point = (vector<Point>) mat;
|
||||
}
|
||||
|
||||
//vector_Point2f
|
||||
void Mat_to_vector_Point2f(Mat& mat, vector<Point2f>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC2 && mat.cols==1);
|
||||
v_point = (vector<Point2f>) mat;
|
||||
}
|
||||
|
||||
//vector_Point2d
|
||||
void Mat_to_vector_Point2d(Mat& mat, vector<Point2d>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC2 && mat.cols==1);
|
||||
v_point = (vector<Point2d>) mat;
|
||||
}
|
||||
|
||||
|
||||
//vector_Point3i
|
||||
void Mat_to_vector_Point3i(Mat& mat, vector<Point3i>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32SC3 && mat.cols==1);
|
||||
v_point = (vector<Point3i>) mat;
|
||||
}
|
||||
|
||||
//vector_Point3f
|
||||
void Mat_to_vector_Point3f(Mat& mat, vector<Point3f>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC3 && mat.cols==1);
|
||||
v_point = (vector<Point3f>) mat;
|
||||
}
|
||||
|
||||
//vector_Point3d
|
||||
void Mat_to_vector_Point3d(Mat& mat, vector<Point3d>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC3 && mat.cols==1);
|
||||
v_point = (vector<Point3d>) mat;
|
||||
}
|
||||
|
||||
|
||||
void vector_Point_to_Mat(vector<Point>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point2f_to_Mat(vector<Point2f>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point2d_to_Mat(vector<Point2d>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point3i_to_Mat(vector<Point3i>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point3f_to_Mat(vector<Point3f>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point3d_to_Mat(vector<Point3d>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
//vector_KeyPoint
|
||||
void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
|
||||
{
|
||||
v_kp.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC(7) && mat.cols==1);
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<float, 7> v = mat.at< Vec<float, 7> >(i, 0);
|
||||
KeyPoint kp(v[0], v[1], v[2], v[3], v[4], (int)v[5], (int)v[6]);
|
||||
v_kp.push_back(kp);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat)
|
||||
{
|
||||
int count = v_kp.size();
|
||||
mat.create(count, 1, CV_32FC(7));
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
KeyPoint kp = v_kp[i];
|
||||
mat.at< Vec<float, 7> >(i, 0) = Vec<float, 7>(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//vector_Mat
|
||||
void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat)
|
||||
{
|
||||
v_mat.clear();
|
||||
if(mat.type() == CV_32SC2 && mat.cols == 1)
|
||||
{
|
||||
v_mat.reserve(mat.rows);
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<int, 2> a = mat.at< Vec<int, 2> >(i, 0);
|
||||
long long addr = (((long long)a[0])<<32) | a[1];
|
||||
Mat& m = *( (Mat*) addr );
|
||||
v_mat.push_back(m);
|
||||
}
|
||||
} else {
|
||||
LOGD("Mat_to_vector_Mat() FAILED: mat.type() == CV_32SC2 && mat.cols == 1");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
|
||||
{
|
||||
int count = v_mat.size();
|
||||
mat.create(count, 1, CV_32SC2);
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
long long addr = (long long) new Mat(v_mat[i]);
|
||||
mat.at< Vec<int, 2> >(i, 0) = Vec<int, 2>(addr>>32, addr&0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
//vector_DMatch
|
||||
void Mat_to_vector_DMatch(Mat& mat, vector<DMatch>& v_dm)
|
||||
{
|
||||
v_dm.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC4 && mat.cols==1);
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<float, 4> v = mat.at< Vec<float, 4> >(i, 0);
|
||||
DMatch dm((int)v[0], (int)v[1], (int)v[2], v[3]);
|
||||
v_dm.push_back(dm);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void vector_DMatch_to_Mat(vector<DMatch>& v_dm, Mat& mat)
|
||||
{
|
||||
int count = v_dm.size();
|
||||
mat.create(count, 1, CV_32FC4);
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
DMatch dm = v_dm[i];
|
||||
mat.at< Vec<float, 4> >(i, 0) = Vec<float, 4>(dm.queryIdx, dm.trainIdx, dm.imgIdx, dm.distance);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Mat_to_vector_vector_Point(Mat& mat, vector< vector< Point > >& vv_pt)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<Point> vpt;
|
||||
Mat_to_vector_Point(vm[i], vpt);
|
||||
vv_pt.push_back(vpt);
|
||||
}
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_Point2f(Mat& mat, vector< vector< Point2f > >& vv_pt)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<Point2f> vpt;
|
||||
Mat_to_vector_Point2f(vm[i], vpt);
|
||||
vv_pt.push_back(vpt);
|
||||
}
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_Point3f(Mat& mat, vector< vector< Point3f > >& vv_pt)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<Point3f> vpt;
|
||||
Mat_to_vector_Point3f(vm[i], vpt);
|
||||
vv_pt.push_back(vpt);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
void Mat_to_vector_vector_KeyPoint(Mat& mat, vector< vector< KeyPoint > >& vv_kp)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<KeyPoint> vkp;
|
||||
Mat_to_vector_KeyPoint(vm[i], vkp);
|
||||
vv_kp.push_back(vkp);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_KeyPoint_to_Mat(vector< vector< KeyPoint > >& vv_kp, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_kp.size() );
|
||||
for(size_t i=0; i<vv_kp.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_KeyPoint_to_Mat(vv_kp[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_DMatch(Mat& mat, vector< vector< DMatch > >& vv_dm)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<DMatch> vdm;
|
||||
Mat_to_vector_DMatch(vm[i], vdm);
|
||||
vv_dm.push_back(vdm);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_DMatch_to_Mat(vector< vector< DMatch > >& vv_dm, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_dm.size() );
|
||||
for(size_t i=0; i<vv_dm.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_DMatch_to_Mat(vv_dm[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Mat_to_vector_vector_char(Mat& mat, vector< vector< char > >& vv_ch)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<char> vch;
|
||||
Mat_to_vector_char(vm[i], vch);
|
||||
vv_ch.push_back(vch);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_ch.size() );
|
||||
for(size_t i=0; i<vv_ch.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_char_to_Mat(vv_ch[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void vector_vector_Point_to_Mat(vector< vector< Point > >& vv_pt, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_pt.size() );
|
||||
for(size_t i=0; i<vv_pt.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_Point_to_Mat(vv_pt[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_pt.size() );
|
||||
for(size_t i=0; i<vv_pt.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_Point2f_to_Mat(vv_pt[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void vector_vector_Point3f_to_Mat(vector< vector< Point3f > >& vv_pt, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_pt.size() );
|
||||
for(size_t i=0; i<vv_pt.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_Point3f_to_Mat(vv_pt[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void vector_Vec4i_to_Mat(vector<Vec4i>& v_vec, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_vec, true);
|
||||
}
|
||||
|
||||
void vector_Vec4f_to_Mat(vector<Vec4f>& v_vec, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_vec, true);
|
||||
}
|
||||
|
||||
void vector_Vec6f_to_Mat(vector<Vec6f>& v_vec, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_vec, true);
|
||||
}
|
73
modules/java/generator/src/cpp/converters.h
Normal file
73
modules/java/generator/src/cpp/converters.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "features2d_manual.hpp"
|
||||
|
||||
void Mat_to_vector_int(cv::Mat& mat, std::vector<int>& v_int);
|
||||
void vector_int_to_Mat(std::vector<int>& v_int, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_double(cv::Mat& mat, std::vector<double>& v_double);
|
||||
void vector_double_to_Mat(std::vector<double>& v_double, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_float(cv::Mat& mat, std::vector<float>& v_float);
|
||||
void vector_float_to_Mat(std::vector<float>& v_float, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_uchar(cv::Mat& mat, std::vector<uchar>& v_uchar);
|
||||
void vector_uchar_to_Mat(std::vector<uchar>& v_uchar, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_char(cv::Mat& mat, std::vector<char>& v_char);
|
||||
void vector_char_to_Mat(std::vector<char>& v_char, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_Rect(cv::Mat& mat, std::vector<cv::Rect>& v_rect);
|
||||
void vector_Rect_to_Mat(std::vector<cv::Rect>& v_rect, cv::Mat& mat);
|
||||
|
||||
|
||||
void Mat_to_vector_Point(cv::Mat& mat, std::vector<cv::Point>& v_point);
|
||||
void Mat_to_vector_Point2f(cv::Mat& mat, std::vector<cv::Point2f>& v_point);
|
||||
void Mat_to_vector_Point2d(cv::Mat& mat, std::vector<cv::Point2d>& v_point);
|
||||
void Mat_to_vector_Point3i(cv::Mat& mat, std::vector<cv::Point3i>& v_point);
|
||||
void Mat_to_vector_Point3f(cv::Mat& mat, std::vector<cv::Point3f>& v_point);
|
||||
void Mat_to_vector_Point3d(cv::Mat& mat, std::vector<cv::Point3d>& v_point);
|
||||
|
||||
void vector_Point_to_Mat(std::vector<cv::Point>& v_point, cv::Mat& mat);
|
||||
void vector_Point2f_to_Mat(std::vector<cv::Point2f>& v_point, cv::Mat& mat);
|
||||
void vector_Point2d_to_Mat(std::vector<cv::Point2d>& v_point, cv::Mat& mat);
|
||||
void vector_Point3i_to_Mat(std::vector<cv::Point3i>& v_point, cv::Mat& mat);
|
||||
void vector_Point3f_to_Mat(std::vector<cv::Point3f>& v_point, cv::Mat& mat);
|
||||
void vector_Point3d_to_Mat(std::vector<cv::Point3d>& v_point, cv::Mat& mat);
|
||||
|
||||
void vector_Vec4i_to_Mat(std::vector<cv::Vec4i>& v_vec, cv::Mat& mat);
|
||||
void vector_Vec4f_to_Mat(std::vector<cv::Vec4f>& v_vec, cv::Mat& mat);
|
||||
void vector_Vec6f_to_Mat(std::vector<cv::Vec6f>& v_vec, cv::Mat& mat);
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
void Mat_to_vector_KeyPoint(cv::Mat& mat, std::vector<cv::KeyPoint>& v_kp);
|
||||
void vector_KeyPoint_to_Mat(std::vector<cv::KeyPoint>& v_kp, cv::Mat& mat);
|
||||
#endif
|
||||
|
||||
void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat);
|
||||
void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat);
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
void Mat_to_vector_DMatch(cv::Mat& mat, std::vector<cv::DMatch>& v_dm);
|
||||
void vector_DMatch_to_Mat(std::vector<cv::DMatch>& v_dm, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_KeyPoint(cv::Mat& mat, std::vector< std::vector< cv::KeyPoint > >& vv_kp);
|
||||
void vector_vector_KeyPoint_to_Mat(std::vector< std::vector< cv::KeyPoint > >& vv_kp, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_DMatch(cv::Mat& mat, std::vector< std::vector< cv::DMatch > >& vv_dm);
|
||||
void vector_vector_DMatch_to_Mat(std::vector< std::vector< cv::DMatch > >& vv_dm, cv::Mat& mat);
|
||||
#endif
|
||||
|
||||
void Mat_to_vector_vector_char(cv::Mat& mat, std::vector< std::vector< char > >& vv_ch);
|
||||
void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_Point(cv::Mat& mat, std::vector< std::vector< cv::Point > >& vv_pt);
|
||||
void vector_vector_Point_to_Mat(std::vector< std::vector< cv::Point > >& vv_pt, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_Point2f(cv::Mat& mat, std::vector< std::vector< cv::Point2f > >& vv_pt);
|
||||
void vector_vector_Point2f_to_Mat(std::vector< std::vector< cv::Point2f > >& vv_pt, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_Point3f(cv::Mat& mat, std::vector< std::vector< cv::Point3f > >& vv_pt);
|
||||
void vector_vector_Point3f_to_Mat(std::vector< std::vector< cv::Point3f > >& vv_pt, cv::Mat& mat);
|
26
modules/java/generator/src/cpp/core_manual.hpp
Normal file
26
modules/java/generator/src/cpp/core_manual.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
#if 0
|
||||
|
||||
namespace cv
|
||||
{
|
||||
CV_EXPORTS_W void add(InputArray src1, Scalar src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1);
|
||||
|
||||
CV_EXPORTS_W void subtract(InputArray src1, Scalar src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1);
|
||||
|
||||
CV_EXPORTS_W void multiply(InputArray src1, Scalar src2, OutputArray dst, double scale=1, int dtype=-1);
|
||||
|
||||
CV_EXPORTS_W void divide(InputArray src1, Scalar src2, OutputArray dst, double scale=1, int dtype=-1);
|
||||
|
||||
CV_EXPORTS_W void absdiff(InputArray src1, Scalar src2, OutputArray dst);
|
||||
|
||||
CV_EXPORTS_W void compare(InputArray src1, Scalar src2, OutputArray dst, int cmpop);
|
||||
|
||||
CV_EXPORTS_W void min(InputArray src1, Scalar src2, OutputArray dst);
|
||||
|
||||
CV_EXPORTS_W void max(InputArray src1, Scalar src2, OutputArray dst);
|
||||
|
||||
}
|
||||
#endif //0
|
454
modules/java/generator/src/cpp/features2d_manual.hpp
Normal file
454
modules/java/generator/src/cpp/features2d_manual.hpp
Normal file
@@ -0,0 +1,454 @@
|
||||
#ifndef __OPENCV_FEATURES_2D_MANUAL_HPP__
|
||||
#define __OPENCV_FEATURES_2D_MANUAL_HPP__
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
class CV_EXPORTS_AS(FeatureDetector) javaFeatureDetector : public FeatureDetector
|
||||
{
|
||||
public:
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
CV_WRAP void detect( const Mat& image, CV_OUT vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
||||
CV_WRAP void detect( const vector<Mat>& images, CV_OUT vector<vector<KeyPoint> >& keypoints, const vector<Mat>& masks=vector<Mat>() ) const;
|
||||
CV_WRAP virtual bool empty() const;
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
FAST = 1,
|
||||
STAR = 2,
|
||||
SIFT = 3,
|
||||
SURF = 4,
|
||||
ORB = 5,
|
||||
MSER = 6,
|
||||
GFTT = 7,
|
||||
HARRIS = 8,
|
||||
SIMPLEBLOB = 9,
|
||||
DENSE = 10,
|
||||
|
||||
|
||||
GRIDRETECTOR = 1000,
|
||||
|
||||
GRID_FAST = GRIDRETECTOR + FAST,
|
||||
GRID_STAR = GRIDRETECTOR + STAR,
|
||||
GRID_SIFT = GRIDRETECTOR + SIFT,
|
||||
GRID_SURF = GRIDRETECTOR + SURF,
|
||||
GRID_ORB = GRIDRETECTOR + ORB,
|
||||
GRID_MSER = GRIDRETECTOR + MSER,
|
||||
GRID_GFTT = GRIDRETECTOR + GFTT,
|
||||
GRID_HARRIS = GRIDRETECTOR + HARRIS,
|
||||
GRID_SIMPLEBLOB = GRIDRETECTOR + SIMPLEBLOB,
|
||||
GRID_DENSE = GRIDRETECTOR + DENSE,
|
||||
|
||||
|
||||
PYRAMIDDETECTOR = 2000,
|
||||
|
||||
PYRAMID_FAST = PYRAMIDDETECTOR + FAST,
|
||||
PYRAMID_STAR = PYRAMIDDETECTOR + STAR,
|
||||
PYRAMID_SIFT = PYRAMIDDETECTOR + SIFT,
|
||||
PYRAMID_SURF = PYRAMIDDETECTOR + SURF,
|
||||
PYRAMID_ORB = PYRAMIDDETECTOR + ORB,
|
||||
PYRAMID_MSER = PYRAMIDDETECTOR + MSER,
|
||||
PYRAMID_GFTT = PYRAMIDDETECTOR + GFTT,
|
||||
PYRAMID_HARRIS = PYRAMIDDETECTOR + HARRIS,
|
||||
PYRAMID_SIMPLEBLOB = PYRAMIDDETECTOR + SIMPLEBLOB,
|
||||
PYRAMID_DENSE = PYRAMIDDETECTOR + DENSE,
|
||||
|
||||
DYNAMICDETECTOR = 3000,
|
||||
|
||||
DYNAMIC_FAST = DYNAMICDETECTOR + FAST,
|
||||
DYNAMIC_STAR = DYNAMICDETECTOR + STAR,
|
||||
DYNAMIC_SIFT = DYNAMICDETECTOR + SIFT,
|
||||
DYNAMIC_SURF = DYNAMICDETECTOR + SURF,
|
||||
DYNAMIC_ORB = DYNAMICDETECTOR + ORB,
|
||||
DYNAMIC_MSER = DYNAMICDETECTOR + MSER,
|
||||
DYNAMIC_GFTT = DYNAMICDETECTOR + GFTT,
|
||||
DYNAMIC_HARRIS = DYNAMICDETECTOR + HARRIS,
|
||||
DYNAMIC_SIMPLEBLOB = DYNAMICDETECTOR + SIMPLEBLOB,
|
||||
DYNAMIC_DENSE = DYNAMICDETECTOR + DENSE
|
||||
};
|
||||
|
||||
//supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX)
|
||||
//not supported: SimpleBlob, Dense
|
||||
CV_WRAP static javaFeatureDetector* create( int detectorType )
|
||||
{
|
||||
string name;
|
||||
if (detectorType > DYNAMICDETECTOR)
|
||||
{
|
||||
name = "Dynamic";
|
||||
detectorType -= DYNAMICDETECTOR;
|
||||
}
|
||||
if (detectorType > PYRAMIDDETECTOR)
|
||||
{
|
||||
name = "Pyramid";
|
||||
detectorType -= PYRAMIDDETECTOR;
|
||||
}
|
||||
if (detectorType > GRIDRETECTOR)
|
||||
{
|
||||
name = "Grid";
|
||||
detectorType -= GRIDRETECTOR;
|
||||
}
|
||||
|
||||
switch(detectorType)
|
||||
{
|
||||
case FAST:
|
||||
name += "FAST";
|
||||
break;
|
||||
case STAR:
|
||||
name += "STAR";
|
||||
break;
|
||||
case SIFT:
|
||||
name += "SIFT";
|
||||
break;
|
||||
case SURF:
|
||||
name += "SURF";
|
||||
break;
|
||||
case ORB:
|
||||
name += "ORB";
|
||||
break;
|
||||
case MSER:
|
||||
name += "MSER";
|
||||
break;
|
||||
case GFTT:
|
||||
name += "GFTT";
|
||||
break;
|
||||
case HARRIS:
|
||||
name += "HARRIS";
|
||||
break;
|
||||
case SIMPLEBLOB:
|
||||
name += "SimpleBlob";
|
||||
break;
|
||||
case DENSE:
|
||||
name += "Dense";
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Specified feature detector type is not supported." );
|
||||
break;
|
||||
}
|
||||
|
||||
Ptr<FeatureDetector> detector = FeatureDetector::create(name);
|
||||
detector.addref();
|
||||
return (javaFeatureDetector*)((FeatureDetector*) detector);
|
||||
}
|
||||
|
||||
CV_WRAP void write( const string& fileName ) const
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::WRITE);
|
||||
((FeatureDetector*)this)->write(fs);
|
||||
fs.release();
|
||||
}
|
||||
|
||||
CV_WRAP void read( const string& fileName )
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::READ);
|
||||
((FeatureDetector*)this)->read(fs.root());
|
||||
fs.release();
|
||||
}
|
||||
};
|
||||
|
||||
class CV_EXPORTS_AS(DescriptorMatcher) javaDescriptorMatcher : public DescriptorMatcher
|
||||
{
|
||||
public:
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
CV_WRAP virtual bool isMaskSupported() const;
|
||||
CV_WRAP virtual void add( const vector<Mat>& descriptors );
|
||||
CV_WRAP const vector<Mat>& getTrainDescriptors() const;
|
||||
CV_WRAP virtual void clear();
|
||||
CV_WRAP virtual bool empty() const;
|
||||
CV_WRAP virtual void train();
|
||||
CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
CV_OUT vector<DMatch>& matches, const Mat& mask=Mat() ) const;
|
||||
CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void match( const Mat& queryDescriptors, CV_OUT vector<DMatch>& matches,
|
||||
const vector<Mat>& masks=vector<Mat>() );
|
||||
CV_WRAP void knnMatch( const Mat& queryDescriptors, CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
CV_WRAP void radiusMatch( const Mat& queryDescriptors, CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
FLANNBASED = 1,
|
||||
BRUTEFORCE = 2,
|
||||
BRUTEFORCE_L1 = 3,
|
||||
BRUTEFORCE_HAMMING = 4,
|
||||
BRUTEFORCE_HAMMINGLUT = 5,
|
||||
BRUTEFORCE_SL2 = 6
|
||||
};
|
||||
|
||||
CV_WRAP_AS(clone) javaDescriptorMatcher* jclone( bool emptyTrainData=false ) const
|
||||
{
|
||||
Ptr<DescriptorMatcher> matcher = this->clone(emptyTrainData);
|
||||
matcher.addref();
|
||||
return (javaDescriptorMatcher*)((DescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
//supported: FlannBased, BruteForce, BruteForce-L1, BruteForce-Hamming, BruteForce-HammingLUT
|
||||
CV_WRAP static javaDescriptorMatcher* create( int matcherType )
|
||||
{
|
||||
string name;
|
||||
|
||||
switch(matcherType)
|
||||
{
|
||||
case FLANNBASED:
|
||||
name = "FlannBased";
|
||||
break;
|
||||
case BRUTEFORCE:
|
||||
name = "BruteForce";
|
||||
break;
|
||||
case BRUTEFORCE_L1:
|
||||
name = "BruteForce-L1";
|
||||
break;
|
||||
case BRUTEFORCE_HAMMING:
|
||||
name = "BruteForce-Hamming";
|
||||
break;
|
||||
case BRUTEFORCE_HAMMINGLUT:
|
||||
name = "BruteForce-HammingLUT";
|
||||
break;
|
||||
case BRUTEFORCE_SL2:
|
||||
name = "BruteForce-SL2";
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Specified descriptor matcher type is not supported." );
|
||||
break;
|
||||
}
|
||||
|
||||
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(name);
|
||||
matcher.addref();
|
||||
return (javaDescriptorMatcher*)((DescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
CV_WRAP void write( const string& fileName ) const
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::WRITE);
|
||||
((DescriptorMatcher*)this)->write(fs);
|
||||
fs.release();
|
||||
}
|
||||
|
||||
CV_WRAP void read( const string& fileName )
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::READ);
|
||||
((DescriptorMatcher*)this)->read(fs.root());
|
||||
fs.release();
|
||||
}
|
||||
};
|
||||
|
||||
class CV_EXPORTS_AS(DescriptorExtractor) javaDescriptorExtractor : public DescriptorExtractor
|
||||
{
|
||||
public:
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
CV_WRAP void compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
|
||||
CV_WRAP void compute( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, CV_OUT vector<Mat>& descriptors ) const;
|
||||
CV_WRAP virtual int descriptorSize() const;
|
||||
CV_WRAP virtual int descriptorType() const;
|
||||
|
||||
CV_WRAP virtual bool empty() const;
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
SIFT = 1,
|
||||
SURF = 2,
|
||||
ORB = 3,
|
||||
BRIEF = 4,
|
||||
|
||||
|
||||
OPPONENTEXTRACTOR = 1000,
|
||||
|
||||
|
||||
|
||||
OPPONENT_SIFT = OPPONENTEXTRACTOR + SIFT,
|
||||
OPPONENT_SURF = OPPONENTEXTRACTOR + SURF,
|
||||
OPPONENT_ORB = OPPONENTEXTRACTOR + ORB,
|
||||
OPPONENT_BRIEF = OPPONENTEXTRACTOR + BRIEF
|
||||
};
|
||||
|
||||
//supported SIFT, SURF, ORB, BRIEF, Opponent(XXXX)
|
||||
//not supported: Calonder
|
||||
CV_WRAP static javaDescriptorExtractor* create( int extractorType )
|
||||
{
|
||||
string name;
|
||||
|
||||
if (extractorType > OPPONENTEXTRACTOR)
|
||||
{
|
||||
name = "Opponent";
|
||||
extractorType -= OPPONENTEXTRACTOR;
|
||||
}
|
||||
|
||||
switch(extractorType)
|
||||
{
|
||||
case SIFT:
|
||||
name += "SIFT";
|
||||
break;
|
||||
case SURF:
|
||||
name += "SURF";
|
||||
break;
|
||||
case ORB:
|
||||
name += "ORB";
|
||||
break;
|
||||
case BRIEF:
|
||||
name += "BRIEF";
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Specified descriptor extractor type is not supported." );
|
||||
break;
|
||||
}
|
||||
|
||||
Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create(name);
|
||||
extractor.addref();
|
||||
return (javaDescriptorExtractor*)((DescriptorExtractor*) extractor);
|
||||
}
|
||||
|
||||
CV_WRAP void write( const string& fileName ) const
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::WRITE);
|
||||
((DescriptorExtractor*)this)->write(fs);
|
||||
fs.release();
|
||||
}
|
||||
|
||||
CV_WRAP void read( const string& fileName )
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::READ);
|
||||
((DescriptorExtractor*)this)->read(fs.root());
|
||||
fs.release();
|
||||
}
|
||||
};
|
||||
|
||||
class CV_EXPORTS_AS(GenericDescriptorMatcher) javaGenericDescriptorMatcher : public GenericDescriptorMatcher
|
||||
{
|
||||
public:
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
CV_WRAP virtual void add( const vector<Mat>& images,
|
||||
vector<vector<KeyPoint> >& keypoints );
|
||||
CV_WRAP const vector<Mat>& getTrainImages() const;
|
||||
CV_WRAP const vector<vector<KeyPoint> >& getTrainKeypoints() const;
|
||||
CV_WRAP virtual void clear();
|
||||
CV_WRAP virtual bool isMaskSupported();
|
||||
CV_WRAP virtual void train();
|
||||
CV_WRAP void classify( const Mat& queryImage, CV_IN_OUT vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints ) const;
|
||||
CV_WRAP void classify( const Mat& queryImage, CV_IN_OUT vector<KeyPoint>& queryKeypoints );
|
||||
CV_WRAP void match( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
|
||||
CV_OUT vector<DMatch>& matches, const Mat& mask=Mat() ) const;
|
||||
CV_WRAP void knnMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
|
||||
CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void radiusMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
|
||||
CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void match( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
CV_OUT vector<DMatch>& matches, const vector<Mat>& masks=vector<Mat>() );
|
||||
CV_WRAP void knnMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
CV_WRAP void radiusMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
CV_WRAP virtual bool empty() const;
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
ONEWAY = 1,
|
||||
FERN = 2
|
||||
};
|
||||
|
||||
CV_WRAP_AS(clone) javaGenericDescriptorMatcher* jclone( bool emptyTrainData=false ) const
|
||||
{
|
||||
Ptr<GenericDescriptorMatcher> matcher = this->clone(emptyTrainData);
|
||||
matcher.addref();
|
||||
return (javaGenericDescriptorMatcher*)((GenericDescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
//supported: OneWay, Fern
|
||||
//unsupported: Vector
|
||||
CV_WRAP static javaGenericDescriptorMatcher* create( int matcherType )
|
||||
{
|
||||
string name;
|
||||
|
||||
switch(matcherType)
|
||||
{
|
||||
case ONEWAY:
|
||||
name = "ONEWAY";
|
||||
break;
|
||||
case FERN:
|
||||
name = "FERN";
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Specified generic descriptor matcher type is not supported." );
|
||||
break;
|
||||
}
|
||||
|
||||
Ptr<GenericDescriptorMatcher> matcher = GenericDescriptorMatcher::create(name);
|
||||
matcher.addref();
|
||||
return (javaGenericDescriptorMatcher*)((GenericDescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
CV_WRAP void write( const string& fileName ) const
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::WRITE);
|
||||
((GenericDescriptorMatcher*)this)->write(fs);
|
||||
fs.release();
|
||||
}
|
||||
|
||||
CV_WRAP void read( const string& fileName )
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::READ);
|
||||
((GenericDescriptorMatcher*)this)->read(fs.root());
|
||||
fs.release();
|
||||
}
|
||||
};
|
||||
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
enum
|
||||
{
|
||||
DRAW_OVER_OUTIMG = 1, // Output image matrix will not be created (Mat::create).
|
||||
// Matches will be drawn on existing content of output image.
|
||||
NOT_DRAW_SINGLE_POINTS = 2, // Single keypoints will not be drawn.
|
||||
DRAW_RICH_KEYPOINTS = 4 // For each keypoint the circle around keypoint with keypoint size and
|
||||
// orientation will be drawn.
|
||||
};
|
||||
|
||||
// Draw keypoints.
|
||||
CV_EXPORTS_W void drawKeypoints( const Mat& image, const vector<KeyPoint>& keypoints, Mat& outImage,
|
||||
const Scalar& color=Scalar::all(-1), int flags=0 );
|
||||
|
||||
// Draws matches of keypints from two images on output image.
|
||||
CV_EXPORTS_W void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
|
||||
const Mat& img2, const vector<KeyPoint>& keypoints2,
|
||||
const vector<DMatch>& matches1to2, Mat& outImg,
|
||||
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
|
||||
const vector<char>& matchesMask=vector<char>(), int flags=0 );
|
||||
|
||||
CV_EXPORTS_AS(drawMatches2) void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
|
||||
const Mat& img2, const vector<KeyPoint>& keypoints2,
|
||||
const vector<vector<DMatch> >& matches1to2, Mat& outImg,
|
||||
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
|
||||
const vector<vector<char> >& matchesMask=vector<vector<char> >(), int flags=0);
|
||||
|
||||
#endif
|
||||
|
||||
} //cv
|
||||
|
||||
#endif // HAVE_OPENCV_FEATURES2D
|
||||
|
||||
#endif // __OPENCV_FEATURES_2D_MANUAL_HPP__
|
59
modules/java/generator/src/cpp/jni_part.cpp
Normal file
59
modules/java/generator/src/cpp/jni_part.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
# include "opencv2/nonfree/nonfree.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
# include "opencv2/features2d/features2d.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
# include "opencv2/video/video.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_ML
|
||||
# include "opencv2/ml/ml.hpp"
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JNI_OnLoad(JavaVM* vm, void* )
|
||||
{
|
||||
JNIEnv* env;
|
||||
if (vm->GetEnv((void**) &env, JNI_VERSION_1_6) != JNI_OK)
|
||||
return -1;
|
||||
|
||||
bool init = true;
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
init &= cv::initModule_nonfree();
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
init &= cv::initModule_features2d();
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
init &= cv::initModule_video();
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_ML
|
||||
init &= cv::initModule_ml();
|
||||
#endif
|
||||
|
||||
if(!init)
|
||||
return -1;
|
||||
|
||||
/* get class with (*env)->FindClass */
|
||||
/* register methods with (*env)->RegisterNatives */
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNI_OnUnload(JavaVM*, void*)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
|
||||
} // extern "C"
|
144
modules/java/generator/src/cpp/utils.cpp
Normal file
144
modules/java/generator/src/cpp/utils.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
|
||||
#include <android/bitmap.h>
|
||||
|
||||
#include <android/log.h>
|
||||
#define LOG_TAG "org.opencv.android.Utils"
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||
#ifdef DEBUG
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
||||
#else //!DEBUG
|
||||
#define LOGD(...)
|
||||
#endif //DEBUG
|
||||
|
||||
using namespace cv;
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: org_opencv_android_Utils
|
||||
* Method: void nBitmapToMat(Bitmap b, long m_addr)
|
||||
*/
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nBitmapToMat
|
||||
(JNIEnv * env, jclass, jobject bitmap, jlong m_addr);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nBitmapToMat
|
||||
(JNIEnv * env, jclass, jobject bitmap, jlong m_addr)
|
||||
{
|
||||
AndroidBitmapInfo info;
|
||||
void* pixels = 0;
|
||||
Mat& dst = *((Mat*)m_addr);
|
||||
|
||||
try {
|
||||
LOGD("nBitmapToMat");
|
||||
CV_Assert( AndroidBitmap_getInfo(env, bitmap, &info) >= 0 );
|
||||
CV_Assert( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 ||
|
||||
info.format == ANDROID_BITMAP_FORMAT_RGB_565 );
|
||||
CV_Assert( AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 );
|
||||
CV_Assert( pixels );
|
||||
dst.create(info.height, info.width, CV_8UC4);
|
||||
if( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 )
|
||||
{
|
||||
LOGD("nBitmapToMat: RGBA_8888 -> CV_8UC4");
|
||||
Mat tmp(info.height, info.width, CV_8UC4, pixels);
|
||||
tmp.copyTo(dst);
|
||||
} else {
|
||||
// info.format == ANDROID_BITMAP_FORMAT_RGB_565
|
||||
LOGD("nBitmapToMat: RGB_565 -> CV_8UC4");
|
||||
Mat tmp(info.height, info.width, CV_8UC2, pixels);
|
||||
cvtColor(tmp, dst, CV_BGR5652RGBA);
|
||||
}
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
return;
|
||||
} catch(cv::Exception e) {
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
LOGE("nBitmapToMat catched cv::Exception: %s", e.what());
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return;
|
||||
} catch (...) {
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
LOGE("nBitmapToMat catched unknown exception (...)");
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {nBitmapToMat}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_opencv_android_Utils
|
||||
* Method: void nMatToBitmap(long m_addr, Bitmap b)
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nMatToBitmap
|
||||
(JNIEnv * env, jclass, jlong m_addr, jobject bitmap);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nMatToBitmap
|
||||
(JNIEnv * env, jclass, jlong m_addr, jobject bitmap)
|
||||
{
|
||||
AndroidBitmapInfo info;
|
||||
void* pixels = 0;
|
||||
Mat& dst = *((Mat*)m_addr);
|
||||
|
||||
try {
|
||||
LOGD("nMatToBitmap");
|
||||
CV_Assert( AndroidBitmap_getInfo(env, bitmap, &info) >= 0 );
|
||||
CV_Assert( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 ||
|
||||
info.format == ANDROID_BITMAP_FORMAT_RGB_565 );
|
||||
CV_Assert( dst.dims == 2 && info.height == (uint32_t)dst.rows && info.width == (uint32_t)dst.cols );
|
||||
CV_Assert( dst.type() == CV_8UC1 || dst.type() == CV_8UC3 || dst.type() == CV_8UC4 );
|
||||
CV_Assert( AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 );
|
||||
CV_Assert( pixels );
|
||||
if( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 )
|
||||
{
|
||||
Mat tmp(info.height, info.width, CV_8UC4, pixels);
|
||||
if(dst.type() == CV_8UC1)
|
||||
{
|
||||
LOGD("nMatToBitmap: CV_8UC1 -> RGBA_8888");
|
||||
cvtColor(dst, tmp, CV_GRAY2RGBA);
|
||||
} else if(dst.type() == CV_8UC3){
|
||||
LOGD("nMatToBitmap: CV_8UC3 -> RGBA_8888");
|
||||
cvtColor(dst, tmp, CV_RGB2RGBA);
|
||||
} else if(dst.type() == CV_8UC4){
|
||||
LOGD("nMatToBitmap: CV_8UC4 -> RGBA_8888");
|
||||
dst.copyTo(tmp);
|
||||
}
|
||||
} else {
|
||||
// info.format == ANDROID_BITMAP_FORMAT_RGB_565
|
||||
Mat tmp(info.height, info.width, CV_8UC2, pixels);
|
||||
if(dst.type() == CV_8UC1)
|
||||
{
|
||||
LOGD("nMatToBitmap: CV_8UC1 -> RGB_565");
|
||||
cvtColor(dst, tmp, CV_GRAY2BGR565);
|
||||
} else if(dst.type() == CV_8UC3){
|
||||
LOGD("nMatToBitmap: CV_8UC3 -> RGB_565");
|
||||
cvtColor(dst, tmp, CV_RGB2BGR565);
|
||||
} else if(dst.type() == CV_8UC4){
|
||||
LOGD("nMatToBitmap: CV_8UC4 -> RGB_565");
|
||||
cvtColor(dst, tmp, CV_RGBA2BGR565);
|
||||
}
|
||||
}
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
return;
|
||||
} catch(cv::Exception e) {
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
LOGE("nMatToBitmap catched cv::Exception: %s", e.what());
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return;
|
||||
} catch (...) {
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
LOGE("nMatToBitmap catched unknown exception (...)");
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {nMatToBitmap}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // extern "C"
|
Reference in New Issue
Block a user