Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/java/generator/src/cpp/Mat.cpp
16354 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html
4
5
#include "opencv2/core.hpp"
6
7
#define LOG_TAG "org.opencv.core.Mat"
8
#include "common.h"
9
10
using namespace cv;
11
12
/// throw java exception
13
static void throwJavaException(JNIEnv *env, const std::exception *e, const char *method) {
14
std::string what = "unknown exception";
15
jclass je = 0;
16
17
if(e) {
18
std::string exception_type = "std::exception";
19
20
if(dynamic_cast<const cv::Exception*>(e)) {
21
exception_type = "cv::Exception";
22
je = env->FindClass("org/opencv/core/CvException");
23
}
24
25
what = exception_type + ": " + e->what();
26
}
27
28
if(!je) je = env->FindClass("java/lang/Exception");
29
env->ThrowNew(je, what.c_str());
30
31
LOGE("%s caught %s", method, what.c_str());
32
CV_UNUSED(method); // avoid "unused" warning
33
}
34
35
extern "C" {
36
37
38
//
39
// MatXXX::MatXXX()
40
//
41
42
43
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__
44
(JNIEnv*, jclass);
45
46
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__
47
(JNIEnv*, jclass)
48
{
49
LOGD("Mat::n_1Mat__()");
50
return (jlong) new cv::Mat();
51
}
52
53
54
55
//
56
// Mat::Mat(int rows, int cols, int type, void* data)
57
//
58
59
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIILjava_nio_ByteBuffer_2
60
(JNIEnv* env, jclass, jint rows, jint cols, jint type, jobject data);
61
62
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIILjava_nio_ByteBuffer_2
63
(JNIEnv* env, jclass, jint rows, jint cols, jint type, jobject data)
64
{
65
static const char method_name[] = "Mat::n_1Mat__IIILByteBuffer()";
66
try {
67
LOGD("%s", method_name);
68
return (jlong) new Mat( rows, cols, type, (void*)env->GetDirectBufferAddress(data) );
69
} catch(const std::exception &e) {
70
throwJavaException(env, &e, method_name);
71
} catch (...) {
72
throwJavaException(env, 0, method_name);
73
}
74
75
return 0;
76
}
77
78
79
80
//
81
// Mat::Mat(int rows, int cols, int type)
82
//
83
84
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__III
85
(JNIEnv* env, jclass, jint rows, jint cols, jint type);
86
87
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__III
88
(JNIEnv* env, jclass, jint rows, jint cols, jint type)
89
{
90
static const char method_name[] = "Mat::n_1Mat__III()";
91
try {
92
LOGD("%s", method_name);
93
return (jlong) new Mat( rows, cols, type );
94
} catch(const std::exception &e) {
95
throwJavaException(env, &e, method_name);
96
} catch (...) {
97
throwJavaException(env, 0, method_name);
98
}
99
100
return 0;
101
}
102
103
104
105
//
106
// Mat::Mat(Size size, int type)
107
//
108
109
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDI
110
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);
111
112
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDI
113
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)
114
{
115
static const char method_name[] = "Mat::n_1Mat__DDI()";
116
try {
117
LOGD("%s", method_name);
118
Size size((int)size_width, (int)size_height);
119
return (jlong) new Mat( size, type );
120
} catch(const std::exception &e) {
121
throwJavaException(env, &e, method_name);
122
} catch (...) {
123
throwJavaException(env, 0, method_name);
124
}
125
126
return 0;
127
}
128
129
130
131
//
132
// Mat::Mat(int rows, int cols, int type, Scalar s)
133
//
134
135
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIIDDDD
136
(JNIEnv* env, jclass, jint rows, jint cols, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3);
137
138
139
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIIDDDD
140
(JNIEnv* env, jclass, jint rows, jint cols, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3)
141
{
142
static const char method_name[] = "Mat::n_1Mat__IIIDDDD()";
143
try {
144
LOGD("%s", method_name);
145
Scalar s(s_val0, s_val1, s_val2, s_val3);
146
return (jlong) new Mat( rows, cols, type, s );
147
} catch(const std::exception &e) {
148
throwJavaException(env, &e, method_name);
149
} catch (...) {
150
throwJavaException(env, 0, method_name);
151
}
152
153
return 0;
154
}
155
156
157
158
//
159
// Mat::Mat(Size size, int type, Scalar s)
160
//
161
162
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDIDDDD
163
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3);
164
165
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDIDDDD
166
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3)
167
{
168
static const char method_name[] = "Mat::n_1Mat__DDIDDDD()";
169
try {
170
LOGD("%s", method_name);
171
Size size((int)size_width, (int)size_height);
172
Scalar s(s_val0, s_val1, s_val2, s_val3);
173
return (jlong) new Mat( size, type, s );
174
} catch(const std::exception &e) {
175
throwJavaException(env, &e, method_name);
176
} catch (...) {
177
throwJavaException(env, 0, method_name);
178
}
179
180
return 0;
181
}
182
183
184
185
//
186
// Mat::Mat(Mat m, Range rowRange, Range colRange = Range::all())
187
//
188
189
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JIIII
190
(JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end);
191
192
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JIIII
193
(JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end)
194
{
195
static const char method_name[] = "Mat::n_1Mat__JIIII()";
196
try {
197
LOGD("%s", method_name);
198
Range rowRange(rowRange_start, rowRange_end);
199
Range colRange(colRange_start, colRange_end);
200
return (jlong) new Mat( (*(Mat*)m_nativeObj), rowRange, colRange );
201
} catch(const std::exception &e) {
202
throwJavaException(env, &e, method_name);
203
} catch (...) {
204
throwJavaException(env, 0, method_name);
205
}
206
207
return 0;
208
}
209
210
211
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JII
212
(JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end);
213
214
215
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JII
216
(JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end)
217
{
218
static const char method_name[] = "Mat::n_1Mat__JII()";
219
try {
220
LOGD("%s", method_name);
221
Range rowRange(rowRange_start, rowRange_end);
222
return (jlong) new Mat( (*(Mat*)m_nativeObj), rowRange );
223
} catch(const std::exception &e) {
224
throwJavaException(env, &e, method_name);
225
} catch (...) {
226
throwJavaException(env, 0, method_name);
227
}
228
229
return 0;
230
}
231
232
233
//
234
// Mat Mat::adjustROI(int dtop, int dbottom, int dleft, int dright)
235
//
236
237
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1adjustROI
238
(JNIEnv* env, jclass, jlong self, jint dtop, jint dbottom, jint dleft, jint dright);
239
240
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1adjustROI
241
(JNIEnv* env, jclass, jlong self, jint dtop, jint dbottom, jint dleft, jint dright)
242
{
243
static const char method_name[] = "Mat::n_1adjustROI()";
244
try {
245
LOGD("%s", method_name);
246
Mat* me = (Mat*) self; //TODO: check for NULL
247
Mat _retval_ = me->adjustROI( dtop, dbottom, dleft, dright );
248
return (jlong) new Mat(_retval_);
249
} catch(const std::exception &e) {
250
throwJavaException(env, &e, method_name);
251
} catch (...) {
252
throwJavaException(env, 0, method_name);
253
}
254
255
return 0;
256
}
257
258
259
260
//
261
// void Mat::assignTo(Mat m, int type = -1)
262
//
263
264
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJI
265
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint type);
266
267
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJI
268
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint type)
269
{
270
static const char method_name[] = "Mat::n_1assignTo__JJI()";
271
try {
272
LOGD("%s", method_name);
273
Mat* me = (Mat*) self; //TODO: check for NULL
274
me->assignTo( (*(Mat*)m_nativeObj), type );
275
} catch(const std::exception &e) {
276
throwJavaException(env, &e, method_name);
277
} catch (...) {
278
throwJavaException(env, 0, method_name);
279
}
280
}
281
282
283
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJ
284
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
285
286
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJ
287
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
288
{
289
static const char method_name[] = "Mat::n_1assignTo__JJ()";
290
try {
291
LOGD("%s", method_name);
292
Mat* me = (Mat*) self; //TODO: check for NULL
293
me->assignTo( (*(Mat*)m_nativeObj) );
294
} catch(const std::exception &e) {
295
throwJavaException(env, &e, method_name);
296
} catch (...) {
297
throwJavaException(env, 0, method_name);
298
}
299
}
300
301
302
303
//
304
// int Mat::channels()
305
//
306
307
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1channels
308
(JNIEnv* env, jclass, jlong self);
309
310
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1channels
311
(JNIEnv* env, jclass, jlong self)
312
{
313
static const char method_name[] = "Mat::n_1channels()";
314
try {
315
LOGD("%s", method_name);
316
Mat* me = (Mat*) self; //TODO: check for NULL
317
return me->channels( );
318
} catch(const std::exception &e) {
319
throwJavaException(env, &e, method_name);
320
} catch (...) {
321
throwJavaException(env, 0, method_name);
322
}
323
324
return 0;
325
}
326
327
328
329
//
330
// int Mat::checkVector(int elemChannels, int depth = -1, bool requireContinuous = true)
331
//
332
333
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JIIZ
334
(JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth, jboolean requireContinuous);
335
336
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JIIZ
337
(JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth, jboolean requireContinuous)
338
{
339
static const char method_name[] = "Mat::n_1checkVector__JIIZ()";
340
try {
341
LOGD("%s", method_name);
342
Mat* me = (Mat*) self; //TODO: check for NULL
343
return me->checkVector( elemChannels, depth, requireContinuous );
344
} catch(const std::exception &e) {
345
throwJavaException(env, &e, method_name);
346
} catch (...) {
347
throwJavaException(env, 0, method_name);
348
}
349
350
return 0;
351
}
352
353
354
355
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JII
356
(JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth);
357
358
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JII
359
(JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth)
360
{
361
static const char method_name[] = "Mat::n_1checkVector__JII()";
362
try {
363
LOGD("%s", method_name);
364
Mat* me = (Mat*) self; //TODO: check for NULL
365
return me->checkVector( elemChannels, depth );
366
} catch(const std::exception &e) {
367
throwJavaException(env, &e, method_name);
368
} catch (...) {
369
throwJavaException(env, 0, method_name);
370
}
371
372
return 0;
373
}
374
375
376
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JI
377
(JNIEnv* env, jclass, jlong self, jint elemChannels);
378
379
380
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JI
381
(JNIEnv* env, jclass, jlong self, jint elemChannels)
382
{
383
static const char method_name[] = "Mat::n_1checkVector__JI()";
384
try {
385
LOGD("%s", method_name);
386
Mat* me = (Mat*) self; //TODO: check for NULL
387
return me->checkVector( elemChannels );
388
} catch(const std::exception &e) {
389
throwJavaException(env, &e, method_name);
390
} catch (...) {
391
throwJavaException(env, 0, method_name);
392
}
393
394
return 0;
395
}
396
397
398
399
//
400
// Mat Mat::clone()
401
//
402
403
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1clone
404
(JNIEnv* env, jclass, jlong self);
405
406
407
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1clone
408
(JNIEnv* env, jclass, jlong self)
409
{
410
static const char method_name[] = "Mat::n_1clone()";
411
try {
412
LOGD("%s", method_name);
413
Mat* me = (Mat*) self; //TODO: check for NULL
414
Mat _retval_ = me->clone( );
415
return (jlong) new Mat(_retval_);
416
} catch(const std::exception &e) {
417
throwJavaException(env, &e, method_name);
418
} catch (...) {
419
throwJavaException(env, 0, method_name);
420
}
421
422
return 0;
423
}
424
425
426
427
//
428
// Mat Mat::col(int x)
429
//
430
431
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1col
432
(JNIEnv* env, jclass, jlong self, jint x);
433
434
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1col
435
(JNIEnv* env, jclass, jlong self, jint x)
436
{
437
static const char method_name[] = "Mat::n_1col()";
438
try {
439
LOGD("%s", method_name);
440
Mat* me = (Mat*) self; //TODO: check for NULL
441
Mat _retval_ = me->col( x );
442
return (jlong) new Mat(_retval_);
443
} catch(const std::exception &e) {
444
throwJavaException(env, &e, method_name);
445
} catch (...) {
446
throwJavaException(env, 0, method_name);
447
}
448
449
return 0;
450
}
451
452
453
454
//
455
// Mat Mat::colRange(int startcol, int endcol)
456
//
457
458
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1colRange
459
(JNIEnv* env, jclass, jlong self, jint startcol, jint endcol);
460
461
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1colRange
462
(JNIEnv* env, jclass, jlong self, jint startcol, jint endcol)
463
{
464
static const char method_name[] = "Mat::n_1colRange()";
465
try {
466
LOGD("%s", method_name);
467
Mat* me = (Mat*) self; //TODO: check for NULL
468
Mat _retval_ = me->colRange( startcol, endcol );
469
return (jlong) new Mat(_retval_);
470
} catch(const std::exception &e) {
471
throwJavaException(env, &e, method_name);
472
} catch (...) {
473
throwJavaException(env, 0, method_name);
474
}
475
476
return 0;
477
}
478
479
480
481
//
482
// int Mat::dims()
483
//
484
485
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1dims
486
(JNIEnv* env, jclass, jlong self);
487
488
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1dims
489
(JNIEnv* env, jclass, jlong self)
490
{
491
static const char method_name[] = "Mat::n_1dims()";
492
try {
493
LOGD("%s", method_name);
494
Mat* me = (Mat*) self; //TODO: check for NULL
495
return me->dims;
496
} catch(const cv::Exception& e) {
497
throwJavaException(env, &e, method_name);
498
} catch (...) {
499
throwJavaException(env, 0, method_name);
500
}
501
502
return 0;
503
}
504
505
506
507
//
508
// int Mat::cols()
509
//
510
511
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1cols
512
(JNIEnv* env, jclass, jlong self);
513
514
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1cols
515
(JNIEnv* env, jclass, jlong self)
516
{
517
static const char method_name[] = "Mat::n_1cols()";
518
try {
519
LOGD("%s", method_name);
520
Mat* me = (Mat*) self; //TODO: check for NULL
521
return me->cols;
522
} catch(const std::exception &e) {
523
throwJavaException(env, &e, method_name);
524
} catch (...) {
525
throwJavaException(env, 0, method_name);
526
}
527
528
return 0;
529
}
530
531
532
533
//
534
// void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta = 0)
535
//
536
537
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJIDD
538
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha, jdouble beta);
539
540
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJIDD
541
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha, jdouble beta)
542
{
543
static const char method_name[] = "Mat::n_1convertTo__JJIDD()";
544
try {
545
LOGD("%s", method_name);
546
Mat* me = (Mat*) self; //TODO: check for NULL
547
Mat& m = *((Mat*)m_nativeObj);
548
me->convertTo( m, rtype, alpha, beta );
549
} catch(const std::exception &e) {
550
throwJavaException(env, &e, method_name);
551
} catch (...) {
552
throwJavaException(env, 0, method_name);
553
}
554
}
555
556
557
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJID
558
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha);
559
560
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJID
561
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha)
562
{
563
static const char method_name[] = "Mat::n_1convertTo__JJID()";
564
try {
565
LOGD("%s", method_name);
566
Mat* me = (Mat*) self; //TODO: check for NULL
567
Mat& m = *((Mat*)m_nativeObj);
568
me->convertTo( m, rtype, alpha );
569
} catch(const std::exception &e) {
570
throwJavaException(env, &e, method_name);
571
} catch (...) {
572
throwJavaException(env, 0, method_name);
573
}
574
}
575
576
577
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJI
578
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype);
579
580
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJI
581
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype)
582
{
583
static const char method_name[] = "Mat::n_1convertTo__JJI()";
584
try {
585
LOGD("%s", method_name);
586
Mat* me = (Mat*) self; //TODO: check for NULL
587
Mat& m = *((Mat*)m_nativeObj);
588
me->convertTo( m, rtype );
589
} catch(const std::exception &e) {
590
throwJavaException(env, &e, method_name);
591
} catch (...) {
592
throwJavaException(env, 0, method_name);
593
}
594
}
595
596
597
598
//
599
// void Mat::copyTo(Mat& m)
600
//
601
602
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJ
603
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
604
605
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJ
606
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
607
{
608
static const char method_name[] = "Mat::n_1copyTo__JJ()";
609
try {
610
LOGD("%s", method_name);
611
Mat* me = (Mat*) self; //TODO: check for NULL
612
Mat& m = *((Mat*)m_nativeObj);
613
me->copyTo( m );
614
} catch(const std::exception &e) {
615
throwJavaException(env, &e, method_name);
616
} catch (...) {
617
throwJavaException(env, 0, method_name);
618
}
619
}
620
621
622
623
//
624
// void Mat::copyTo(Mat& m, Mat mask)
625
//
626
627
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJJ
628
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jlong mask_nativeObj);
629
630
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJJ
631
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jlong mask_nativeObj)
632
{
633
static const char method_name[] = "Mat::n_1copyTo__JJJ()";
634
try {
635
LOGD("%s", method_name);
636
Mat* me = (Mat*) self; //TODO: check for NULL
637
Mat& m = *((Mat*)m_nativeObj);
638
Mat& mask = *((Mat*)mask_nativeObj);
639
me->copyTo( m, mask );
640
} catch(const std::exception &e) {
641
throwJavaException(env, &e, method_name);
642
} catch (...) {
643
throwJavaException(env, 0, method_name);
644
}
645
}
646
647
648
649
//
650
// void Mat::create(int rows, int cols, int type)
651
//
652
653
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JIII
654
(JNIEnv* env, jclass, jlong self, jint rows, jint cols, jint type);
655
656
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JIII
657
(JNIEnv* env, jclass, jlong self, jint rows, jint cols, jint type)
658
{
659
static const char method_name[] = "Mat::n_1create__JIII()";
660
try {
661
LOGD("%s", method_name);
662
Mat* me = (Mat*) self; //TODO: check for NULL
663
me->create( rows, cols, type );
664
} catch(const std::exception &e) {
665
throwJavaException(env, &e, method_name);
666
} catch (...) {
667
throwJavaException(env, 0, method_name);
668
}
669
}
670
671
672
673
//
674
// void Mat::create(Size size, int type)
675
//
676
677
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JDDI
678
(JNIEnv* env, jclass, jlong self, jdouble size_width, jdouble size_height, jint type);
679
680
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JDDI
681
(JNIEnv* env, jclass, jlong self, jdouble size_width, jdouble size_height, jint type)
682
{
683
static const char method_name[] = "Mat::n_1create__JDDI()";
684
try {
685
LOGD("%s", method_name);
686
Mat* me = (Mat*) self; //TODO: check for NULL
687
Size size((int)size_width, (int)size_height);
688
me->create( size, type );
689
} catch(const std::exception &e) {
690
throwJavaException(env, &e, method_name);
691
} catch (...) {
692
throwJavaException(env, 0, method_name);
693
}
694
}
695
696
697
698
//
699
// Mat Mat::cross(Mat m)
700
//
701
702
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1cross
703
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
704
705
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1cross
706
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
707
{
708
static const char method_name[] = "Mat::n_1cross()";
709
try {
710
LOGD("%s", method_name);
711
Mat* me = (Mat*) self; //TODO: check for NULL
712
Mat& m = *((Mat*)m_nativeObj);
713
Mat _retval_ = me->cross( m );
714
return (jlong) new Mat(_retval_);
715
} catch(const std::exception &e) {
716
throwJavaException(env, &e, method_name);
717
} catch (...) {
718
throwJavaException(env, 0, method_name);
719
}
720
721
return 0;
722
}
723
724
725
726
//
727
// long Mat::dataAddr()
728
//
729
730
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1dataAddr
731
(JNIEnv*, jclass, jlong self);
732
733
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1dataAddr
734
(JNIEnv*, jclass, jlong self)
735
{
736
LOGD("Mat::n_1dataAddr()");
737
Mat* me = (Mat*) self; //TODO: check for NULL
738
return (jlong) me->data;
739
}
740
741
742
743
//
744
// int Mat::depth()
745
//
746
747
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1depth
748
(JNIEnv* env, jclass, jlong self);
749
750
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1depth
751
(JNIEnv* env, jclass, jlong self)
752
{
753
static const char method_name[] = "Mat::n_1depth()";
754
try {
755
LOGD("%s", method_name);
756
Mat* me = (Mat*) self; //TODO: check for NULL
757
return me->depth( );
758
} catch(const std::exception &e) {
759
throwJavaException(env, &e, method_name);
760
} catch (...) {
761
throwJavaException(env, 0, method_name);
762
}
763
764
return 0;
765
}
766
767
768
769
//
770
// Mat Mat::diag(int d = 0)
771
//
772
773
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__JI
774
(JNIEnv* env, jclass, jlong self, jint d);
775
776
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__JI
777
(JNIEnv* env, jclass, jlong self, jint d)
778
{
779
static const char method_name[] = "Mat::n_1diag__JI()";
780
try {
781
LOGD("%s", method_name);
782
Mat* me = (Mat*) self; //TODO: check for NULL
783
Mat _retval_ = me->diag( d );
784
return (jlong) new Mat(_retval_);
785
} catch(const std::exception &e) {
786
throwJavaException(env, &e, method_name);
787
} catch (...) {
788
throwJavaException(env, 0, method_name);
789
}
790
791
return 0;
792
}
793
794
795
796
797
//
798
// static Mat Mat::diag(Mat d)
799
//
800
801
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__J
802
(JNIEnv* env, jclass, jlong d_nativeObj);
803
804
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__J
805
(JNIEnv* env, jclass, jlong d_nativeObj)
806
{
807
static const char method_name[] = "Mat::n_1diag__J()";
808
try {
809
LOGD("%s", method_name);
810
Mat _retval_ = Mat::diag( (*(Mat*)d_nativeObj) );
811
return (jlong) new Mat(_retval_);
812
} catch(const std::exception &e) {
813
throwJavaException(env, &e, method_name);
814
} catch (...) {
815
throwJavaException(env, 0, method_name);
816
}
817
818
return 0;
819
}
820
821
822
823
//
824
// double Mat::dot(Mat m)
825
//
826
827
JNIEXPORT jdouble JNICALL Java_org_opencv_core_Mat_n_1dot
828
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
829
830
JNIEXPORT jdouble JNICALL Java_org_opencv_core_Mat_n_1dot
831
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
832
{
833
static const char method_name[] = "Mat::n_1dot()";
834
try {
835
LOGD("%s", method_name);
836
Mat* me = (Mat*) self; //TODO: check for NULL
837
Mat& m = *((Mat*)m_nativeObj);
838
return me->dot( m );
839
} catch(const std::exception &e) {
840
throwJavaException(env, &e, method_name);
841
} catch (...) {
842
throwJavaException(env, 0, method_name);
843
}
844
845
return 0;
846
}
847
848
849
850
//
851
// size_t Mat::elemSize()
852
//
853
854
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize
855
(JNIEnv* env, jclass, jlong self);
856
857
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize
858
(JNIEnv* env, jclass, jlong self)
859
{
860
static const char method_name[] = "Mat::n_1elemSize()";
861
try {
862
LOGD("%s", method_name);
863
Mat* me = (Mat*) self; //TODO: check for NULL
864
return me->elemSize( );
865
} catch(const std::exception &e) {
866
throwJavaException(env, &e, method_name);
867
} catch (...) {
868
throwJavaException(env, 0, method_name);
869
}
870
871
return 0;
872
}
873
874
875
876
//
877
// size_t Mat::elemSize1()
878
//
879
880
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize1
881
(JNIEnv* env, jclass, jlong self);
882
883
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize1
884
(JNIEnv* env, jclass, jlong self)
885
{
886
static const char method_name[] = "Mat::n_1elemSize1()";
887
try {
888
LOGD("%s", method_name);
889
Mat* me = (Mat*) self; //TODO: check for NULL
890
return me->elemSize1( );
891
} catch(const std::exception &e) {
892
throwJavaException(env, &e, method_name);
893
} catch (...) {
894
throwJavaException(env, 0, method_name);
895
}
896
897
return 0;
898
}
899
900
901
902
//
903
// bool Mat::empty()
904
//
905
906
JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1empty
907
(JNIEnv* env, jclass, jlong self);
908
909
JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1empty
910
(JNIEnv* env, jclass, jlong self)
911
{
912
static const char method_name[] = "Mat::n_1empty()";
913
try {
914
LOGD("%s", method_name);
915
Mat* me = (Mat*) self; //TODO: check for NULL
916
return me->empty( );
917
} catch(const std::exception &e) {
918
throwJavaException(env, &e, method_name);
919
} catch (...) {
920
throwJavaException(env, 0, method_name);
921
}
922
923
return 0;
924
}
925
926
927
928
//
929
// static Mat Mat::eye(int rows, int cols, int type)
930
//
931
932
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__III
933
(JNIEnv* env, jclass, jint rows, jint cols, jint type);
934
935
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__III
936
(JNIEnv* env, jclass, jint rows, jint cols, jint type)
937
{
938
static const char method_name[] = "Mat::n_1eye__III()";
939
try {
940
LOGD("%s", method_name);
941
Mat _retval_ = Mat::eye( rows, cols, type );
942
return (jlong) new Mat(_retval_);
943
} catch(const std::exception &e) {
944
throwJavaException(env, &e, method_name);
945
} catch (...) {
946
throwJavaException(env, 0, method_name);
947
}
948
949
return 0;
950
}
951
952
953
954
//
955
// static Mat Mat::eye(Size size, int type)
956
//
957
958
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__DDI
959
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);
960
961
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__DDI
962
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)
963
{
964
static const char method_name[] = "Mat::n_1eye__DDI()";
965
try {
966
LOGD("%s", method_name);
967
Size size((int)size_width, (int)size_height);
968
Mat _retval_ = Mat::eye( size, type );
969
return (jlong) new Mat(_retval_);
970
} catch(const std::exception &e) {
971
throwJavaException(env, &e, method_name);
972
} catch (...) {
973
throwJavaException(env, 0, method_name);
974
}
975
976
return 0;
977
}
978
979
980
981
//
982
// Mat Mat::inv(int method = DECOMP_LU)
983
//
984
985
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__JI
986
(JNIEnv* env, jclass, jlong self, jint method);
987
988
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__JI
989
(JNIEnv* env, jclass, jlong self, jint method)
990
{
991
static const char method_name[] = "Mat::n_1inv__JI()";
992
try {
993
LOGD("%s", method_name);
994
Mat* me = (Mat*) self; //TODO: check for NULL
995
Mat _retval_ = me->inv( method );
996
return (jlong) new Mat(_retval_);
997
} catch(const std::exception &e) {
998
throwJavaException(env, &e, method_name);
999
} catch (...) {
1000
throwJavaException(env, 0, method_name);
1001
}
1002
1003
return 0;
1004
}
1005
1006
1007
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__J
1008
(JNIEnv* env, jclass, jlong self);
1009
1010
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__J
1011
(JNIEnv* env, jclass, jlong self)
1012
{
1013
static const char method_name[] = "Mat::n_1inv__J()";
1014
try {
1015
LOGD("%s", method_name);
1016
Mat* me = (Mat*) self; //TODO: check for NULL
1017
Mat _retval_ = me->inv( );
1018
return (jlong) new Mat(_retval_);
1019
} catch(const std::exception &e) {
1020
throwJavaException(env, &e, method_name);
1021
} catch (...) {
1022
throwJavaException(env, 0, method_name);
1023
}
1024
1025
return 0;
1026
}
1027
1028
1029
1030
//
1031
// bool Mat::isContinuous()
1032
//
1033
1034
JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isContinuous
1035
(JNIEnv* env, jclass, jlong self);
1036
1037
JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isContinuous
1038
(JNIEnv* env, jclass, jlong self)
1039
{
1040
static const char method_name[] = "Mat::n_1isContinuous()";
1041
try {
1042
LOGD("%s", method_name);
1043
Mat* me = (Mat*) self; //TODO: check for NULL
1044
return me->isContinuous( );
1045
} catch(const std::exception &e) {
1046
throwJavaException(env, &e, method_name);
1047
} catch (...) {
1048
throwJavaException(env, 0, method_name);
1049
}
1050
1051
return 0;
1052
}
1053
1054
1055
1056
//
1057
// bool Mat::isSubmatrix()
1058
//
1059
1060
JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isSubmatrix
1061
(JNIEnv* env, jclass, jlong self);
1062
1063
JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isSubmatrix
1064
(JNIEnv* env, jclass, jlong self)
1065
{
1066
static const char method_name[] = "Mat::n_1isSubmatrix()";
1067
try {
1068
LOGD("%s", method_name);
1069
Mat* me = (Mat*) self; //TODO: check for NULL
1070
return me->isSubmatrix( );
1071
} catch(const std::exception &e) {
1072
throwJavaException(env, &e, method_name);
1073
} catch (...) {
1074
throwJavaException(env, 0, method_name);
1075
}
1076
1077
return 0;
1078
}
1079
1080
1081
1082
//
1083
// void Mat::locateROI(Size wholeSize, Point ofs)
1084
//
1085
1086
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_locateROI_10
1087
(JNIEnv* env, jclass, jlong self, jdoubleArray wholeSize_out, jdoubleArray ofs_out);
1088
1089
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_locateROI_10
1090
(JNIEnv* env, jclass, jlong self, jdoubleArray wholeSize_out, jdoubleArray ofs_out)
1091
{
1092
static const char method_name[] = "core::locateROI_10()";
1093
try {
1094
LOGD("%s", method_name);
1095
Mat* me = (Mat*) self; //TODO: check for NULL
1096
Size wholeSize;
1097
Point ofs;
1098
me->locateROI( wholeSize, ofs );
1099
jdouble 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);
1100
} catch(const std::exception &e) {
1101
throwJavaException(env, &e, method_name);
1102
} catch (...) {
1103
throwJavaException(env, 0, method_name);
1104
}
1105
}
1106
1107
1108
1109
//
1110
// Mat Mat::mul(Mat m, double scale = 1)
1111
//
1112
1113
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJD
1114
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jdouble scale);
1115
1116
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJD
1117
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jdouble scale)
1118
{
1119
static const char method_name[] = "Mat::n_1mul__JJD()";
1120
try {
1121
LOGD("%s", method_name);
1122
Mat* me = (Mat*) self; //TODO: check for NULL
1123
Mat& m = *((Mat*)m_nativeObj);
1124
Mat _retval_ = me->mul( m, scale );
1125
return (jlong) new Mat(_retval_);
1126
} catch(const std::exception &e) {
1127
throwJavaException(env, &e, method_name);
1128
} catch (...) {
1129
throwJavaException(env, 0, method_name);
1130
}
1131
1132
return 0;
1133
}
1134
1135
1136
1137
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJ
1138
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
1139
1140
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJ
1141
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
1142
{
1143
static const char method_name[] = "Mat::n_1mul__JJ()";
1144
try {
1145
LOGD("%s", method_name);
1146
Mat* me = (Mat*) self; //TODO: check for NULL
1147
Mat& m = *((Mat*)m_nativeObj);
1148
Mat _retval_ = me->mul( m );
1149
return (jlong) new Mat(_retval_);
1150
} catch(const std::exception &e) {
1151
throwJavaException(env, &e, method_name);
1152
} catch (...) {
1153
throwJavaException(env, 0, method_name);
1154
}
1155
1156
return 0;
1157
}
1158
1159
1160
1161
//
1162
// static Mat Mat::ones(int rows, int cols, int type)
1163
//
1164
1165
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__III
1166
(JNIEnv* env, jclass, jint rows, jint cols, jint type);
1167
1168
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__III
1169
(JNIEnv* env, jclass, jint rows, jint cols, jint type)
1170
{
1171
static const char method_name[] = "Mat::n_1ones__III()";
1172
try {
1173
LOGD("%s", method_name);
1174
Mat _retval_ = Mat::ones( rows, cols, type );
1175
return (jlong) new Mat(_retval_);
1176
} catch(const std::exception &e) {
1177
throwJavaException(env, &e, method_name);
1178
} catch (...) {
1179
throwJavaException(env, 0, method_name);
1180
}
1181
1182
return 0;
1183
}
1184
1185
1186
1187
//
1188
// static Mat Mat::ones(Size size, int type)
1189
//
1190
1191
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__DDI
1192
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);
1193
1194
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__DDI
1195
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)
1196
{
1197
static const char method_name[] = "Mat::n_1ones__DDI()";
1198
try {
1199
LOGD("%s", method_name);
1200
Size size((int)size_width, (int)size_height);
1201
Mat _retval_ = Mat::ones( size, type );
1202
return (jlong) new Mat(_retval_);
1203
} catch(const std::exception &e) {
1204
throwJavaException(env, &e, method_name);
1205
} catch (...) {
1206
throwJavaException(env, 0, method_name);
1207
}
1208
1209
return 0;
1210
}
1211
1212
1213
1214
//
1215
// void Mat::push_back(Mat m)
1216
//
1217
1218
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1push_1back
1219
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
1220
1221
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1push_1back
1222
(JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
1223
{
1224
static const char method_name[] = "Mat::n_1push_1back()";
1225
try {
1226
LOGD("%s", method_name);
1227
Mat* me = (Mat*) self; //TODO: check for NULL
1228
me->push_back( (*(Mat*)m_nativeObj) );
1229
} catch(const std::exception &e) {
1230
throwJavaException(env, &e, method_name);
1231
} catch (...) {
1232
throwJavaException(env, 0, method_name);
1233
}
1234
}
1235
1236
1237
1238
//
1239
// void Mat::release()
1240
//
1241
1242
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1release
1243
(JNIEnv* env, jclass, jlong self);
1244
1245
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1release
1246
(JNIEnv* env, jclass, jlong self)
1247
{
1248
static const char method_name[] = "Mat::n_1release()";
1249
try {
1250
LOGD("%s", method_name);
1251
Mat* me = (Mat*) self; //TODO: check for NULL
1252
me->release( );
1253
} catch(const std::exception &e) {
1254
throwJavaException(env, &e, method_name);
1255
} catch (...) {
1256
throwJavaException(env, 0, method_name);
1257
}
1258
}
1259
1260
1261
1262
//
1263
// Mat Mat::reshape(int cn, int rows = 0)
1264
//
1265
1266
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JII
1267
(JNIEnv* env, jclass, jlong self, jint cn, jint rows);
1268
1269
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JII
1270
(JNIEnv* env, jclass, jlong self, jint cn, jint rows)
1271
{
1272
static const char method_name[] = "Mat::n_1reshape__JII()";
1273
try {
1274
LOGD("%s", method_name);
1275
Mat* me = (Mat*) self; //TODO: check for NULL
1276
Mat _retval_ = me->reshape( cn, rows );
1277
return (jlong) new Mat(_retval_);
1278
} catch(const std::exception &e) {
1279
throwJavaException(env, &e, method_name);
1280
} catch (...) {
1281
throwJavaException(env, 0, method_name);
1282
}
1283
1284
return 0;
1285
}
1286
1287
1288
1289
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JI
1290
(JNIEnv* env, jclass, jlong self, jint cn);
1291
1292
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JI
1293
(JNIEnv* env, jclass, jlong self, jint cn)
1294
{
1295
static const char method_name[] = "Mat::n_1reshape__JI()";
1296
try {
1297
LOGD("%s", method_name);
1298
Mat* me = (Mat*) self; //TODO: check for NULL
1299
Mat _retval_ = me->reshape( cn );
1300
return (jlong) new Mat(_retval_);
1301
} catch(const std::exception &e) {
1302
throwJavaException(env, &e, method_name);
1303
} catch (...) {
1304
throwJavaException(env, 0, method_name);
1305
}
1306
1307
return 0;
1308
}
1309
1310
1311
1312
//
1313
// Mat Mat::row(int y)
1314
//
1315
1316
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1row
1317
(JNIEnv* env, jclass, jlong self, jint y);
1318
1319
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1row
1320
(JNIEnv* env, jclass, jlong self, jint y)
1321
{
1322
static const char method_name[] = "Mat::n_1row()";
1323
try {
1324
LOGD("%s", method_name);
1325
Mat* me = (Mat*) self; //TODO: check for NULL
1326
Mat _retval_ = me->row( y );
1327
return (jlong) new Mat(_retval_);
1328
} catch(const std::exception &e) {
1329
throwJavaException(env, &e, method_name);
1330
} catch (...) {
1331
throwJavaException(env, 0, method_name);
1332
}
1333
1334
return 0;
1335
}
1336
1337
1338
1339
//
1340
// Mat Mat::rowRange(int startrow, int endrow)
1341
//
1342
1343
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1rowRange
1344
(JNIEnv* env, jclass, jlong self, jint startrow, jint endrow);
1345
1346
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1rowRange
1347
(JNIEnv* env, jclass, jlong self, jint startrow, jint endrow)
1348
{
1349
static const char method_name[] = "Mat::n_1rowRange()";
1350
try {
1351
LOGD("%s", method_name);
1352
Mat* me = (Mat*) self; //TODO: check for NULL
1353
Mat _retval_ = me->rowRange( startrow, endrow );
1354
return (jlong) new Mat(_retval_);
1355
} catch(const std::exception &e) {
1356
throwJavaException(env, &e, method_name);
1357
} catch (...) {
1358
throwJavaException(env, 0, method_name);
1359
}
1360
1361
return 0;
1362
}
1363
1364
1365
1366
//
1367
// int Mat::rows()
1368
//
1369
1370
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1rows
1371
(JNIEnv* env, jclass, jlong self);
1372
1373
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1rows
1374
(JNIEnv* env, jclass, jlong self)
1375
{
1376
static const char method_name[] = "Mat::n_1rows()";
1377
try {
1378
LOGD("%s", method_name);
1379
Mat* me = (Mat*) self; //TODO: check for NULL
1380
return me->rows;
1381
} catch(const std::exception &e) {
1382
throwJavaException(env, &e, method_name);
1383
} catch (...) {
1384
throwJavaException(env, 0, method_name);
1385
}
1386
1387
return 0;
1388
}
1389
1390
1391
1392
//
1393
// Mat Mat::operator =(Scalar s)
1394
//
1395
1396
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDD
1397
(JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3);
1398
1399
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDD
1400
(JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3)
1401
{
1402
static const char method_name[] = "Mat::n_1setTo__JDDDD()";
1403
try {
1404
LOGD("%s", method_name);
1405
Mat* me = (Mat*) self; //TODO: check for NULL
1406
Scalar s(s_val0, s_val1, s_val2, s_val3);
1407
Mat _retval_ = me->operator =( s );
1408
return (jlong) new Mat(_retval_);
1409
} catch(const std::exception &e) {
1410
throwJavaException(env, &e, method_name);
1411
} catch (...) {
1412
throwJavaException(env, 0, method_name);
1413
}
1414
1415
return 0;
1416
}
1417
1418
1419
1420
//
1421
// Mat Mat::setTo(Scalar value, Mat mask = Mat())
1422
//
1423
1424
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDDJ
1425
(JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3, jlong mask_nativeObj);
1426
1427
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDDJ
1428
(JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3, jlong mask_nativeObj)
1429
{
1430
static const char method_name[] = "Mat::n_1setTo__JDDDDJ()";
1431
try {
1432
LOGD("%s", method_name);
1433
Mat* me = (Mat*) self; //TODO: check for NULL
1434
Scalar s(s_val0, s_val1, s_val2, s_val3);
1435
Mat& mask = *((Mat*)mask_nativeObj);
1436
Mat _retval_ = me->setTo( s, mask );
1437
return (jlong) new Mat(_retval_);
1438
} catch(const std::exception &e) {
1439
throwJavaException(env, &e, method_name);
1440
} catch (...) {
1441
throwJavaException(env, 0, method_name);
1442
}
1443
1444
return 0;
1445
}
1446
1447
1448
1449
//
1450
// Mat Mat::setTo(Mat value, Mat mask = Mat())
1451
//
1452
1453
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJJ
1454
(JNIEnv* env, jclass, jlong self, jlong value_nativeObj, jlong mask_nativeObj);
1455
1456
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJJ
1457
(JNIEnv* env, jclass, jlong self, jlong value_nativeObj, jlong mask_nativeObj)
1458
{
1459
static const char method_name[] = "Mat::n_1setTo__JJJ()";
1460
try {
1461
LOGD("%s", method_name);
1462
Mat* me = (Mat*) self; //TODO: check for NULL
1463
Mat& value = *((Mat*)value_nativeObj);
1464
Mat& mask = *((Mat*)mask_nativeObj);
1465
Mat _retval_ = me->setTo( value, mask );
1466
return (jlong) new Mat(_retval_);
1467
} catch(const std::exception &e) {
1468
throwJavaException(env, &e, method_name);
1469
} catch (...) {
1470
throwJavaException(env, 0, method_name);
1471
}
1472
1473
return 0;
1474
}
1475
1476
1477
1478
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJ
1479
(JNIEnv* env, jclass, jlong self, jlong value_nativeObj);
1480
1481
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJ
1482
(JNIEnv* env, jclass, jlong self, jlong value_nativeObj)
1483
{
1484
static const char method_name[] = "Mat::n_1setTo__JJ()";
1485
try {
1486
LOGD("%s", method_name);
1487
Mat* me = (Mat*) self; //TODO: check for NULL
1488
Mat& value = *((Mat*)value_nativeObj);
1489
Mat _retval_ = me->setTo( value );
1490
return (jlong) new Mat(_retval_);
1491
} catch(const std::exception &e) {
1492
throwJavaException(env, &e, method_name);
1493
} catch (...) {
1494
throwJavaException(env, 0, method_name);
1495
}
1496
1497
return 0;
1498
}
1499
1500
1501
1502
//
1503
// Size Mat::size()
1504
//
1505
1506
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_n_1size
1507
(JNIEnv* env, jclass, jlong self);
1508
1509
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_n_1size
1510
(JNIEnv* env, jclass, jlong self)
1511
{
1512
static const char method_name[] = "Mat::n_1size()";
1513
try {
1514
LOGD("%s", method_name);
1515
Mat* me = (Mat*) self; //TODO: check for NULL
1516
Size _retval_ = me->size( );
1517
jdoubleArray _da_retval_ = env->NewDoubleArray(2);
1518
jdouble _tmp_retval_[2] = {(jdouble)_retval_.width, (jdouble)_retval_.height};
1519
env->SetDoubleArrayRegion(_da_retval_, 0, 2, _tmp_retval_);
1520
return _da_retval_;
1521
} catch(const std::exception &e) {
1522
throwJavaException(env, &e, method_name);
1523
} catch (...) {
1524
throwJavaException(env, 0, method_name);
1525
}
1526
1527
return 0;
1528
}
1529
1530
1531
1532
//
1533
// size_t Mat::step1(int i = 0)
1534
//
1535
1536
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__JI
1537
(JNIEnv* env, jclass, jlong self, jint i);
1538
1539
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__JI
1540
(JNIEnv* env, jclass, jlong self, jint i)
1541
{
1542
static const char method_name[] = "Mat::n_1step1__JI()";
1543
try {
1544
LOGD("%s", method_name);
1545
Mat* me = (Mat*) self; //TODO: check for NULL
1546
return me->step1( i );
1547
} catch(const std::exception &e) {
1548
throwJavaException(env, &e, method_name);
1549
} catch (...) {
1550
throwJavaException(env, 0, method_name);
1551
}
1552
1553
return 0;
1554
}
1555
1556
1557
1558
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__J
1559
(JNIEnv* env, jclass, jlong self);
1560
1561
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__J
1562
(JNIEnv* env, jclass, jlong self)
1563
{
1564
static const char method_name[] = "Mat::n_1step1__J()";
1565
try {
1566
LOGD("%s", method_name);
1567
Mat* me = (Mat*) self; //TODO: check for NULL
1568
return me->step1( );
1569
} catch(const std::exception &e) {
1570
throwJavaException(env, &e, method_name);
1571
} catch (...) {
1572
throwJavaException(env, 0, method_name);
1573
}
1574
1575
return 0;
1576
}
1577
1578
//
1579
// Mat Mat::operator()(Range rowRange, Range colRange)
1580
//
1581
1582
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat_1rr
1583
(JNIEnv* env, jclass, jlong self, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end);
1584
1585
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat_1rr
1586
(JNIEnv* env, jclass, jlong self, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end)
1587
{
1588
static const char method_name[] = "Mat::n_1submat_1rr()";
1589
try {
1590
LOGD("%s", method_name);
1591
Mat* me = (Mat*) self; //TODO: check for NULL
1592
Range rowRange(rowRange_start, rowRange_end);
1593
Range colRange(colRange_start, colRange_end);
1594
Mat _retval_ = me->operator()( rowRange, colRange );
1595
return (jlong) new Mat(_retval_);
1596
} catch(const std::exception &e) {
1597
throwJavaException(env, &e, method_name);
1598
} catch (...) {
1599
throwJavaException(env, 0, method_name);
1600
}
1601
1602
return 0;
1603
}
1604
1605
1606
1607
//
1608
// Mat Mat::operator()(Rect roi)
1609
//
1610
1611
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat
1612
(JNIEnv* env, jclass, jlong self, jint roi_x, jint roi_y, jint roi_width, jint roi_height);
1613
1614
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat
1615
(JNIEnv* env, jclass, jlong self, jint roi_x, jint roi_y, jint roi_width, jint roi_height)
1616
{
1617
static const char method_name[] = "Mat::n_1submat()";
1618
try {
1619
LOGD("%s", method_name);
1620
Mat* me = (Mat*) self; //TODO: check for NULL
1621
Rect roi(roi_x, roi_y, roi_width, roi_height);
1622
Mat _retval_ = me->operator()( roi );
1623
return (jlong) new Mat(_retval_);
1624
} catch(const std::exception &e) {
1625
throwJavaException(env, &e, method_name);
1626
} catch (...) {
1627
throwJavaException(env, 0, method_name);
1628
}
1629
1630
return 0;
1631
}
1632
1633
1634
1635
//
1636
// Mat Mat::t()
1637
//
1638
1639
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1t
1640
(JNIEnv* env, jclass, jlong self);
1641
1642
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1t
1643
(JNIEnv* env, jclass, jlong self)
1644
{
1645
static const char method_name[] = "Mat::n_1t()";
1646
try {
1647
LOGD("%s", method_name);
1648
Mat* me = (Mat*) self; //TODO: check for NULL
1649
Mat _retval_ = me->t( );
1650
return (jlong) new Mat(_retval_);
1651
} catch(const std::exception &e) {
1652
throwJavaException(env, &e, method_name);
1653
} catch (...) {
1654
throwJavaException(env, 0, method_name);
1655
}
1656
1657
return 0;
1658
}
1659
1660
1661
1662
//
1663
// size_t Mat::total()
1664
//
1665
1666
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1total
1667
(JNIEnv* env, jclass, jlong self);
1668
1669
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1total
1670
(JNIEnv* env, jclass, jlong self)
1671
{
1672
static const char method_name[] = "Mat::n_1total()";
1673
try {
1674
LOGD("%s", method_name);
1675
Mat* me = (Mat*) self; //TODO: check for NULL
1676
return me->total( );
1677
} catch(const std::exception &e) {
1678
throwJavaException(env, &e, method_name);
1679
} catch (...) {
1680
throwJavaException(env, 0, method_name);
1681
}
1682
1683
return 0;
1684
}
1685
1686
1687
1688
//
1689
// int Mat::type()
1690
//
1691
1692
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1type
1693
(JNIEnv* env, jclass, jlong self);
1694
1695
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1type
1696
(JNIEnv* env, jclass, jlong self)
1697
{
1698
static const char method_name[] = "Mat::n_1type()";
1699
try {
1700
LOGD("%s", method_name);
1701
Mat* me = (Mat*) self; //TODO: check for NULL
1702
return me->type( );
1703
} catch(const std::exception &e) {
1704
throwJavaException(env, &e, method_name);
1705
} catch (...) {
1706
throwJavaException(env, 0, method_name);
1707
}
1708
1709
return 0;
1710
}
1711
1712
1713
1714
//
1715
// static Mat Mat::zeros(int rows, int cols, int type)
1716
//
1717
1718
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__III
1719
(JNIEnv* env, jclass, jint rows, jint cols, jint type);
1720
1721
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__III
1722
(JNIEnv* env, jclass, jint rows, jint cols, jint type)
1723
{
1724
static const char method_name[] = "Mat::n_1zeros__III()";
1725
try {
1726
LOGD("%s", method_name);
1727
Mat _retval_ = Mat::zeros( rows, cols, type );
1728
return (jlong) new Mat(_retval_);
1729
} catch(const std::exception &e) {
1730
throwJavaException(env, &e, method_name);
1731
} catch (...) {
1732
throwJavaException(env, 0, method_name);
1733
}
1734
1735
return 0;
1736
}
1737
1738
1739
1740
//
1741
// static Mat Mat::zeros(Size size, int type)
1742
//
1743
1744
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__DDI
1745
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);
1746
1747
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__DDI
1748
(JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)
1749
{
1750
static const char method_name[] = "Mat::n_1zeros__DDI()";
1751
try {
1752
LOGD("%s", method_name);
1753
Size size((int)size_width, (int)size_height);
1754
Mat _retval_ = Mat::zeros( size, type );
1755
return (jlong) new Mat(_retval_);
1756
} catch(const std::exception &e) {
1757
throwJavaException(env, &e, method_name);
1758
} catch (...) {
1759
throwJavaException(env, 0, method_name);
1760
}
1761
1762
return 0;
1763
}
1764
1765
1766
1767
//
1768
// native support for java finalize()
1769
// static void Mat::n_delete( __int64 self )
1770
//
1771
1772
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1delete
1773
(JNIEnv*, jclass, jlong self);
1774
1775
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1delete
1776
(JNIEnv*, jclass, jlong self)
1777
{
1778
delete (Mat*) self;
1779
}
1780
1781
} // extern "C"
1782
1783
namespace {
1784
/// map java-array-types to assigned data
1785
template<class T> struct JavaOpenCVTrait;
1786
1787
/// less typing for specialisations
1788
#define JOCvT(t,s,c1,c2) \
1789
template<> struct JavaOpenCVTrait<t##Array> { \
1790
typedef t value_type; /* type of array element */ \
1791
static const char get[]; /* name of getter */ \
1792
static const char put[]; /* name of putter */ \
1793
enum {cvtype_1 = c1, cvtype_2 = c2 }; /* allowed OpenCV-types */ \
1794
}; \
1795
const char JavaOpenCVTrait<t##Array>::get[] = "Mat::nGet" s "()"; \
1796
const char JavaOpenCVTrait<t##Array>::put[] = "Mat::nPut" s "()"
1797
1798
JOCvT(jbyte, "B", CV_8U, CV_8S);
1799
JOCvT(jshort, "S", CV_16U, CV_16S);
1800
JOCvT(jint, "I", CV_32S, CV_32S);
1801
JOCvT(jfloat, "F", CV_32F, CV_32F);
1802
JOCvT(jdouble, "D", CV_64F, CV_64F);
1803
#undef JOCvT
1804
}
1805
1806
template<typename T> static int mat_put(cv::Mat* m, int row, int col, int count, int offset, char* buff)
1807
{
1808
if(! m) return 0;
1809
if(! buff) return 0;
1810
1811
count *= sizeof(T);
1812
int rest = ((m->rows - row) * m->cols - col) * (int)m->elemSize();
1813
if(count>rest) count = rest;
1814
int res = count;
1815
1816
if( m->isContinuous() )
1817
{
1818
memcpy(m->ptr(row, col), buff + offset, count);
1819
} else {
1820
// row by row
1821
int num = (m->cols - col) * (int)m->elemSize(); // 1st partial row
1822
if(count<num) num = count;
1823
uchar* data = m->ptr(row++, col);
1824
while(count>0){
1825
memcpy(data, buff + offset, num);
1826
count -= num;
1827
buff += num;
1828
num = m->cols * (int)m->elemSize();
1829
if(count<num) num = count;
1830
data = m->ptr(row++, 0);
1831
}
1832
}
1833
return res;
1834
}
1835
1836
template<class ARRAY> static jint java_mat_put(JNIEnv* env, jlong self, jint row, jint col, jint count, jint offset, ARRAY vals)
1837
{
1838
static const char *method_name = JavaOpenCVTrait<ARRAY>::put;
1839
try {
1840
LOGD("%s", method_name);
1841
cv::Mat* me = (cv::Mat*) self;
1842
if(! self) return 0; // no native object behind
1843
if(me->depth() != JavaOpenCVTrait<ARRAY>::cvtype_1 && me->depth() != JavaOpenCVTrait<ARRAY>::cvtype_2) return 0; // incompatible type
1844
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
1845
1846
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
1847
int res = mat_put<typename JavaOpenCVTrait<ARRAY>::value_type>(me, row, col, count, offset, values);
1848
env->ReleasePrimitiveArrayCritical(vals, values, JNI_ABORT);
1849
return res;
1850
} catch(const std::exception &e) {
1851
throwJavaException(env, &e, method_name);
1852
} catch (...) {
1853
throwJavaException(env, 0, method_name);
1854
}
1855
1856
return 0;
1857
}
1858
1859
extern "C" {
1860
1861
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutB
1862
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals);
1863
1864
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutB
1865
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals)
1866
{
1867
return java_mat_put(env, self, row, col, count, 0, vals);
1868
}
1869
1870
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutBwOffset
1871
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jint offset, jbyteArray vals);
1872
1873
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutBwOffset
1874
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jint offset, jbyteArray vals)
1875
{
1876
return java_mat_put(env, self, row, col, count, offset, vals);
1877
}
1878
1879
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutS
1880
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals);
1881
1882
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutS
1883
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals)
1884
{
1885
return java_mat_put(env, self, row, col, count, 0, vals);
1886
}
1887
1888
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutI
1889
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals);
1890
1891
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutI
1892
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals)
1893
{
1894
return java_mat_put(env, self, row, col, count, 0, vals);
1895
}
1896
1897
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutF
1898
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals);
1899
1900
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutF
1901
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals)
1902
{
1903
return java_mat_put(env, self, row, col, count, 0, vals);
1904
}
1905
1906
// unlike other nPut()-s this one (with double[]) should convert input values to correct type
1907
#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); }
1908
1909
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
1910
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals);
1911
1912
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
1913
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals)
1914
{
1915
static const char* method_name = JavaOpenCVTrait<jdoubleArray>::put;
1916
try {
1917
LOGD("%s", method_name);
1918
cv::Mat* me = (cv::Mat*) self;
1919
if(!me || !me->data) return 0; // no native object behind
1920
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
1921
1922
int rest = ((me->rows - row) * me->cols - col) * me->channels();
1923
if(count>rest) count = rest;
1924
int res = count;
1925
double* values = (double*)env->GetPrimitiveArrayCritical(vals, 0);
1926
double* src = values;
1927
int r, c;
1928
for(c=col; c<me->cols && count>0; c++)
1929
{
1930
switch(me->depth()) {
1931
case CV_8U: PUT_ITEM(uchar, row, c); break;
1932
case CV_8S: PUT_ITEM(schar, row, c); break;
1933
case CV_16U: PUT_ITEM(ushort, row, c); break;
1934
case CV_16S: PUT_ITEM(short, row, c); break;
1935
case CV_32S: PUT_ITEM(int, row, c); break;
1936
case CV_32F: PUT_ITEM(float, row, c); break;
1937
case CV_64F: PUT_ITEM(double, row, c); break;
1938
}
1939
}
1940
1941
for(r=row+1; r<me->rows && count>0; r++)
1942
for(c=0; c<me->cols && count>0; c++)
1943
{
1944
switch(me->depth()) {
1945
case CV_8U: PUT_ITEM(uchar, r, c); break;
1946
case CV_8S: PUT_ITEM(schar, r, c); break;
1947
case CV_16U: PUT_ITEM(ushort, r, c); break;
1948
case CV_16S: PUT_ITEM(short, r, c); break;
1949
case CV_32S: PUT_ITEM(int, r, c); break;
1950
case CV_32F: PUT_ITEM(float, r, c); break;
1951
case CV_64F: PUT_ITEM(double, r, c); break;
1952
}
1953
}
1954
1955
env->ReleasePrimitiveArrayCritical(vals, values, 0);
1956
return res;
1957
} catch(const std::exception &e) {
1958
throwJavaException(env, &e, method_name);
1959
} catch (...) {
1960
throwJavaException(env, 0, method_name);
1961
}
1962
1963
return 0;
1964
}
1965
1966
} // extern "C"
1967
1968
template<typename T> static int mat_get(cv::Mat* m, int row, int col, int count, char* buff)
1969
{
1970
if(! m) return 0;
1971
if(! buff) return 0;
1972
1973
int bytesToCopy = count * sizeof(T);
1974
int bytesRestInMat = ((m->rows - row) * m->cols - col) * (int)m->elemSize();
1975
if(bytesToCopy > bytesRestInMat) bytesToCopy = bytesRestInMat;
1976
int res = bytesToCopy;
1977
1978
if( m->isContinuous() )
1979
{
1980
memcpy(buff, m->ptr(row, col), bytesToCopy);
1981
} else {
1982
// row by row
1983
int bytesInRow = (m->cols - col) * (int)m->elemSize(); // 1st partial row
1984
while(bytesToCopy > 0)
1985
{
1986
int len = std::min(bytesToCopy, bytesInRow);
1987
memcpy(buff, m->ptr(row, col), len);
1988
bytesToCopy -= len;
1989
buff += len;
1990
row++;
1991
col = 0;
1992
bytesInRow = m->cols * (int)m->elemSize();
1993
}
1994
}
1995
return res;
1996
}
1997
1998
template<class ARRAY> static jint java_mat_get(JNIEnv* env, jlong self, jint row, jint col, jint count, ARRAY vals) {
1999
static const char *method_name = JavaOpenCVTrait<ARRAY>::get;
2000
try {
2001
LOGD("%s", method_name);
2002
cv::Mat* me = (cv::Mat*) self;
2003
if(! self) return 0; // no native object behind
2004
if(me->depth() != JavaOpenCVTrait<ARRAY>::cvtype_1 && me->depth() != JavaOpenCVTrait<ARRAY>::cvtype_2) return 0; // incompatible type
2005
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
2006
2007
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
2008
int res = mat_get<typename JavaOpenCVTrait<ARRAY>::value_type>(me, row, col, count, values);
2009
env->ReleasePrimitiveArrayCritical(vals, values, 0);
2010
return res;
2011
} catch(const std::exception &e) {
2012
throwJavaException(env, &e, method_name);
2013
} catch (...) {
2014
throwJavaException(env, 0, method_name);
2015
}
2016
2017
return 0;
2018
}
2019
2020
extern "C" {
2021
2022
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetB
2023
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals);
2024
2025
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetB
2026
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals)
2027
{
2028
return java_mat_get(env, self, row, col, count, vals);
2029
}
2030
2031
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetS
2032
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals);
2033
2034
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetS
2035
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals)
2036
{
2037
return java_mat_get(env, self, row, col, count, vals);
2038
}
2039
2040
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetI
2041
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals);
2042
2043
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetI
2044
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals)
2045
{
2046
return java_mat_get(env, self, row, col, count, vals);
2047
}
2048
2049
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetF
2050
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals);
2051
2052
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetF
2053
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals)
2054
{
2055
return java_mat_get(env, self, row, col, count, vals);
2056
}
2057
2058
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetD
2059
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals);
2060
2061
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetD
2062
(JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals)
2063
{
2064
return java_mat_get(env, self, row, col, count, vals);
2065
}
2066
2067
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nGet
2068
(JNIEnv* env, jclass, jlong self, jint row, jint col);
2069
2070
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nGet
2071
(JNIEnv* env, jclass, jlong self, jint row, jint col)
2072
{
2073
static const char method_name[] = "Mat::nGet()";
2074
try {
2075
LOGD("%s", method_name);
2076
cv::Mat* me = (cv::Mat*) self;
2077
if(! self) return 0; // no native object behind
2078
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
2079
2080
jdoubleArray res = env->NewDoubleArray(me->channels());
2081
if(res){
2082
jdouble buff[CV_CN_MAX];//me->channels()
2083
int i;
2084
switch(me->depth()){
2085
case CV_8U: for(i=0; i<me->channels(); i++) buff[i] = *((unsigned char*) me->ptr(row, col) + i); break;
2086
case CV_8S: for(i=0; i<me->channels(); i++) buff[i] = *((signed char*) me->ptr(row, col) + i); break;
2087
case CV_16U: for(i=0; i<me->channels(); i++) buff[i] = *((unsigned short*)me->ptr(row, col) + i); break;
2088
case CV_16S: for(i=0; i<me->channels(); i++) buff[i] = *((signed short*) me->ptr(row, col) + i); break;
2089
case CV_32S: for(i=0; i<me->channels(); i++) buff[i] = *((int*) me->ptr(row, col) + i); break;
2090
case CV_32F: for(i=0; i<me->channels(); i++) buff[i] = *((float*) me->ptr(row, col) + i); break;
2091
case CV_64F: for(i=0; i<me->channels(); i++) buff[i] = *((double*) me->ptr(row, col) + i); break;
2092
}
2093
env->SetDoubleArrayRegion(res, 0, me->channels(), buff);
2094
}
2095
return res;
2096
} catch(const std::exception &e) {
2097
throwJavaException(env, &e, method_name);
2098
} catch (...) {
2099
throwJavaException(env, 0, method_name);
2100
}
2101
2102
return 0;
2103
}
2104
2105
JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump
2106
(JNIEnv *env, jclass, jlong self);
2107
2108
JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump
2109
(JNIEnv *env, jclass, jlong self)
2110
{
2111
static const char method_name[] = "Mat::nDump()";
2112
try {
2113
LOGD("%s", method_name);
2114
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
2115
String s;
2116
Ptr<Formatted> fmtd = Formatter::get()->format(*me);
2117
for(const char* str = fmtd->next(); str; str = fmtd->next())
2118
{
2119
s = s + String(str);
2120
}
2121
return env->NewStringUTF(s.c_str());
2122
} catch(const std::exception &e) {
2123
throwJavaException(env, &e, method_name);
2124
} catch (...) {
2125
throwJavaException(env, 0, method_name);
2126
}
2127
2128
return 0;
2129
}
2130
2131
2132
} // extern "C"
2133
2134