Path: blob/master/modules/java/generator/src/cpp/Mat.cpp
16354 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html34#include "opencv2/core.hpp"56#define LOG_TAG "org.opencv.core.Mat"7#include "common.h"89using namespace cv;1011/// throw java exception12static void throwJavaException(JNIEnv *env, const std::exception *e, const char *method) {13std::string what = "unknown exception";14jclass je = 0;1516if(e) {17std::string exception_type = "std::exception";1819if(dynamic_cast<const cv::Exception*>(e)) {20exception_type = "cv::Exception";21je = env->FindClass("org/opencv/core/CvException");22}2324what = exception_type + ": " + e->what();25}2627if(!je) je = env->FindClass("java/lang/Exception");28env->ThrowNew(je, what.c_str());2930LOGE("%s caught %s", method, what.c_str());31CV_UNUSED(method); // avoid "unused" warning32}3334extern "C" {353637//38// MatXXX::MatXXX()39//404142JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__43(JNIEnv*, jclass);4445JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__46(JNIEnv*, jclass)47{48LOGD("Mat::n_1Mat__()");49return (jlong) new cv::Mat();50}51525354//55// Mat::Mat(int rows, int cols, int type, void* data)56//5758JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIILjava_nio_ByteBuffer_259(JNIEnv* env, jclass, jint rows, jint cols, jint type, jobject data);6061JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIILjava_nio_ByteBuffer_262(JNIEnv* env, jclass, jint rows, jint cols, jint type, jobject data)63{64static const char method_name[] = "Mat::n_1Mat__IIILByteBuffer()";65try {66LOGD("%s", method_name);67return (jlong) new Mat( rows, cols, type, (void*)env->GetDirectBufferAddress(data) );68} catch(const std::exception &e) {69throwJavaException(env, &e, method_name);70} catch (...) {71throwJavaException(env, 0, method_name);72}7374return 0;75}76777879//80// Mat::Mat(int rows, int cols, int type)81//8283JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__III84(JNIEnv* env, jclass, jint rows, jint cols, jint type);8586JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__III87(JNIEnv* env, jclass, jint rows, jint cols, jint type)88{89static const char method_name[] = "Mat::n_1Mat__III()";90try {91LOGD("%s", method_name);92return (jlong) new Mat( rows, cols, type );93} catch(const std::exception &e) {94throwJavaException(env, &e, method_name);95} catch (...) {96throwJavaException(env, 0, method_name);97}9899return 0;100}101102103104//105// Mat::Mat(Size size, int type)106//107108JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDI109(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);110111JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDI112(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)113{114static const char method_name[] = "Mat::n_1Mat__DDI()";115try {116LOGD("%s", method_name);117Size size((int)size_width, (int)size_height);118return (jlong) new Mat( size, type );119} catch(const std::exception &e) {120throwJavaException(env, &e, method_name);121} catch (...) {122throwJavaException(env, 0, method_name);123}124125return 0;126}127128129130//131// Mat::Mat(int rows, int cols, int type, Scalar s)132//133134JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIIDDDD135(JNIEnv* env, jclass, jint rows, jint cols, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3);136137138JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIIDDDD139(JNIEnv* env, jclass, jint rows, jint cols, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3)140{141static const char method_name[] = "Mat::n_1Mat__IIIDDDD()";142try {143LOGD("%s", method_name);144Scalar s(s_val0, s_val1, s_val2, s_val3);145return (jlong) new Mat( rows, cols, type, s );146} catch(const std::exception &e) {147throwJavaException(env, &e, method_name);148} catch (...) {149throwJavaException(env, 0, method_name);150}151152return 0;153}154155156157//158// Mat::Mat(Size size, int type, Scalar s)159//160161JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDIDDDD162(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3);163164JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDIDDDD165(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3)166{167static const char method_name[] = "Mat::n_1Mat__DDIDDDD()";168try {169LOGD("%s", method_name);170Size size((int)size_width, (int)size_height);171Scalar s(s_val0, s_val1, s_val2, s_val3);172return (jlong) new Mat( size, type, s );173} catch(const std::exception &e) {174throwJavaException(env, &e, method_name);175} catch (...) {176throwJavaException(env, 0, method_name);177}178179return 0;180}181182183184//185// Mat::Mat(Mat m, Range rowRange, Range colRange = Range::all())186//187188JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JIIII189(JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end);190191JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JIIII192(JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end)193{194static const char method_name[] = "Mat::n_1Mat__JIIII()";195try {196LOGD("%s", method_name);197Range rowRange(rowRange_start, rowRange_end);198Range colRange(colRange_start, colRange_end);199return (jlong) new Mat( (*(Mat*)m_nativeObj), rowRange, colRange );200} catch(const std::exception &e) {201throwJavaException(env, &e, method_name);202} catch (...) {203throwJavaException(env, 0, method_name);204}205206return 0;207}208209210JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JII211(JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end);212213214JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JII215(JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end)216{217static const char method_name[] = "Mat::n_1Mat__JII()";218try {219LOGD("%s", method_name);220Range rowRange(rowRange_start, rowRange_end);221return (jlong) new Mat( (*(Mat*)m_nativeObj), rowRange );222} catch(const std::exception &e) {223throwJavaException(env, &e, method_name);224} catch (...) {225throwJavaException(env, 0, method_name);226}227228return 0;229}230231232//233// Mat Mat::adjustROI(int dtop, int dbottom, int dleft, int dright)234//235236JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1adjustROI237(JNIEnv* env, jclass, jlong self, jint dtop, jint dbottom, jint dleft, jint dright);238239JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1adjustROI240(JNIEnv* env, jclass, jlong self, jint dtop, jint dbottom, jint dleft, jint dright)241{242static const char method_name[] = "Mat::n_1adjustROI()";243try {244LOGD("%s", method_name);245Mat* me = (Mat*) self; //TODO: check for NULL246Mat _retval_ = me->adjustROI( dtop, dbottom, dleft, dright );247return (jlong) new Mat(_retval_);248} catch(const std::exception &e) {249throwJavaException(env, &e, method_name);250} catch (...) {251throwJavaException(env, 0, method_name);252}253254return 0;255}256257258259//260// void Mat::assignTo(Mat m, int type = -1)261//262263JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJI264(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint type);265266JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJI267(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint type)268{269static const char method_name[] = "Mat::n_1assignTo__JJI()";270try {271LOGD("%s", method_name);272Mat* me = (Mat*) self; //TODO: check for NULL273me->assignTo( (*(Mat*)m_nativeObj), type );274} catch(const std::exception &e) {275throwJavaException(env, &e, method_name);276} catch (...) {277throwJavaException(env, 0, method_name);278}279}280281282JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJ283(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);284285JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJ286(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)287{288static const char method_name[] = "Mat::n_1assignTo__JJ()";289try {290LOGD("%s", method_name);291Mat* me = (Mat*) self; //TODO: check for NULL292me->assignTo( (*(Mat*)m_nativeObj) );293} catch(const std::exception &e) {294throwJavaException(env, &e, method_name);295} catch (...) {296throwJavaException(env, 0, method_name);297}298}299300301302//303// int Mat::channels()304//305306JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1channels307(JNIEnv* env, jclass, jlong self);308309JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1channels310(JNIEnv* env, jclass, jlong self)311{312static const char method_name[] = "Mat::n_1channels()";313try {314LOGD("%s", method_name);315Mat* me = (Mat*) self; //TODO: check for NULL316return me->channels( );317} catch(const std::exception &e) {318throwJavaException(env, &e, method_name);319} catch (...) {320throwJavaException(env, 0, method_name);321}322323return 0;324}325326327328//329// int Mat::checkVector(int elemChannels, int depth = -1, bool requireContinuous = true)330//331332JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JIIZ333(JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth, jboolean requireContinuous);334335JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JIIZ336(JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth, jboolean requireContinuous)337{338static const char method_name[] = "Mat::n_1checkVector__JIIZ()";339try {340LOGD("%s", method_name);341Mat* me = (Mat*) self; //TODO: check for NULL342return me->checkVector( elemChannels, depth, requireContinuous );343} catch(const std::exception &e) {344throwJavaException(env, &e, method_name);345} catch (...) {346throwJavaException(env, 0, method_name);347}348349return 0;350}351352353354JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JII355(JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth);356357JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JII358(JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth)359{360static const char method_name[] = "Mat::n_1checkVector__JII()";361try {362LOGD("%s", method_name);363Mat* me = (Mat*) self; //TODO: check for NULL364return me->checkVector( elemChannels, depth );365} catch(const std::exception &e) {366throwJavaException(env, &e, method_name);367} catch (...) {368throwJavaException(env, 0, method_name);369}370371return 0;372}373374375JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JI376(JNIEnv* env, jclass, jlong self, jint elemChannels);377378379JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JI380(JNIEnv* env, jclass, jlong self, jint elemChannels)381{382static const char method_name[] = "Mat::n_1checkVector__JI()";383try {384LOGD("%s", method_name);385Mat* me = (Mat*) self; //TODO: check for NULL386return me->checkVector( elemChannels );387} catch(const std::exception &e) {388throwJavaException(env, &e, method_name);389} catch (...) {390throwJavaException(env, 0, method_name);391}392393return 0;394}395396397398//399// Mat Mat::clone()400//401402JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1clone403(JNIEnv* env, jclass, jlong self);404405406JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1clone407(JNIEnv* env, jclass, jlong self)408{409static const char method_name[] = "Mat::n_1clone()";410try {411LOGD("%s", method_name);412Mat* me = (Mat*) self; //TODO: check for NULL413Mat _retval_ = me->clone( );414return (jlong) new Mat(_retval_);415} catch(const std::exception &e) {416throwJavaException(env, &e, method_name);417} catch (...) {418throwJavaException(env, 0, method_name);419}420421return 0;422}423424425426//427// Mat Mat::col(int x)428//429430JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1col431(JNIEnv* env, jclass, jlong self, jint x);432433JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1col434(JNIEnv* env, jclass, jlong self, jint x)435{436static const char method_name[] = "Mat::n_1col()";437try {438LOGD("%s", method_name);439Mat* me = (Mat*) self; //TODO: check for NULL440Mat _retval_ = me->col( x );441return (jlong) new Mat(_retval_);442} catch(const std::exception &e) {443throwJavaException(env, &e, method_name);444} catch (...) {445throwJavaException(env, 0, method_name);446}447448return 0;449}450451452453//454// Mat Mat::colRange(int startcol, int endcol)455//456457JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1colRange458(JNIEnv* env, jclass, jlong self, jint startcol, jint endcol);459460JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1colRange461(JNIEnv* env, jclass, jlong self, jint startcol, jint endcol)462{463static const char method_name[] = "Mat::n_1colRange()";464try {465LOGD("%s", method_name);466Mat* me = (Mat*) self; //TODO: check for NULL467Mat _retval_ = me->colRange( startcol, endcol );468return (jlong) new Mat(_retval_);469} catch(const std::exception &e) {470throwJavaException(env, &e, method_name);471} catch (...) {472throwJavaException(env, 0, method_name);473}474475return 0;476}477478479480//481// int Mat::dims()482//483484JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1dims485(JNIEnv* env, jclass, jlong self);486487JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1dims488(JNIEnv* env, jclass, jlong self)489{490static const char method_name[] = "Mat::n_1dims()";491try {492LOGD("%s", method_name);493Mat* me = (Mat*) self; //TODO: check for NULL494return me->dims;495} catch(const cv::Exception& e) {496throwJavaException(env, &e, method_name);497} catch (...) {498throwJavaException(env, 0, method_name);499}500501return 0;502}503504505506//507// int Mat::cols()508//509510JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1cols511(JNIEnv* env, jclass, jlong self);512513JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1cols514(JNIEnv* env, jclass, jlong self)515{516static const char method_name[] = "Mat::n_1cols()";517try {518LOGD("%s", method_name);519Mat* me = (Mat*) self; //TODO: check for NULL520return me->cols;521} catch(const std::exception &e) {522throwJavaException(env, &e, method_name);523} catch (...) {524throwJavaException(env, 0, method_name);525}526527return 0;528}529530531532//533// void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta = 0)534//535536JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJIDD537(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha, jdouble beta);538539JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJIDD540(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha, jdouble beta)541{542static const char method_name[] = "Mat::n_1convertTo__JJIDD()";543try {544LOGD("%s", method_name);545Mat* me = (Mat*) self; //TODO: check for NULL546Mat& m = *((Mat*)m_nativeObj);547me->convertTo( m, rtype, alpha, beta );548} catch(const std::exception &e) {549throwJavaException(env, &e, method_name);550} catch (...) {551throwJavaException(env, 0, method_name);552}553}554555556JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJID557(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha);558559JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJID560(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha)561{562static const char method_name[] = "Mat::n_1convertTo__JJID()";563try {564LOGD("%s", method_name);565Mat* me = (Mat*) self; //TODO: check for NULL566Mat& m = *((Mat*)m_nativeObj);567me->convertTo( m, rtype, alpha );568} catch(const std::exception &e) {569throwJavaException(env, &e, method_name);570} catch (...) {571throwJavaException(env, 0, method_name);572}573}574575576JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJI577(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype);578579JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJI580(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype)581{582static const char method_name[] = "Mat::n_1convertTo__JJI()";583try {584LOGD("%s", method_name);585Mat* me = (Mat*) self; //TODO: check for NULL586Mat& m = *((Mat*)m_nativeObj);587me->convertTo( m, rtype );588} catch(const std::exception &e) {589throwJavaException(env, &e, method_name);590} catch (...) {591throwJavaException(env, 0, method_name);592}593}594595596597//598// void Mat::copyTo(Mat& m)599//600601JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJ602(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);603604JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJ605(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)606{607static const char method_name[] = "Mat::n_1copyTo__JJ()";608try {609LOGD("%s", method_name);610Mat* me = (Mat*) self; //TODO: check for NULL611Mat& m = *((Mat*)m_nativeObj);612me->copyTo( m );613} catch(const std::exception &e) {614throwJavaException(env, &e, method_name);615} catch (...) {616throwJavaException(env, 0, method_name);617}618}619620621622//623// void Mat::copyTo(Mat& m, Mat mask)624//625626JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJJ627(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jlong mask_nativeObj);628629JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJJ630(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jlong mask_nativeObj)631{632static const char method_name[] = "Mat::n_1copyTo__JJJ()";633try {634LOGD("%s", method_name);635Mat* me = (Mat*) self; //TODO: check for NULL636Mat& m = *((Mat*)m_nativeObj);637Mat& mask = *((Mat*)mask_nativeObj);638me->copyTo( m, mask );639} catch(const std::exception &e) {640throwJavaException(env, &e, method_name);641} catch (...) {642throwJavaException(env, 0, method_name);643}644}645646647648//649// void Mat::create(int rows, int cols, int type)650//651652JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JIII653(JNIEnv* env, jclass, jlong self, jint rows, jint cols, jint type);654655JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JIII656(JNIEnv* env, jclass, jlong self, jint rows, jint cols, jint type)657{658static const char method_name[] = "Mat::n_1create__JIII()";659try {660LOGD("%s", method_name);661Mat* me = (Mat*) self; //TODO: check for NULL662me->create( rows, cols, type );663} catch(const std::exception &e) {664throwJavaException(env, &e, method_name);665} catch (...) {666throwJavaException(env, 0, method_name);667}668}669670671672//673// void Mat::create(Size size, int type)674//675676JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JDDI677(JNIEnv* env, jclass, jlong self, jdouble size_width, jdouble size_height, jint type);678679JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JDDI680(JNIEnv* env, jclass, jlong self, jdouble size_width, jdouble size_height, jint type)681{682static const char method_name[] = "Mat::n_1create__JDDI()";683try {684LOGD("%s", method_name);685Mat* me = (Mat*) self; //TODO: check for NULL686Size size((int)size_width, (int)size_height);687me->create( size, type );688} catch(const std::exception &e) {689throwJavaException(env, &e, method_name);690} catch (...) {691throwJavaException(env, 0, method_name);692}693}694695696697//698// Mat Mat::cross(Mat m)699//700701JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1cross702(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);703704JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1cross705(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)706{707static const char method_name[] = "Mat::n_1cross()";708try {709LOGD("%s", method_name);710Mat* me = (Mat*) self; //TODO: check for NULL711Mat& m = *((Mat*)m_nativeObj);712Mat _retval_ = me->cross( m );713return (jlong) new Mat(_retval_);714} catch(const std::exception &e) {715throwJavaException(env, &e, method_name);716} catch (...) {717throwJavaException(env, 0, method_name);718}719720return 0;721}722723724725//726// long Mat::dataAddr()727//728729JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1dataAddr730(JNIEnv*, jclass, jlong self);731732JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1dataAddr733(JNIEnv*, jclass, jlong self)734{735LOGD("Mat::n_1dataAddr()");736Mat* me = (Mat*) self; //TODO: check for NULL737return (jlong) me->data;738}739740741742//743// int Mat::depth()744//745746JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1depth747(JNIEnv* env, jclass, jlong self);748749JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1depth750(JNIEnv* env, jclass, jlong self)751{752static const char method_name[] = "Mat::n_1depth()";753try {754LOGD("%s", method_name);755Mat* me = (Mat*) self; //TODO: check for NULL756return me->depth( );757} catch(const std::exception &e) {758throwJavaException(env, &e, method_name);759} catch (...) {760throwJavaException(env, 0, method_name);761}762763return 0;764}765766767768//769// Mat Mat::diag(int d = 0)770//771772JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__JI773(JNIEnv* env, jclass, jlong self, jint d);774775JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__JI776(JNIEnv* env, jclass, jlong self, jint d)777{778static const char method_name[] = "Mat::n_1diag__JI()";779try {780LOGD("%s", method_name);781Mat* me = (Mat*) self; //TODO: check for NULL782Mat _retval_ = me->diag( d );783return (jlong) new Mat(_retval_);784} catch(const std::exception &e) {785throwJavaException(env, &e, method_name);786} catch (...) {787throwJavaException(env, 0, method_name);788}789790return 0;791}792793794795796//797// static Mat Mat::diag(Mat d)798//799800JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__J801(JNIEnv* env, jclass, jlong d_nativeObj);802803JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__J804(JNIEnv* env, jclass, jlong d_nativeObj)805{806static const char method_name[] = "Mat::n_1diag__J()";807try {808LOGD("%s", method_name);809Mat _retval_ = Mat::diag( (*(Mat*)d_nativeObj) );810return (jlong) new Mat(_retval_);811} catch(const std::exception &e) {812throwJavaException(env, &e, method_name);813} catch (...) {814throwJavaException(env, 0, method_name);815}816817return 0;818}819820821822//823// double Mat::dot(Mat m)824//825826JNIEXPORT jdouble JNICALL Java_org_opencv_core_Mat_n_1dot827(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);828829JNIEXPORT jdouble JNICALL Java_org_opencv_core_Mat_n_1dot830(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)831{832static const char method_name[] = "Mat::n_1dot()";833try {834LOGD("%s", method_name);835Mat* me = (Mat*) self; //TODO: check for NULL836Mat& m = *((Mat*)m_nativeObj);837return me->dot( m );838} catch(const std::exception &e) {839throwJavaException(env, &e, method_name);840} catch (...) {841throwJavaException(env, 0, method_name);842}843844return 0;845}846847848849//850// size_t Mat::elemSize()851//852853JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize854(JNIEnv* env, jclass, jlong self);855856JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize857(JNIEnv* env, jclass, jlong self)858{859static const char method_name[] = "Mat::n_1elemSize()";860try {861LOGD("%s", method_name);862Mat* me = (Mat*) self; //TODO: check for NULL863return me->elemSize( );864} catch(const std::exception &e) {865throwJavaException(env, &e, method_name);866} catch (...) {867throwJavaException(env, 0, method_name);868}869870return 0;871}872873874875//876// size_t Mat::elemSize1()877//878879JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize1880(JNIEnv* env, jclass, jlong self);881882JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize1883(JNIEnv* env, jclass, jlong self)884{885static const char method_name[] = "Mat::n_1elemSize1()";886try {887LOGD("%s", method_name);888Mat* me = (Mat*) self; //TODO: check for NULL889return me->elemSize1( );890} catch(const std::exception &e) {891throwJavaException(env, &e, method_name);892} catch (...) {893throwJavaException(env, 0, method_name);894}895896return 0;897}898899900901//902// bool Mat::empty()903//904905JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1empty906(JNIEnv* env, jclass, jlong self);907908JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1empty909(JNIEnv* env, jclass, jlong self)910{911static const char method_name[] = "Mat::n_1empty()";912try {913LOGD("%s", method_name);914Mat* me = (Mat*) self; //TODO: check for NULL915return me->empty( );916} catch(const std::exception &e) {917throwJavaException(env, &e, method_name);918} catch (...) {919throwJavaException(env, 0, method_name);920}921922return 0;923}924925926927//928// static Mat Mat::eye(int rows, int cols, int type)929//930931JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__III932(JNIEnv* env, jclass, jint rows, jint cols, jint type);933934JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__III935(JNIEnv* env, jclass, jint rows, jint cols, jint type)936{937static const char method_name[] = "Mat::n_1eye__III()";938try {939LOGD("%s", method_name);940Mat _retval_ = Mat::eye( rows, cols, type );941return (jlong) new Mat(_retval_);942} catch(const std::exception &e) {943throwJavaException(env, &e, method_name);944} catch (...) {945throwJavaException(env, 0, method_name);946}947948return 0;949}950951952953//954// static Mat Mat::eye(Size size, int type)955//956957JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__DDI958(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);959960JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__DDI961(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)962{963static const char method_name[] = "Mat::n_1eye__DDI()";964try {965LOGD("%s", method_name);966Size size((int)size_width, (int)size_height);967Mat _retval_ = Mat::eye( size, type );968return (jlong) new Mat(_retval_);969} catch(const std::exception &e) {970throwJavaException(env, &e, method_name);971} catch (...) {972throwJavaException(env, 0, method_name);973}974975return 0;976}977978979980//981// Mat Mat::inv(int method = DECOMP_LU)982//983984JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__JI985(JNIEnv* env, jclass, jlong self, jint method);986987JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__JI988(JNIEnv* env, jclass, jlong self, jint method)989{990static const char method_name[] = "Mat::n_1inv__JI()";991try {992LOGD("%s", method_name);993Mat* me = (Mat*) self; //TODO: check for NULL994Mat _retval_ = me->inv( method );995return (jlong) new Mat(_retval_);996} catch(const std::exception &e) {997throwJavaException(env, &e, method_name);998} catch (...) {999throwJavaException(env, 0, method_name);1000}10011002return 0;1003}100410051006JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__J1007(JNIEnv* env, jclass, jlong self);10081009JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__J1010(JNIEnv* env, jclass, jlong self)1011{1012static const char method_name[] = "Mat::n_1inv__J()";1013try {1014LOGD("%s", method_name);1015Mat* me = (Mat*) self; //TODO: check for NULL1016Mat _retval_ = me->inv( );1017return (jlong) new Mat(_retval_);1018} catch(const std::exception &e) {1019throwJavaException(env, &e, method_name);1020} catch (...) {1021throwJavaException(env, 0, method_name);1022}10231024return 0;1025}1026102710281029//1030// bool Mat::isContinuous()1031//10321033JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isContinuous1034(JNIEnv* env, jclass, jlong self);10351036JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isContinuous1037(JNIEnv* env, jclass, jlong self)1038{1039static const char method_name[] = "Mat::n_1isContinuous()";1040try {1041LOGD("%s", method_name);1042Mat* me = (Mat*) self; //TODO: check for NULL1043return me->isContinuous( );1044} catch(const std::exception &e) {1045throwJavaException(env, &e, method_name);1046} catch (...) {1047throwJavaException(env, 0, method_name);1048}10491050return 0;1051}1052105310541055//1056// bool Mat::isSubmatrix()1057//10581059JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isSubmatrix1060(JNIEnv* env, jclass, jlong self);10611062JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isSubmatrix1063(JNIEnv* env, jclass, jlong self)1064{1065static const char method_name[] = "Mat::n_1isSubmatrix()";1066try {1067LOGD("%s", method_name);1068Mat* me = (Mat*) self; //TODO: check for NULL1069return me->isSubmatrix( );1070} catch(const std::exception &e) {1071throwJavaException(env, &e, method_name);1072} catch (...) {1073throwJavaException(env, 0, method_name);1074}10751076return 0;1077}1078107910801081//1082// void Mat::locateROI(Size wholeSize, Point ofs)1083//10841085JNIEXPORT void JNICALL Java_org_opencv_core_Mat_locateROI_101086(JNIEnv* env, jclass, jlong self, jdoubleArray wholeSize_out, jdoubleArray ofs_out);10871088JNIEXPORT void JNICALL Java_org_opencv_core_Mat_locateROI_101089(JNIEnv* env, jclass, jlong self, jdoubleArray wholeSize_out, jdoubleArray ofs_out)1090{1091static const char method_name[] = "core::locateROI_10()";1092try {1093LOGD("%s", method_name);1094Mat* me = (Mat*) self; //TODO: check for NULL1095Size wholeSize;1096Point ofs;1097me->locateROI( wholeSize, ofs );1098jdouble tmp_wholeSize[2] = {(jdouble)wholeSize.width, (jdouble)wholeSize.height}; env->SetDoubleArrayRegion(wholeSize_out, 0, 2, tmp_wholeSize); jdouble tmp_ofs[2] = {(jdouble)ofs.x, (jdouble)ofs.y}; env->SetDoubleArrayRegion(ofs_out, 0, 2, tmp_ofs);1099} catch(const std::exception &e) {1100throwJavaException(env, &e, method_name);1101} catch (...) {1102throwJavaException(env, 0, method_name);1103}1104}1105110611071108//1109// Mat Mat::mul(Mat m, double scale = 1)1110//11111112JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJD1113(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jdouble scale);11141115JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJD1116(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jdouble scale)1117{1118static const char method_name[] = "Mat::n_1mul__JJD()";1119try {1120LOGD("%s", method_name);1121Mat* me = (Mat*) self; //TODO: check for NULL1122Mat& m = *((Mat*)m_nativeObj);1123Mat _retval_ = me->mul( m, scale );1124return (jlong) new Mat(_retval_);1125} catch(const std::exception &e) {1126throwJavaException(env, &e, method_name);1127} catch (...) {1128throwJavaException(env, 0, method_name);1129}11301131return 0;1132}1133113411351136JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJ1137(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);11381139JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJ1140(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)1141{1142static const char method_name[] = "Mat::n_1mul__JJ()";1143try {1144LOGD("%s", method_name);1145Mat* me = (Mat*) self; //TODO: check for NULL1146Mat& m = *((Mat*)m_nativeObj);1147Mat _retval_ = me->mul( m );1148return (jlong) new Mat(_retval_);1149} catch(const std::exception &e) {1150throwJavaException(env, &e, method_name);1151} catch (...) {1152throwJavaException(env, 0, method_name);1153}11541155return 0;1156}1157115811591160//1161// static Mat Mat::ones(int rows, int cols, int type)1162//11631164JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__III1165(JNIEnv* env, jclass, jint rows, jint cols, jint type);11661167JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__III1168(JNIEnv* env, jclass, jint rows, jint cols, jint type)1169{1170static const char method_name[] = "Mat::n_1ones__III()";1171try {1172LOGD("%s", method_name);1173Mat _retval_ = Mat::ones( rows, cols, type );1174return (jlong) new Mat(_retval_);1175} catch(const std::exception &e) {1176throwJavaException(env, &e, method_name);1177} catch (...) {1178throwJavaException(env, 0, method_name);1179}11801181return 0;1182}1183118411851186//1187// static Mat Mat::ones(Size size, int type)1188//11891190JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__DDI1191(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);11921193JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__DDI1194(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)1195{1196static const char method_name[] = "Mat::n_1ones__DDI()";1197try {1198LOGD("%s", method_name);1199Size size((int)size_width, (int)size_height);1200Mat _retval_ = Mat::ones( size, type );1201return (jlong) new Mat(_retval_);1202} catch(const std::exception &e) {1203throwJavaException(env, &e, method_name);1204} catch (...) {1205throwJavaException(env, 0, method_name);1206}12071208return 0;1209}1210121112121213//1214// void Mat::push_back(Mat m)1215//12161217JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1push_1back1218(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);12191220JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1push_1back1221(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)1222{1223static const char method_name[] = "Mat::n_1push_1back()";1224try {1225LOGD("%s", method_name);1226Mat* me = (Mat*) self; //TODO: check for NULL1227me->push_back( (*(Mat*)m_nativeObj) );1228} catch(const std::exception &e) {1229throwJavaException(env, &e, method_name);1230} catch (...) {1231throwJavaException(env, 0, method_name);1232}1233}1234123512361237//1238// void Mat::release()1239//12401241JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1release1242(JNIEnv* env, jclass, jlong self);12431244JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1release1245(JNIEnv* env, jclass, jlong self)1246{1247static const char method_name[] = "Mat::n_1release()";1248try {1249LOGD("%s", method_name);1250Mat* me = (Mat*) self; //TODO: check for NULL1251me->release( );1252} catch(const std::exception &e) {1253throwJavaException(env, &e, method_name);1254} catch (...) {1255throwJavaException(env, 0, method_name);1256}1257}1258125912601261//1262// Mat Mat::reshape(int cn, int rows = 0)1263//12641265JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JII1266(JNIEnv* env, jclass, jlong self, jint cn, jint rows);12671268JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JII1269(JNIEnv* env, jclass, jlong self, jint cn, jint rows)1270{1271static const char method_name[] = "Mat::n_1reshape__JII()";1272try {1273LOGD("%s", method_name);1274Mat* me = (Mat*) self; //TODO: check for NULL1275Mat _retval_ = me->reshape( cn, rows );1276return (jlong) new Mat(_retval_);1277} catch(const std::exception &e) {1278throwJavaException(env, &e, method_name);1279} catch (...) {1280throwJavaException(env, 0, method_name);1281}12821283return 0;1284}1285128612871288JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JI1289(JNIEnv* env, jclass, jlong self, jint cn);12901291JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JI1292(JNIEnv* env, jclass, jlong self, jint cn)1293{1294static const char method_name[] = "Mat::n_1reshape__JI()";1295try {1296LOGD("%s", method_name);1297Mat* me = (Mat*) self; //TODO: check for NULL1298Mat _retval_ = me->reshape( cn );1299return (jlong) new Mat(_retval_);1300} catch(const std::exception &e) {1301throwJavaException(env, &e, method_name);1302} catch (...) {1303throwJavaException(env, 0, method_name);1304}13051306return 0;1307}1308130913101311//1312// Mat Mat::row(int y)1313//13141315JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1row1316(JNIEnv* env, jclass, jlong self, jint y);13171318JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1row1319(JNIEnv* env, jclass, jlong self, jint y)1320{1321static const char method_name[] = "Mat::n_1row()";1322try {1323LOGD("%s", method_name);1324Mat* me = (Mat*) self; //TODO: check for NULL1325Mat _retval_ = me->row( y );1326return (jlong) new Mat(_retval_);1327} catch(const std::exception &e) {1328throwJavaException(env, &e, method_name);1329} catch (...) {1330throwJavaException(env, 0, method_name);1331}13321333return 0;1334}1335133613371338//1339// Mat Mat::rowRange(int startrow, int endrow)1340//13411342JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1rowRange1343(JNIEnv* env, jclass, jlong self, jint startrow, jint endrow);13441345JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1rowRange1346(JNIEnv* env, jclass, jlong self, jint startrow, jint endrow)1347{1348static const char method_name[] = "Mat::n_1rowRange()";1349try {1350LOGD("%s", method_name);1351Mat* me = (Mat*) self; //TODO: check for NULL1352Mat _retval_ = me->rowRange( startrow, endrow );1353return (jlong) new Mat(_retval_);1354} catch(const std::exception &e) {1355throwJavaException(env, &e, method_name);1356} catch (...) {1357throwJavaException(env, 0, method_name);1358}13591360return 0;1361}1362136313641365//1366// int Mat::rows()1367//13681369JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1rows1370(JNIEnv* env, jclass, jlong self);13711372JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1rows1373(JNIEnv* env, jclass, jlong self)1374{1375static const char method_name[] = "Mat::n_1rows()";1376try {1377LOGD("%s", method_name);1378Mat* me = (Mat*) self; //TODO: check for NULL1379return me->rows;1380} catch(const std::exception &e) {1381throwJavaException(env, &e, method_name);1382} catch (...) {1383throwJavaException(env, 0, method_name);1384}13851386return 0;1387}1388138913901391//1392// Mat Mat::operator =(Scalar s)1393//13941395JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDD1396(JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3);13971398JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDD1399(JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3)1400{1401static const char method_name[] = "Mat::n_1setTo__JDDDD()";1402try {1403LOGD("%s", method_name);1404Mat* me = (Mat*) self; //TODO: check for NULL1405Scalar s(s_val0, s_val1, s_val2, s_val3);1406Mat _retval_ = me->operator =( s );1407return (jlong) new Mat(_retval_);1408} catch(const std::exception &e) {1409throwJavaException(env, &e, method_name);1410} catch (...) {1411throwJavaException(env, 0, method_name);1412}14131414return 0;1415}1416141714181419//1420// Mat Mat::setTo(Scalar value, Mat mask = Mat())1421//14221423JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDDJ1424(JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3, jlong mask_nativeObj);14251426JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDDJ1427(JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3, jlong mask_nativeObj)1428{1429static const char method_name[] = "Mat::n_1setTo__JDDDDJ()";1430try {1431LOGD("%s", method_name);1432Mat* me = (Mat*) self; //TODO: check for NULL1433Scalar s(s_val0, s_val1, s_val2, s_val3);1434Mat& mask = *((Mat*)mask_nativeObj);1435Mat _retval_ = me->setTo( s, mask );1436return (jlong) new Mat(_retval_);1437} catch(const std::exception &e) {1438throwJavaException(env, &e, method_name);1439} catch (...) {1440throwJavaException(env, 0, method_name);1441}14421443return 0;1444}1445144614471448//1449// Mat Mat::setTo(Mat value, Mat mask = Mat())1450//14511452JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJJ1453(JNIEnv* env, jclass, jlong self, jlong value_nativeObj, jlong mask_nativeObj);14541455JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJJ1456(JNIEnv* env, jclass, jlong self, jlong value_nativeObj, jlong mask_nativeObj)1457{1458static const char method_name[] = "Mat::n_1setTo__JJJ()";1459try {1460LOGD("%s", method_name);1461Mat* me = (Mat*) self; //TODO: check for NULL1462Mat& value = *((Mat*)value_nativeObj);1463Mat& mask = *((Mat*)mask_nativeObj);1464Mat _retval_ = me->setTo( value, mask );1465return (jlong) new Mat(_retval_);1466} catch(const std::exception &e) {1467throwJavaException(env, &e, method_name);1468} catch (...) {1469throwJavaException(env, 0, method_name);1470}14711472return 0;1473}1474147514761477JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJ1478(JNIEnv* env, jclass, jlong self, jlong value_nativeObj);14791480JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJ1481(JNIEnv* env, jclass, jlong self, jlong value_nativeObj)1482{1483static const char method_name[] = "Mat::n_1setTo__JJ()";1484try {1485LOGD("%s", method_name);1486Mat* me = (Mat*) self; //TODO: check for NULL1487Mat& value = *((Mat*)value_nativeObj);1488Mat _retval_ = me->setTo( value );1489return (jlong) new Mat(_retval_);1490} catch(const std::exception &e) {1491throwJavaException(env, &e, method_name);1492} catch (...) {1493throwJavaException(env, 0, method_name);1494}14951496return 0;1497}1498149915001501//1502// Size Mat::size()1503//15041505JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_n_1size1506(JNIEnv* env, jclass, jlong self);15071508JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_n_1size1509(JNIEnv* env, jclass, jlong self)1510{1511static const char method_name[] = "Mat::n_1size()";1512try {1513LOGD("%s", method_name);1514Mat* me = (Mat*) self; //TODO: check for NULL1515Size _retval_ = me->size( );1516jdoubleArray _da_retval_ = env->NewDoubleArray(2);1517jdouble _tmp_retval_[2] = {(jdouble)_retval_.width, (jdouble)_retval_.height};1518env->SetDoubleArrayRegion(_da_retval_, 0, 2, _tmp_retval_);1519return _da_retval_;1520} catch(const std::exception &e) {1521throwJavaException(env, &e, method_name);1522} catch (...) {1523throwJavaException(env, 0, method_name);1524}15251526return 0;1527}1528152915301531//1532// size_t Mat::step1(int i = 0)1533//15341535JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__JI1536(JNIEnv* env, jclass, jlong self, jint i);15371538JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__JI1539(JNIEnv* env, jclass, jlong self, jint i)1540{1541static const char method_name[] = "Mat::n_1step1__JI()";1542try {1543LOGD("%s", method_name);1544Mat* me = (Mat*) self; //TODO: check for NULL1545return me->step1( i );1546} catch(const std::exception &e) {1547throwJavaException(env, &e, method_name);1548} catch (...) {1549throwJavaException(env, 0, method_name);1550}15511552return 0;1553}1554155515561557JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__J1558(JNIEnv* env, jclass, jlong self);15591560JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__J1561(JNIEnv* env, jclass, jlong self)1562{1563static const char method_name[] = "Mat::n_1step1__J()";1564try {1565LOGD("%s", method_name);1566Mat* me = (Mat*) self; //TODO: check for NULL1567return me->step1( );1568} catch(const std::exception &e) {1569throwJavaException(env, &e, method_name);1570} catch (...) {1571throwJavaException(env, 0, method_name);1572}15731574return 0;1575}15761577//1578// Mat Mat::operator()(Range rowRange, Range colRange)1579//15801581JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat_1rr1582(JNIEnv* env, jclass, jlong self, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end);15831584JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat_1rr1585(JNIEnv* env, jclass, jlong self, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end)1586{1587static const char method_name[] = "Mat::n_1submat_1rr()";1588try {1589LOGD("%s", method_name);1590Mat* me = (Mat*) self; //TODO: check for NULL1591Range rowRange(rowRange_start, rowRange_end);1592Range colRange(colRange_start, colRange_end);1593Mat _retval_ = me->operator()( rowRange, colRange );1594return (jlong) new Mat(_retval_);1595} catch(const std::exception &e) {1596throwJavaException(env, &e, method_name);1597} catch (...) {1598throwJavaException(env, 0, method_name);1599}16001601return 0;1602}1603160416051606//1607// Mat Mat::operator()(Rect roi)1608//16091610JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat1611(JNIEnv* env, jclass, jlong self, jint roi_x, jint roi_y, jint roi_width, jint roi_height);16121613JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat1614(JNIEnv* env, jclass, jlong self, jint roi_x, jint roi_y, jint roi_width, jint roi_height)1615{1616static const char method_name[] = "Mat::n_1submat()";1617try {1618LOGD("%s", method_name);1619Mat* me = (Mat*) self; //TODO: check for NULL1620Rect roi(roi_x, roi_y, roi_width, roi_height);1621Mat _retval_ = me->operator()( roi );1622return (jlong) new Mat(_retval_);1623} catch(const std::exception &e) {1624throwJavaException(env, &e, method_name);1625} catch (...) {1626throwJavaException(env, 0, method_name);1627}16281629return 0;1630}1631163216331634//1635// Mat Mat::t()1636//16371638JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1t1639(JNIEnv* env, jclass, jlong self);16401641JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1t1642(JNIEnv* env, jclass, jlong self)1643{1644static const char method_name[] = "Mat::n_1t()";1645try {1646LOGD("%s", method_name);1647Mat* me = (Mat*) self; //TODO: check for NULL1648Mat _retval_ = me->t( );1649return (jlong) new Mat(_retval_);1650} catch(const std::exception &e) {1651throwJavaException(env, &e, method_name);1652} catch (...) {1653throwJavaException(env, 0, method_name);1654}16551656return 0;1657}1658165916601661//1662// size_t Mat::total()1663//16641665JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1total1666(JNIEnv* env, jclass, jlong self);16671668JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1total1669(JNIEnv* env, jclass, jlong self)1670{1671static const char method_name[] = "Mat::n_1total()";1672try {1673LOGD("%s", method_name);1674Mat* me = (Mat*) self; //TODO: check for NULL1675return me->total( );1676} catch(const std::exception &e) {1677throwJavaException(env, &e, method_name);1678} catch (...) {1679throwJavaException(env, 0, method_name);1680}16811682return 0;1683}1684168516861687//1688// int Mat::type()1689//16901691JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1type1692(JNIEnv* env, jclass, jlong self);16931694JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1type1695(JNIEnv* env, jclass, jlong self)1696{1697static const char method_name[] = "Mat::n_1type()";1698try {1699LOGD("%s", method_name);1700Mat* me = (Mat*) self; //TODO: check for NULL1701return me->type( );1702} catch(const std::exception &e) {1703throwJavaException(env, &e, method_name);1704} catch (...) {1705throwJavaException(env, 0, method_name);1706}17071708return 0;1709}1710171117121713//1714// static Mat Mat::zeros(int rows, int cols, int type)1715//17161717JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__III1718(JNIEnv* env, jclass, jint rows, jint cols, jint type);17191720JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__III1721(JNIEnv* env, jclass, jint rows, jint cols, jint type)1722{1723static const char method_name[] = "Mat::n_1zeros__III()";1724try {1725LOGD("%s", method_name);1726Mat _retval_ = Mat::zeros( rows, cols, type );1727return (jlong) new Mat(_retval_);1728} catch(const std::exception &e) {1729throwJavaException(env, &e, method_name);1730} catch (...) {1731throwJavaException(env, 0, method_name);1732}17331734return 0;1735}1736173717381739//1740// static Mat Mat::zeros(Size size, int type)1741//17421743JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__DDI1744(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);17451746JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__DDI1747(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)1748{1749static const char method_name[] = "Mat::n_1zeros__DDI()";1750try {1751LOGD("%s", method_name);1752Size size((int)size_width, (int)size_height);1753Mat _retval_ = Mat::zeros( size, type );1754return (jlong) new Mat(_retval_);1755} catch(const std::exception &e) {1756throwJavaException(env, &e, method_name);1757} catch (...) {1758throwJavaException(env, 0, method_name);1759}17601761return 0;1762}1763176417651766//1767// native support for java finalize()1768// static void Mat::n_delete( __int64 self )1769//17701771JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1delete1772(JNIEnv*, jclass, jlong self);17731774JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1delete1775(JNIEnv*, jclass, jlong self)1776{1777delete (Mat*) self;1778}17791780} // extern "C"17811782namespace {1783/// map java-array-types to assigned data1784template<class T> struct JavaOpenCVTrait;17851786/// less typing for specialisations1787#define JOCvT(t,s,c1,c2) \1788template<> struct JavaOpenCVTrait<t##Array> { \1789typedef t value_type; /* type of array element */ \1790static const char get[]; /* name of getter */ \1791static const char put[]; /* name of putter */ \1792enum {cvtype_1 = c1, cvtype_2 = c2 }; /* allowed OpenCV-types */ \1793}; \1794const char JavaOpenCVTrait<t##Array>::get[] = "Mat::nGet" s "()"; \1795const char JavaOpenCVTrait<t##Array>::put[] = "Mat::nPut" s "()"17961797JOCvT(jbyte, "B", CV_8U, CV_8S);1798JOCvT(jshort, "S", CV_16U, CV_16S);1799JOCvT(jint, "I", CV_32S, CV_32S);1800JOCvT(jfloat, "F", CV_32F, CV_32F);1801JOCvT(jdouble, "D", CV_64F, CV_64F);1802#undef JOCvT1803}18041805template<typename T> static int mat_put(cv::Mat* m, int row, int col, int count, int offset, char* buff)1806{1807if(! m) return 0;1808if(! buff) return 0;18091810count *= sizeof(T);1811int rest = ((m->rows - row) * m->cols - col) * (int)m->elemSize();1812if(count>rest) count = rest;1813int res = count;18141815if( m->isContinuous() )1816{1817memcpy(m->ptr(row, col), buff + offset, count);1818} else {1819// row by row1820int num = (m->cols - col) * (int)m->elemSize(); // 1st partial row1821if(count<num) num = count;1822uchar* data = m->ptr(row++, col);1823while(count>0){1824memcpy(data, buff + offset, num);1825count -= num;1826buff += num;1827num = m->cols * (int)m->elemSize();1828if(count<num) num = count;1829data = m->ptr(row++, 0);1830}1831}1832return res;1833}18341835template<class ARRAY> static jint java_mat_put(JNIEnv* env, jlong self, jint row, jint col, jint count, jint offset, ARRAY vals)1836{1837static const char *method_name = JavaOpenCVTrait<ARRAY>::put;1838try {1839LOGD("%s", method_name);1840cv::Mat* me = (cv::Mat*) self;1841if(! self) return 0; // no native object behind1842if(me->depth() != JavaOpenCVTrait<ARRAY>::cvtype_1 && me->depth() != JavaOpenCVTrait<ARRAY>::cvtype_2) return 0; // incompatible type1843if(me->rows<=row || me->cols<=col) return 0; // indexes out of range18441845char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);1846int res = mat_put<typename JavaOpenCVTrait<ARRAY>::value_type>(me, row, col, count, offset, values);1847env->ReleasePrimitiveArrayCritical(vals, values, JNI_ABORT);1848return res;1849} catch(const std::exception &e) {1850throwJavaException(env, &e, method_name);1851} catch (...) {1852throwJavaException(env, 0, method_name);1853}18541855return 0;1856}18571858extern "C" {18591860JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutB1861(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals);18621863JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutB1864(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals)1865{1866return java_mat_put(env, self, row, col, count, 0, vals);1867}18681869JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutBwOffset1870(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jint offset, jbyteArray vals);18711872JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutBwOffset1873(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jint offset, jbyteArray vals)1874{1875return java_mat_put(env, self, row, col, count, offset, vals);1876}18771878JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutS1879(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals);18801881JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutS1882(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals)1883{1884return java_mat_put(env, self, row, col, count, 0, vals);1885}18861887JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutI1888(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals);18891890JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutI1891(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals)1892{1893return java_mat_put(env, self, row, col, count, 0, vals);1894}18951896JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutF1897(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals);18981899JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutF1900(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals)1901{1902return java_mat_put(env, self, row, col, count, 0, vals);1903}19041905// unlike other nPut()-s this one (with double[]) should convert input values to correct type1906#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); }19071908JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD1909(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals);19101911JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD1912(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals)1913{1914static const char* method_name = JavaOpenCVTrait<jdoubleArray>::put;1915try {1916LOGD("%s", method_name);1917cv::Mat* me = (cv::Mat*) self;1918if(!me || !me->data) return 0; // no native object behind1919if(me->rows<=row || me->cols<=col) return 0; // indexes out of range19201921int rest = ((me->rows - row) * me->cols - col) * me->channels();1922if(count>rest) count = rest;1923int res = count;1924double* values = (double*)env->GetPrimitiveArrayCritical(vals, 0);1925double* src = values;1926int r, c;1927for(c=col; c<me->cols && count>0; c++)1928{1929switch(me->depth()) {1930case CV_8U: PUT_ITEM(uchar, row, c); break;1931case CV_8S: PUT_ITEM(schar, row, c); break;1932case CV_16U: PUT_ITEM(ushort, row, c); break;1933case CV_16S: PUT_ITEM(short, row, c); break;1934case CV_32S: PUT_ITEM(int, row, c); break;1935case CV_32F: PUT_ITEM(float, row, c); break;1936case CV_64F: PUT_ITEM(double, row, c); break;1937}1938}19391940for(r=row+1; r<me->rows && count>0; r++)1941for(c=0; c<me->cols && count>0; c++)1942{1943switch(me->depth()) {1944case CV_8U: PUT_ITEM(uchar, r, c); break;1945case CV_8S: PUT_ITEM(schar, r, c); break;1946case CV_16U: PUT_ITEM(ushort, r, c); break;1947case CV_16S: PUT_ITEM(short, r, c); break;1948case CV_32S: PUT_ITEM(int, r, c); break;1949case CV_32F: PUT_ITEM(float, r, c); break;1950case CV_64F: PUT_ITEM(double, r, c); break;1951}1952}19531954env->ReleasePrimitiveArrayCritical(vals, values, 0);1955return res;1956} catch(const std::exception &e) {1957throwJavaException(env, &e, method_name);1958} catch (...) {1959throwJavaException(env, 0, method_name);1960}19611962return 0;1963}19641965} // extern "C"19661967template<typename T> static int mat_get(cv::Mat* m, int row, int col, int count, char* buff)1968{1969if(! m) return 0;1970if(! buff) return 0;19711972int bytesToCopy = count * sizeof(T);1973int bytesRestInMat = ((m->rows - row) * m->cols - col) * (int)m->elemSize();1974if(bytesToCopy > bytesRestInMat) bytesToCopy = bytesRestInMat;1975int res = bytesToCopy;19761977if( m->isContinuous() )1978{1979memcpy(buff, m->ptr(row, col), bytesToCopy);1980} else {1981// row by row1982int bytesInRow = (m->cols - col) * (int)m->elemSize(); // 1st partial row1983while(bytesToCopy > 0)1984{1985int len = std::min(bytesToCopy, bytesInRow);1986memcpy(buff, m->ptr(row, col), len);1987bytesToCopy -= len;1988buff += len;1989row++;1990col = 0;1991bytesInRow = m->cols * (int)m->elemSize();1992}1993}1994return res;1995}19961997template<class ARRAY> static jint java_mat_get(JNIEnv* env, jlong self, jint row, jint col, jint count, ARRAY vals) {1998static const char *method_name = JavaOpenCVTrait<ARRAY>::get;1999try {2000LOGD("%s", method_name);2001cv::Mat* me = (cv::Mat*) self;2002if(! self) return 0; // no native object behind2003if(me->depth() != JavaOpenCVTrait<ARRAY>::cvtype_1 && me->depth() != JavaOpenCVTrait<ARRAY>::cvtype_2) return 0; // incompatible type2004if(me->rows<=row || me->cols<=col) return 0; // indexes out of range20052006char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);2007int res = mat_get<typename JavaOpenCVTrait<ARRAY>::value_type>(me, row, col, count, values);2008env->ReleasePrimitiveArrayCritical(vals, values, 0);2009return res;2010} catch(const std::exception &e) {2011throwJavaException(env, &e, method_name);2012} catch (...) {2013throwJavaException(env, 0, method_name);2014}20152016return 0;2017}20182019extern "C" {20202021JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetB2022(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals);20232024JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetB2025(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals)2026{2027return java_mat_get(env, self, row, col, count, vals);2028}20292030JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetS2031(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals);20322033JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetS2034(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals)2035{2036return java_mat_get(env, self, row, col, count, vals);2037}20382039JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetI2040(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals);20412042JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetI2043(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals)2044{2045return java_mat_get(env, self, row, col, count, vals);2046}20472048JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetF2049(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals);20502051JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetF2052(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals)2053{2054return java_mat_get(env, self, row, col, count, vals);2055}20562057JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetD2058(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals);20592060JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetD2061(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals)2062{2063return java_mat_get(env, self, row, col, count, vals);2064}20652066JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nGet2067(JNIEnv* env, jclass, jlong self, jint row, jint col);20682069JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nGet2070(JNIEnv* env, jclass, jlong self, jint row, jint col)2071{2072static const char method_name[] = "Mat::nGet()";2073try {2074LOGD("%s", method_name);2075cv::Mat* me = (cv::Mat*) self;2076if(! self) return 0; // no native object behind2077if(me->rows<=row || me->cols<=col) return 0; // indexes out of range20782079jdoubleArray res = env->NewDoubleArray(me->channels());2080if(res){2081jdouble buff[CV_CN_MAX];//me->channels()2082int i;2083switch(me->depth()){2084case CV_8U: for(i=0; i<me->channels(); i++) buff[i] = *((unsigned char*) me->ptr(row, col) + i); break;2085case CV_8S: for(i=0; i<me->channels(); i++) buff[i] = *((signed char*) me->ptr(row, col) + i); break;2086case CV_16U: for(i=0; i<me->channels(); i++) buff[i] = *((unsigned short*)me->ptr(row, col) + i); break;2087case CV_16S: for(i=0; i<me->channels(); i++) buff[i] = *((signed short*) me->ptr(row, col) + i); break;2088case CV_32S: for(i=0; i<me->channels(); i++) buff[i] = *((int*) me->ptr(row, col) + i); break;2089case CV_32F: for(i=0; i<me->channels(); i++) buff[i] = *((float*) me->ptr(row, col) + i); break;2090case CV_64F: for(i=0; i<me->channels(); i++) buff[i] = *((double*) me->ptr(row, col) + i); break;2091}2092env->SetDoubleArrayRegion(res, 0, me->channels(), buff);2093}2094return res;2095} catch(const std::exception &e) {2096throwJavaException(env, &e, method_name);2097} catch (...) {2098throwJavaException(env, 0, method_name);2099}21002101return 0;2102}21032104JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump2105(JNIEnv *env, jclass, jlong self);21062107JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump2108(JNIEnv *env, jclass, jlong self)2109{2110static const char method_name[] = "Mat::nDump()";2111try {2112LOGD("%s", method_name);2113cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL2114String s;2115Ptr<Formatted> fmtd = Formatter::get()->format(*me);2116for(const char* str = fmtd->next(); str; str = fmtd->next())2117{2118s = s + String(str);2119}2120return env->NewStringUTF(s.c_str());2121} catch(const std::exception &e) {2122throwJavaException(env, &e, method_name);2123} catch (...) {2124throwJavaException(env, 0, method_name);2125}21262127return 0;2128}212921302131} // extern "C"213221332134