001package org.opencv.core; 002 003import java.nio.ByteBuffer; 004 005// C++: class Mat 006//javadoc: Mat 007public class Mat { 008 009 public final long nativeObj; 010 011 public Mat(long addr) { 012 if (addr == 0) 013 throw new UnsupportedOperationException("Native object address is NULL"); 014 nativeObj = addr; 015 } 016 017 // 018 // C++: Mat::Mat() 019 // 020 021 // javadoc: Mat::Mat() 022 public Mat() { 023 nativeObj = n_Mat(); 024 } 025 026 // 027 // C++: Mat::Mat(int rows, int cols, int type) 028 // 029 030 // javadoc: Mat::Mat(rows, cols, type) 031 public Mat(int rows, int cols, int type) { 032 nativeObj = n_Mat(rows, cols, type); 033 } 034 035 // 036 // C++: Mat::Mat(int rows, int cols, int type, void* data) 037 // 038 039 // javadoc: Mat::Mat(rows, cols, type, data) 040 public Mat(int rows, int cols, int type, ByteBuffer data) { 041 nativeObj = n_Mat(rows, cols, type, data); 042 } 043 044 // 045 // C++: Mat::Mat(int rows, int cols, int type, void* data, size_t step) 046 // 047 048 // javadoc: Mat::Mat(rows, cols, type, data, step) 049 public Mat(int rows, int cols, int type, ByteBuffer data, long step) { 050 nativeObj = n_Mat(rows, cols, type, data, step); 051 } 052 053 // 054 // C++: Mat::Mat(Size size, int type) 055 // 056 057 // javadoc: Mat::Mat(size, type) 058 public Mat(Size size, int type) { 059 nativeObj = n_Mat(size.width, size.height, type); 060 } 061 062 // 063 // C++: Mat::Mat(int ndims, const int* sizes, int type) 064 // 065 066 // javadoc: Mat::Mat(sizes, type) 067 public Mat(int[] sizes, int type) { 068 nativeObj = n_Mat(sizes.length, sizes, type); 069 } 070 071 // 072 // C++: Mat::Mat(int rows, int cols, int type, Scalar s) 073 // 074 075 // javadoc: Mat::Mat(rows, cols, type, s) 076 public Mat(int rows, int cols, int type, Scalar s) { 077 nativeObj = n_Mat(rows, cols, type, s.val[0], s.val[1], s.val[2], s.val[3]); 078 } 079 080 // 081 // C++: Mat::Mat(Size size, int type, Scalar s) 082 // 083 084 // javadoc: Mat::Mat(size, type, s) 085 public Mat(Size size, int type, Scalar s) { 086 nativeObj = n_Mat(size.width, size.height, type, s.val[0], s.val[1], s.val[2], s.val[3]); 087 } 088 089 // 090 // C++: Mat::Mat(int ndims, const int* sizes, int type, Scalar s) 091 // 092 093 // javadoc: Mat::Mat(sizes, type, s) 094 public Mat(int[] sizes, int type, Scalar s) { 095 nativeObj = n_Mat(sizes.length, sizes, type, s.val[0], s.val[1], s.val[2], s.val[3]); 096 } 097 098 // 099 // C++: Mat::Mat(Mat m, Range rowRange, Range colRange = Range::all()) 100 // 101 102 // javadoc: Mat::Mat(m, rowRange, colRange) 103 public Mat(Mat m, Range rowRange, Range colRange) { 104 nativeObj = n_Mat(m.nativeObj, rowRange.start, rowRange.end, colRange.start, colRange.end); 105 } 106 107 // javadoc: Mat::Mat(m, rowRange) 108 public Mat(Mat m, Range rowRange) { 109 nativeObj = n_Mat(m.nativeObj, rowRange.start, rowRange.end); 110 } 111 112 // 113 // C++: Mat::Mat(const Mat& m, const std::vector<Range>& ranges) 114 // 115 116 // javadoc: Mat::Mat(m, ranges) 117 public Mat(Mat m, Range[] ranges) { 118 nativeObj = n_Mat(m.nativeObj, ranges); 119 } 120 121 // 122 // C++: Mat::Mat(Mat m, Rect roi) 123 // 124 125 // javadoc: Mat::Mat(m, roi) 126 public Mat(Mat m, Rect roi) { 127 nativeObj = n_Mat(m.nativeObj, roi.y, roi.y + roi.height, roi.x, roi.x + roi.width); 128 } 129 130 // 131 // C++: Mat Mat::adjustROI(int dtop, int dbottom, int dleft, int dright) 132 // 133 134 // javadoc: Mat::adjustROI(dtop, dbottom, dleft, dright) 135 public Mat adjustROI(int dtop, int dbottom, int dleft, int dright) { 136 return new Mat(n_adjustROI(nativeObj, dtop, dbottom, dleft, dright)); 137 } 138 139 // 140 // C++: void Mat::assignTo(Mat m, int type = -1) 141 // 142 143 // javadoc: Mat::assignTo(m, type) 144 public void assignTo(Mat m, int type) { 145 n_assignTo(nativeObj, m.nativeObj, type); 146 } 147 148 // javadoc: Mat::assignTo(m) 149 public void assignTo(Mat m) { 150 n_assignTo(nativeObj, m.nativeObj); 151 } 152 153 // 154 // C++: int Mat::channels() 155 // 156 157 // javadoc: Mat::channels() 158 public int channels() { 159 return n_channels(nativeObj); 160 } 161 162 // 163 // C++: int Mat::checkVector(int elemChannels, int depth = -1, bool 164 // requireContinuous = true) 165 // 166 167 // javadoc: Mat::checkVector(elemChannels, depth, requireContinuous) 168 public int checkVector(int elemChannels, int depth, boolean requireContinuous) { 169 return n_checkVector(nativeObj, elemChannels, depth, requireContinuous); 170 } 171 172 // javadoc: Mat::checkVector(elemChannels, depth) 173 public int checkVector(int elemChannels, int depth) { 174 return n_checkVector(nativeObj, elemChannels, depth); 175 } 176 177 // javadoc: Mat::checkVector(elemChannels) 178 public int checkVector(int elemChannels) { 179 return n_checkVector(nativeObj, elemChannels); 180 } 181 182 // 183 // C++: Mat Mat::clone() 184 // 185 186 // javadoc: Mat::clone() 187 public Mat clone() { 188 return new Mat(n_clone(nativeObj)); 189 } 190 191 // 192 // C++: Mat Mat::col(int x) 193 // 194 195 // javadoc: Mat::col(x) 196 public Mat col(int x) { 197 return new Mat(n_col(nativeObj, x)); 198 } 199 200 // 201 // C++: Mat Mat::colRange(int startcol, int endcol) 202 // 203 204 // javadoc: Mat::colRange(startcol, endcol) 205 public Mat colRange(int startcol, int endcol) { 206 return new Mat(n_colRange(nativeObj, startcol, endcol)); 207 } 208 209 // 210 // C++: Mat Mat::colRange(Range r) 211 // 212 213 // javadoc: Mat::colRange(r) 214 public Mat colRange(Range r) { 215 return new Mat(n_colRange(nativeObj, r.start, r.end)); 216 } 217 218 // 219 // C++: int Mat::dims() 220 // 221 222 // javadoc: Mat::dims() 223 public int dims() { 224 return n_dims(nativeObj); 225 } 226 227 // 228 // C++: int Mat::cols() 229 // 230 231 // javadoc: Mat::cols() 232 public int cols() { 233 return n_cols(nativeObj); 234 } 235 236 // 237 // C++: void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta 238 // = 0) 239 // 240 241 // javadoc: Mat::convertTo(m, rtype, alpha, beta) 242 public void convertTo(Mat m, int rtype, double alpha, double beta) { 243 n_convertTo(nativeObj, m.nativeObj, rtype, alpha, beta); 244 } 245 246 // javadoc: Mat::convertTo(m, rtype, alpha) 247 public void convertTo(Mat m, int rtype, double alpha) { 248 n_convertTo(nativeObj, m.nativeObj, rtype, alpha); 249 } 250 251 // javadoc: Mat::convertTo(m, rtype) 252 public void convertTo(Mat m, int rtype) { 253 n_convertTo(nativeObj, m.nativeObj, rtype); 254 } 255 256 // 257 // C++: void Mat::copyTo(Mat& m) 258 // 259 260 // javadoc: Mat::copyTo(m) 261 public void copyTo(Mat m) { 262 n_copyTo(nativeObj, m.nativeObj); 263 } 264 265 // 266 // C++: void Mat::copyTo(Mat& m, Mat mask) 267 // 268 269 // javadoc: Mat::copyTo(m, mask) 270 public void copyTo(Mat m, Mat mask) { 271 n_copyTo(nativeObj, m.nativeObj, mask.nativeObj); 272 } 273 274 // 275 // C++: void Mat::create(int rows, int cols, int type) 276 // 277 278 // javadoc: Mat::create(rows, cols, type) 279 public void create(int rows, int cols, int type) { 280 n_create(nativeObj, rows, cols, type); 281 } 282 283 // 284 // C++: void Mat::create(Size size, int type) 285 // 286 287 // javadoc: Mat::create(size, type) 288 public void create(Size size, int type) { 289 n_create(nativeObj, size.width, size.height, type); 290 } 291 292 // 293 // C++: void Mat::create(int ndims, const int* sizes, int type) 294 // 295 296 // javadoc: Mat::create(sizes, type) 297 public void create(int[] sizes, int type) { 298 n_create(nativeObj, sizes.length, sizes, type); 299 } 300 301 // 302 // C++: void Mat::copySize(const Mat& m); 303 // 304 305 // javadoc: Mat::copySize(m) 306 public void copySize(Mat m) { 307 n_copySize(nativeObj, m.nativeObj); 308 } 309 310 // 311 // C++: Mat Mat::cross(Mat m) 312 // 313 314 // javadoc: Mat::cross(m) 315 public Mat cross(Mat m) { 316 return new Mat(n_cross(nativeObj, m.nativeObj)); 317 } 318 319 // 320 // C++: long Mat::dataAddr() 321 // 322 323 // javadoc: Mat::dataAddr() 324 public long dataAddr() { 325 return n_dataAddr(nativeObj); 326 } 327 328 // 329 // C++: int Mat::depth() 330 // 331 332 // javadoc: Mat::depth() 333 public int depth() { 334 return n_depth(nativeObj); 335 } 336 337 // 338 // C++: Mat Mat::diag(int d = 0) 339 // 340 341 // javadoc: Mat::diag(d) 342 public Mat diag(int d) { 343 return new Mat(n_diag(nativeObj, d)); 344 } 345 346 // javadoc: Mat::diag() 347 public Mat diag() { 348 return new Mat(n_diag(nativeObj, 0)); 349 } 350 351 // 352 // C++: static Mat Mat::diag(Mat d) 353 // 354 355 // javadoc: Mat::diag(d) 356 public static Mat diag(Mat d) { 357 return new Mat(n_diag(d.nativeObj)); 358 } 359 360 // 361 // C++: double Mat::dot(Mat m) 362 // 363 364 // javadoc: Mat::dot(m) 365 public double dot(Mat m) { 366 return n_dot(nativeObj, m.nativeObj); 367 } 368 369 // 370 // C++: size_t Mat::elemSize() 371 // 372 373 // javadoc: Mat::elemSize() 374 public long elemSize() { 375 return n_elemSize(nativeObj); 376 } 377 378 // 379 // C++: size_t Mat::elemSize1() 380 // 381 382 // javadoc: Mat::elemSize1() 383 public long elemSize1() { 384 return n_elemSize1(nativeObj); 385 } 386 387 // 388 // C++: bool Mat::empty() 389 // 390 391 // javadoc: Mat::empty() 392 public boolean empty() { 393 return n_empty(nativeObj); 394 } 395 396 // 397 // C++: static Mat Mat::eye(int rows, int cols, int type) 398 // 399 400 // javadoc: Mat::eye(rows, cols, type) 401 public static Mat eye(int rows, int cols, int type) { 402 return new Mat(n_eye(rows, cols, type)); 403 } 404 405 // 406 // C++: static Mat Mat::eye(Size size, int type) 407 // 408 409 // javadoc: Mat::eye(size, type) 410 public static Mat eye(Size size, int type) { 411 return new Mat(n_eye(size.width, size.height, type)); 412 } 413 414 // 415 // C++: Mat Mat::inv(int method = DECOMP_LU) 416 // 417 418 // javadoc: Mat::inv(method) 419 public Mat inv(int method) { 420 return new Mat(n_inv(nativeObj, method)); 421 } 422 423 // javadoc: Mat::inv() 424 public Mat inv() { 425 return new Mat(n_inv(nativeObj)); 426 } 427 428 // 429 // C++: bool Mat::isContinuous() 430 // 431 432 // javadoc: Mat::isContinuous() 433 public boolean isContinuous() { 434 return n_isContinuous(nativeObj); 435 } 436 437 // 438 // C++: bool Mat::isSubmatrix() 439 // 440 441 // javadoc: Mat::isSubmatrix() 442 public boolean isSubmatrix() { 443 return n_isSubmatrix(nativeObj); 444 } 445 446 // 447 // C++: void Mat::locateROI(Size wholeSize, Point ofs) 448 // 449 450 // javadoc: Mat::locateROI(wholeSize, ofs) 451 public void locateROI(Size wholeSize, Point ofs) { 452 double[] wholeSize_out = new double[2]; 453 double[] ofs_out = new double[2]; 454 locateROI_0(nativeObj, wholeSize_out, ofs_out); 455 if (wholeSize != null) { 456 wholeSize.width = wholeSize_out[0]; 457 wholeSize.height = wholeSize_out[1]; 458 } 459 if (ofs != null) { 460 ofs.x = ofs_out[0]; 461 ofs.y = ofs_out[1]; 462 } 463 } 464 465 // 466 // C++: Mat Mat::mul(Mat m, double scale = 1) 467 // 468 469 /** 470 * Element-wise multiplication with scale factor 471 * @param m operand with with which to perform element-wise multiplication 472 * @param scale scale factor 473 * @return new Mat 474 */ 475 public Mat mul(Mat m, double scale) { 476 return new Mat(n_mul(nativeObj, m.nativeObj, scale)); 477 } 478 479 /** 480 * Element-wise multiplication 481 * @param m operand with with which to perform element-wise multiplication 482 * @return new Mat 483 */ 484 public Mat mul(Mat m) { 485 return new Mat(n_mul(nativeObj, m.nativeObj)); 486 } 487 488 /** 489 * Matrix multiplication 490 * @param m operand with with which to perform matrix multiplication 491 * @see Core#gemm(Mat, Mat, double, Mat, double, Mat, int) 492 * @return new Mat 493 */ 494 public Mat matMul(Mat m) { 495 return new Mat(n_matMul(nativeObj, m.nativeObj)); 496 } 497 498 // 499 // C++: static Mat Mat::ones(int rows, int cols, int type) 500 // 501 502 // javadoc: Mat::ones(rows, cols, type) 503 public static Mat ones(int rows, int cols, int type) { 504 return new Mat(n_ones(rows, cols, type)); 505 } 506 507 // 508 // C++: static Mat Mat::ones(Size size, int type) 509 // 510 511 // javadoc: Mat::ones(size, type) 512 public static Mat ones(Size size, int type) { 513 return new Mat(n_ones(size.width, size.height, type)); 514 } 515 516 // 517 // C++: static Mat Mat::ones(int ndims, const int* sizes, int type) 518 // 519 520 // javadoc: Mat::ones(sizes, type) 521 public static Mat ones(int[] sizes, int type) { 522 return new Mat(n_ones(sizes.length, sizes, type)); 523 } 524 525 // 526 // C++: void Mat::push_back(Mat m) 527 // 528 529 // javadoc: Mat::push_back(m) 530 public void push_back(Mat m) { 531 n_push_back(nativeObj, m.nativeObj); 532 } 533 534 // 535 // C++: void Mat::release() 536 // 537 538 // javadoc: Mat::release() 539 public void release() { 540 n_release(nativeObj); 541 } 542 543 // 544 // C++: Mat Mat::reshape(int cn, int rows = 0) 545 // 546 547 // javadoc: Mat::reshape(cn, rows) 548 public Mat reshape(int cn, int rows) { 549 return new Mat(n_reshape(nativeObj, cn, rows)); 550 } 551 552 // javadoc: Mat::reshape(cn) 553 public Mat reshape(int cn) { 554 return new Mat(n_reshape(nativeObj, cn)); 555 } 556 557 // 558 // C++: Mat Mat::reshape(int cn, int newndims, const int* newsz) 559 // 560 561 // javadoc: Mat::reshape(cn, newshape) 562 public Mat reshape(int cn, int[] newshape) { 563 return new Mat(n_reshape_1(nativeObj, cn, newshape.length, newshape)); 564 } 565 566 // 567 // C++: Mat Mat::row(int y) 568 // 569 570 // javadoc: Mat::row(y) 571 public Mat row(int y) { 572 return new Mat(n_row(nativeObj, y)); 573 } 574 575 // 576 // C++: Mat Mat::rowRange(int startrow, int endrow) 577 // 578 579 // javadoc: Mat::rowRange(startrow, endrow) 580 public Mat rowRange(int startrow, int endrow) { 581 return new Mat(n_rowRange(nativeObj, startrow, endrow)); 582 } 583 584 // 585 // C++: Mat Mat::rowRange(Range r) 586 // 587 588 // javadoc: Mat::rowRange(r) 589 public Mat rowRange(Range r) { 590 return new Mat(n_rowRange(nativeObj, r.start, r.end)); 591 } 592 593 // 594 // C++: int Mat::rows() 595 // 596 597 // javadoc: Mat::rows() 598 public int rows() { 599 return n_rows(nativeObj); 600 } 601 602 // 603 // C++: Mat Mat::operator =(Scalar s) 604 // 605 606 // javadoc: Mat::operator =(s) 607 public Mat setTo(Scalar s) { 608 return new Mat(n_setTo(nativeObj, s.val[0], s.val[1], s.val[2], s.val[3])); 609 } 610 611 // 612 // C++: Mat Mat::setTo(Scalar value, Mat mask = Mat()) 613 // 614 615 // javadoc: Mat::setTo(value, mask) 616 public Mat setTo(Scalar value, Mat mask) { 617 return new Mat(n_setTo(nativeObj, value.val[0], value.val[1], value.val[2], value.val[3], mask.nativeObj)); 618 } 619 620 // 621 // C++: Mat Mat::setTo(Mat value, Mat mask = Mat()) 622 // 623 624 // javadoc: Mat::setTo(value, mask) 625 public Mat setTo(Mat value, Mat mask) { 626 return new Mat(n_setTo(nativeObj, value.nativeObj, mask.nativeObj)); 627 } 628 629 // javadoc: Mat::setTo(value) 630 public Mat setTo(Mat value) { 631 return new Mat(n_setTo(nativeObj, value.nativeObj)); 632 } 633 634 // 635 // C++: Size Mat::size() 636 // 637 638 // javadoc: Mat::size() 639 public Size size() { 640 return new Size(n_size(nativeObj)); 641 } 642 643 // 644 // C++: int Mat::size(int i) 645 // 646 647 // javadoc: Mat::size(int i) 648 public int size(int i) { 649 return n_size_i(nativeObj, i); 650 } 651 652 // 653 // C++: size_t Mat::step1(int i = 0) 654 // 655 656 // javadoc: Mat::step1(i) 657 public long step1(int i) { 658 return n_step1(nativeObj, i); 659 } 660 661 // javadoc: Mat::step1() 662 public long step1() { 663 return n_step1(nativeObj); 664 } 665 666 // 667 // C++: Mat Mat::operator()(int rowStart, int rowEnd, int colStart, int 668 // colEnd) 669 // 670 671 // javadoc: Mat::operator()(rowStart, rowEnd, colStart, colEnd) 672 public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) { 673 return new Mat(n_submat_rr(nativeObj, rowStart, rowEnd, colStart, colEnd)); 674 } 675 676 // 677 // C++: Mat Mat::operator()(Range rowRange, Range colRange) 678 // 679 680 // javadoc: Mat::operator()(rowRange, colRange) 681 public Mat submat(Range rowRange, Range colRange) { 682 return new Mat(n_submat_rr(nativeObj, rowRange.start, rowRange.end, colRange.start, colRange.end)); 683 } 684 685 // 686 // C++: Mat Mat::operator()(const std::vector<Range>& ranges) 687 // 688 689 // javadoc: Mat::operator()(ranges[]) 690 public Mat submat(Range[] ranges) { 691 return new Mat(n_submat_ranges(nativeObj, ranges)); 692 } 693 694 // 695 // C++: Mat Mat::operator()(Rect roi) 696 // 697 698 // javadoc: Mat::operator()(roi) 699 public Mat submat(Rect roi) { 700 return new Mat(n_submat(nativeObj, roi.x, roi.y, roi.width, roi.height)); 701 } 702 703 // 704 // C++: Mat Mat::t() 705 // 706 707 // javadoc: Mat::t() 708 public Mat t() { 709 return new Mat(n_t(nativeObj)); 710 } 711 712 // 713 // C++: size_t Mat::total() 714 // 715 716 // javadoc: Mat::total() 717 public long total() { 718 return n_total(nativeObj); 719 } 720 721 // 722 // C++: int Mat::type() 723 // 724 725 // javadoc: Mat::type() 726 public int type() { 727 return n_type(nativeObj); 728 } 729 730 // 731 // C++: static Mat Mat::zeros(int rows, int cols, int type) 732 // 733 734 // javadoc: Mat::zeros(rows, cols, type) 735 public static Mat zeros(int rows, int cols, int type) { 736 return new Mat(n_zeros(rows, cols, type)); 737 } 738 739 // 740 // C++: static Mat Mat::zeros(Size size, int type) 741 // 742 743 // javadoc: Mat::zeros(size, type) 744 public static Mat zeros(Size size, int type) { 745 return new Mat(n_zeros(size.width, size.height, type)); 746 } 747 748 // 749 // C++: static Mat Mat::zeros(int ndims, const int* sizes, int type) 750 // 751 752 // javadoc: Mat::zeros(sizes, type) 753 public static Mat zeros(int[] sizes, int type) { 754 return new Mat(n_zeros(sizes.length, sizes, type)); 755 } 756 757 @Override 758 protected void finalize() throws Throwable { 759 n_delete(nativeObj); 760 super.finalize(); 761 } 762 763 // javadoc:Mat::toString() 764 @Override 765 public String toString() { 766 String _dims = (dims() > 0) ? "" : "-1*-1*"; 767 for (int i=0; i<dims(); i++) { 768 _dims += size(i) + "*"; 769 } 770 return "Mat [ " + _dims + CvType.typeToString(type()) + 771 ", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() + 772 ", nativeObj=0x" + Long.toHexString(nativeObj) + 773 ", dataAddr=0x" + Long.toHexString(dataAddr()) + 774 " ]"; 775 } 776 777 // javadoc:Mat::dump() 778 public String dump() { 779 return nDump(nativeObj); 780 } 781 782 // javadoc:Mat::put(row,col,data) 783 public int put(int row, int col, double... data) { 784 int t = type(); 785 if (data == null || data.length % CvType.channels(t) != 0) 786 throw new UnsupportedOperationException( 787 "Provided data element number (" + 788 (data == null ? 0 : data.length) + 789 ") should be multiple of the Mat channels count (" + 790 CvType.channels(t) + ")"); 791 return nPutD(nativeObj, row, col, data.length, data); 792 } 793 794 // javadoc:Mat::put(idx,data) 795 public int put(int[] idx, double... data) { 796 int t = type(); 797 if (data == null || data.length % CvType.channels(t) != 0) 798 throw new UnsupportedOperationException( 799 "Provided data element number (" + 800 (data == null ? 0 : data.length) + 801 ") should be multiple of the Mat channels count (" + 802 CvType.channels(t) + ")"); 803 if (idx.length != dims()) 804 throw new IllegalArgumentException("Incorrect number of indices"); 805 return nPutDIdx(nativeObj, idx, data.length, data); 806 } 807 808 // javadoc:Mat::put(row,col,data) 809 public int put(int row, int col, float[] data) { 810 int t = type(); 811 if (data == null || data.length % CvType.channels(t) != 0) 812 throw new UnsupportedOperationException( 813 "Provided data element number (" + 814 (data == null ? 0 : data.length) + 815 ") should be multiple of the Mat channels count (" + 816 CvType.channels(t) + ")"); 817 if (CvType.depth(t) == CvType.CV_32F) { 818 return nPutF(nativeObj, row, col, data.length, data); 819 } 820 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 821 } 822 823 // javadoc:Mat::put(idx,data) 824 public int put(int[] idx, float[] data) { 825 int t = type(); 826 if (data == null || data.length % CvType.channels(t) != 0) 827 throw new UnsupportedOperationException( 828 "Provided data element number (" + 829 (data == null ? 0 : data.length) + 830 ") should be multiple of the Mat channels count (" + 831 CvType.channels(t) + ")"); 832 if (idx.length != dims()) 833 throw new IllegalArgumentException("Incorrect number of indices"); 834 if (CvType.depth(t) == CvType.CV_32F) { 835 return nPutFIdx(nativeObj, idx, data.length, data); 836 } 837 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 838 } 839 840 // javadoc:Mat::put(row,col,data) 841 public int put(int row, int col, int[] data) { 842 int t = type(); 843 if (data == null || data.length % CvType.channels(t) != 0) 844 throw new UnsupportedOperationException( 845 "Provided data element number (" + 846 (data == null ? 0 : data.length) + 847 ") should be multiple of the Mat channels count (" + 848 CvType.channels(t) + ")"); 849 if (CvType.depth(t) == CvType.CV_32S) { 850 return nPutI(nativeObj, row, col, data.length, data); 851 } 852 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 853 } 854 855 // javadoc:Mat::put(idx,data) 856 public int put(int[] idx, int[] data) { 857 int t = type(); 858 if (data == null || data.length % CvType.channels(t) != 0) 859 throw new UnsupportedOperationException( 860 "Provided data element number (" + 861 (data == null ? 0 : data.length) + 862 ") should be multiple of the Mat channels count (" + 863 CvType.channels(t) + ")"); 864 if (idx.length != dims()) 865 throw new IllegalArgumentException("Incorrect number of indices"); 866 if (CvType.depth(t) == CvType.CV_32S) { 867 return nPutIIdx(nativeObj, idx, data.length, data); 868 } 869 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 870 } 871 872 // javadoc:Mat::put(row,col,data) 873 public int put(int row, int col, short[] data) { 874 int t = type(); 875 if (data == null || data.length % CvType.channels(t) != 0) 876 throw new UnsupportedOperationException( 877 "Provided data element number (" + 878 (data == null ? 0 : data.length) + 879 ") should be multiple of the Mat channels count (" + 880 CvType.channels(t) + ")"); 881 if (CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { 882 return nPutS(nativeObj, row, col, data.length, data); 883 } 884 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 885 } 886 887 // javadoc:Mat::put(idx,data) 888 public int put(int[] idx, short[] data) { 889 int t = type(); 890 if (data == null || data.length % CvType.channels(t) != 0) 891 throw new UnsupportedOperationException( 892 "Provided data element number (" + 893 (data == null ? 0 : data.length) + 894 ") should be multiple of the Mat channels count (" + 895 CvType.channels(t) + ")"); 896 if (idx.length != dims()) 897 throw new IllegalArgumentException("Incorrect number of indices"); 898 if (CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { 899 return nPutSIdx(nativeObj, idx, data.length, data); 900 } 901 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 902 } 903 904 // javadoc:Mat::put(row,col,data) 905 public int put(int row, int col, byte[] data) { 906 int t = type(); 907 if (data == null || data.length % CvType.channels(t) != 0) 908 throw new UnsupportedOperationException( 909 "Provided data element number (" + 910 (data == null ? 0 : data.length) + 911 ") should be multiple of the Mat channels count (" + 912 CvType.channels(t) + ")"); 913 if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { 914 return nPutB(nativeObj, row, col, data.length, data); 915 } 916 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 917 } 918 919 // javadoc:Mat::put(idx,data) 920 public int put(int[] idx, byte[] data) { 921 int t = type(); 922 if (data == null || data.length % CvType.channels(t) != 0) 923 throw new UnsupportedOperationException( 924 "Provided data element number (" + 925 (data == null ? 0 : data.length) + 926 ") should be multiple of the Mat channels count (" + 927 CvType.channels(t) + ")"); 928 if (idx.length != dims()) 929 throw new IllegalArgumentException("Incorrect number of indices"); 930 if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { 931 return nPutBIdx(nativeObj, idx, data.length, data); 932 } 933 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 934 } 935 936 // javadoc:Mat::put(row,col,data,offset,length) 937 public int put(int row, int col, byte[] data, int offset, int length) { 938 int t = type(); 939 if (data == null || length % CvType.channels(t) != 0) 940 throw new UnsupportedOperationException( 941 "Provided data element number (" + 942 (data == null ? 0 : data.length) + 943 ") should be multiple of the Mat channels count (" + 944 CvType.channels(t) + ")"); 945 if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { 946 return nPutBwOffset(nativeObj, row, col, length, offset, data); 947 } 948 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 949 } 950 951 // javadoc:Mat::put(idx,data,offset,length) 952 public int put(int[] idx, byte[] data, int offset, int length) { 953 int t = type(); 954 if (data == null || length % CvType.channels(t) != 0) 955 throw new UnsupportedOperationException( 956 "Provided data element number (" + 957 (data == null ? 0 : data.length) + 958 ") should be multiple of the Mat channels count (" + 959 CvType.channels(t) + ")"); 960 if (idx.length != dims()) 961 throw new IllegalArgumentException("Incorrect number of indices"); 962 if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { 963 return nPutBwIdxOffset(nativeObj, idx, length, offset, data); 964 } 965 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 966 } 967 968 // javadoc:Mat::get(row,col,data) 969 public int get(int row, int col, byte[] data) { 970 int t = type(); 971 if (data == null || data.length % CvType.channels(t) != 0) 972 throw new UnsupportedOperationException( 973 "Provided data element number (" + 974 (data == null ? 0 : data.length) + 975 ") should be multiple of the Mat channels count (" + 976 CvType.channels(t) + ")"); 977 if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { 978 return nGetB(nativeObj, row, col, data.length, data); 979 } 980 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 981 } 982 983 // javadoc:Mat::get(idx,data) 984 public int get(int[] idx, byte[] data) { 985 int t = type(); 986 if (data == null || data.length % CvType.channels(t) != 0) 987 throw new UnsupportedOperationException( 988 "Provided data element number (" + 989 (data == null ? 0 : data.length) + 990 ") should be multiple of the Mat channels count (" + 991 CvType.channels(t) + ")"); 992 if (idx.length != dims()) 993 throw new IllegalArgumentException("Incorrect number of indices"); 994 if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { 995 return nGetBIdx(nativeObj, idx, data.length, data); 996 } 997 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 998 } 999 1000 // javadoc:Mat::get(row,col,data) 1001 public int get(int row, int col, short[] data) { 1002 int t = type(); 1003 if (data == null || data.length % CvType.channels(t) != 0) 1004 throw new UnsupportedOperationException( 1005 "Provided data element number (" + 1006 (data == null ? 0 : data.length) + 1007 ") should be multiple of the Mat channels count (" + 1008 CvType.channels(t) + ")"); 1009 if (CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { 1010 return nGetS(nativeObj, row, col, data.length, data); 1011 } 1012 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 1013 } 1014 1015 // javadoc:Mat::get(idx,data) 1016 public int get(int[] idx, short[] data) { 1017 int t = type(); 1018 if (data == null || data.length % CvType.channels(t) != 0) 1019 throw new UnsupportedOperationException( 1020 "Provided data element number (" + 1021 (data == null ? 0 : data.length) + 1022 ") should be multiple of the Mat channels count (" + 1023 CvType.channels(t) + ")"); 1024 if (idx.length != dims()) 1025 throw new IllegalArgumentException("Incorrect number of indices"); 1026 if (CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { 1027 return nGetSIdx(nativeObj, idx, data.length, data); 1028 } 1029 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 1030 } 1031 1032 // javadoc:Mat::get(row,col,data) 1033 public int get(int row, int col, int[] data) { 1034 int t = type(); 1035 if (data == null || data.length % CvType.channels(t) != 0) 1036 throw new UnsupportedOperationException( 1037 "Provided data element number (" + 1038 (data == null ? 0 : data.length) + 1039 ") should be multiple of the Mat channels count (" + 1040 CvType.channels(t) + ")"); 1041 if (CvType.depth(t) == CvType.CV_32S) { 1042 return nGetI(nativeObj, row, col, data.length, data); 1043 } 1044 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 1045 } 1046 1047 // javadoc:Mat::get(idx,data) 1048 public int get(int[] idx, int[] data) { 1049 int t = type(); 1050 if (data == null || data.length % CvType.channels(t) != 0) 1051 throw new UnsupportedOperationException( 1052 "Provided data element number (" + 1053 (data == null ? 0 : data.length) + 1054 ") should be multiple of the Mat channels count (" + 1055 CvType.channels(t) + ")"); 1056 if (idx.length != dims()) 1057 throw new IllegalArgumentException("Incorrect number of indices"); 1058 if (CvType.depth(t) == CvType.CV_32S) { 1059 return nGetIIdx(nativeObj, idx, data.length, data); 1060 } 1061 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 1062 } 1063 1064 // javadoc:Mat::get(row,col,data) 1065 public int get(int row, int col, float[] data) { 1066 int t = type(); 1067 if (data == null || data.length % CvType.channels(t) != 0) 1068 throw new UnsupportedOperationException( 1069 "Provided data element number (" + 1070 (data == null ? 0 : data.length) + 1071 ") should be multiple of the Mat channels count (" + 1072 CvType.channels(t) + ")"); 1073 if (CvType.depth(t) == CvType.CV_32F) { 1074 return nGetF(nativeObj, row, col, data.length, data); 1075 } 1076 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 1077 } 1078 1079 // javadoc:Mat::get(idx,data) 1080 public int get(int[] idx, float[] data) { 1081 int t = type(); 1082 if (data == null || data.length % CvType.channels(t) != 0) 1083 throw new UnsupportedOperationException( 1084 "Provided data element number (" + 1085 (data == null ? 0 : data.length) + 1086 ") should be multiple of the Mat channels count (" + 1087 CvType.channels(t) + ")"); 1088 if (idx.length != dims()) 1089 throw new IllegalArgumentException("Incorrect number of indices"); 1090 if (CvType.depth(t) == CvType.CV_32F) { 1091 return nGetFIdx(nativeObj, idx, data.length, data); 1092 } 1093 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 1094 } 1095 1096 // javadoc:Mat::get(row,col,data) 1097 public int get(int row, int col, double[] data) { 1098 int t = type(); 1099 if (data == null || data.length % CvType.channels(t) != 0) 1100 throw new UnsupportedOperationException( 1101 "Provided data element number (" + 1102 (data == null ? 0 : data.length) + 1103 ") should be multiple of the Mat channels count (" + 1104 CvType.channels(t) + ")"); 1105 if (CvType.depth(t) == CvType.CV_64F) { 1106 return nGetD(nativeObj, row, col, data.length, data); 1107 } 1108 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 1109 } 1110 1111 // javadoc:Mat::get(idx,data) 1112 public int get(int[] idx, double[] data) { 1113 int t = type(); 1114 if (data == null || data.length % CvType.channels(t) != 0) 1115 throw new UnsupportedOperationException( 1116 "Provided data element number (" + 1117 (data == null ? 0 : data.length) + 1118 ") should be multiple of the Mat channels count (" + 1119 CvType.channels(t) + ")"); 1120 if (idx.length != dims()) 1121 throw new IllegalArgumentException("Incorrect number of indices"); 1122 if (CvType.depth(t) == CvType.CV_64F) { 1123 return nGetDIdx(nativeObj, idx, data.length, data); 1124 } 1125 throw new UnsupportedOperationException("Mat data type is not compatible: " + t); 1126 } 1127 1128 // javadoc:Mat::get(row,col) 1129 public double[] get(int row, int col) { 1130 return nGet(nativeObj, row, col); 1131 } 1132 1133 // javadoc:Mat::get(idx) 1134 public double[] get(int[] idx) { 1135 if (idx.length != dims()) 1136 throw new IllegalArgumentException("Incorrect number of indices"); 1137 return nGetIdx(nativeObj, idx); 1138 } 1139 1140 // javadoc:Mat::height() 1141 public int height() { 1142 return rows(); 1143 } 1144 1145 // javadoc:Mat::width() 1146 public int width() { 1147 return cols(); 1148 } 1149 1150 // javadoc:Mat::at(clazz, row, col) 1151 @SuppressWarnings("unchecked") 1152 public <T> Atable<T> at(Class<T> clazz, int row, int col) { 1153 if (clazz == Byte.class || clazz == byte.class) { 1154 return (Atable<T>)new AtableByte(this, row, col); 1155 } else if (clazz == Double.class || clazz == double.class) { 1156 return (Atable<T>)new AtableDouble(this, row, col); 1157 } else if (clazz == Float.class || clazz == float.class) { 1158 return (Atable<T>)new AtableFloat(this, row, col); 1159 } else if (clazz == Integer.class || clazz == int.class) { 1160 return (Atable<T>)new AtableInteger(this, row, col); 1161 } else if (clazz == Short.class || clazz == short.class) { 1162 return (Atable<T>)new AtableShort(this, row, col); 1163 } else { 1164 throw new RuntimeException("Unsupported class type"); 1165 } 1166 } 1167 1168 // javadoc:Mat::at(clazz, idx) 1169 @SuppressWarnings("unchecked") 1170 public <T> Atable<T> at(Class<T> clazz, int[] idx) { 1171 if (clazz == Byte.class || clazz == byte.class) { 1172 return (Atable<T>)new AtableByte(this, idx); 1173 } else if (clazz == Double.class || clazz == double.class) { 1174 return (Atable<T>)new AtableDouble(this, idx); 1175 } else if (clazz == Float.class || clazz == float.class) { 1176 return (Atable<T>)new AtableFloat(this, idx); 1177 } else if (clazz == Integer.class || clazz == int.class) { 1178 return (Atable<T>)new AtableInteger(this, idx); 1179 } else if (clazz == Short.class || clazz == short.class) { 1180 return (Atable<T>)new AtableShort(this, idx); 1181 } else { 1182 throw new RuntimeException("Unsupported class parameter"); 1183 } 1184 } 1185 1186 public static class Tuple2<T> { 1187 public Tuple2(T _0, T _1) { 1188 this._0 = _0; 1189 this._1 = _1; 1190 } 1191 1192 public T get_0() { 1193 return _0; 1194 } 1195 1196 public T get_1() { 1197 return _1; 1198 } 1199 1200 private final T _0; 1201 private final T _1; 1202 } 1203 1204 public static class Tuple3<T> { 1205 public Tuple3(T _0, T _1, T _2) { 1206 this._0 = _0; 1207 this._1 = _1; 1208 this._2 = _2; 1209 } 1210 1211 public T get_0() { 1212 return _0; 1213 } 1214 1215 public T get_1() { 1216 return _1; 1217 } 1218 1219 public T get_2() { 1220 return _2; 1221 } 1222 1223 private final T _0; 1224 private final T _1; 1225 private final T _2; 1226 } 1227 1228 public static class Tuple4<T> { 1229 public Tuple4(T _0, T _1, T _2, T _3) { 1230 this._0 = _0; 1231 this._1 = _1; 1232 this._2 = _2; 1233 this._3 = _3; 1234 } 1235 1236 public T get_0() { 1237 return _0; 1238 } 1239 1240 public T get_1() { 1241 return _1; 1242 } 1243 1244 public T get_2() { 1245 return _2; 1246 } 1247 1248 public T get_3() { 1249 return _3; 1250 } 1251 1252 private final T _0; 1253 private final T _1; 1254 private final T _2; 1255 private final T _3; 1256 } 1257 1258 public interface Atable<T> { 1259 T getV(); 1260 void setV(T v); 1261 Tuple2<T> getV2c(); 1262 void setV2c(Tuple2<T> v); 1263 Tuple3<T> getV3c(); 1264 void setV3c(Tuple3<T> v); 1265 Tuple4<T> getV4c(); 1266 void setV4c(Tuple4<T> v); 1267 } 1268 1269 private static class AtableBase { 1270 1271 protected AtableBase(Mat mat, int row, int col) { 1272 this.mat = mat; 1273 indices = new int[2]; 1274 indices[0] = row; 1275 indices[1] = col; 1276 } 1277 1278 protected AtableBase(Mat mat, int[] indices) { 1279 this.mat = mat; 1280 this.indices = indices; 1281 } 1282 1283 protected final Mat mat; 1284 protected final int[] indices; 1285 } 1286 1287 private static class AtableByte extends AtableBase implements Atable<Byte> { 1288 1289 public AtableByte(Mat mat, int row, int col) { 1290 super(mat, row, col); 1291 } 1292 1293 public AtableByte(Mat mat, int[] indices) { 1294 super(mat, indices); 1295 } 1296 1297 @Override 1298 public Byte getV() { 1299 byte[] data = new byte[1]; 1300 mat.get(indices, data); 1301 return data[0]; 1302 } 1303 1304 @Override 1305 public void setV(Byte v) { 1306 byte[] data = new byte[] { v }; 1307 mat.put(indices, data); 1308 } 1309 1310 @Override 1311 public Tuple2<Byte> getV2c() { 1312 byte[] data = new byte[2]; 1313 mat.get(indices, data); 1314 return new Tuple2<Byte>(data[0], data[1]); 1315 } 1316 1317 @Override 1318 public void setV2c(Tuple2<Byte> v) { 1319 byte[] data = new byte[] { v._0, v._1 }; 1320 mat.put(indices, data); 1321 } 1322 1323 @Override 1324 public Tuple3<Byte> getV3c() { 1325 byte[] data = new byte[3]; 1326 mat.get(indices, data); 1327 return new Tuple3<Byte>(data[0], data[1], data[2]); 1328 } 1329 1330 @Override 1331 public void setV3c(Tuple3<Byte> v) { 1332 byte[] data = new byte[] { v._0, v._1, v._2 }; 1333 mat.put(indices, data); 1334 } 1335 1336 @Override 1337 public Tuple4<Byte> getV4c() { 1338 byte[] data = new byte[4]; 1339 mat.get(indices, data); 1340 return new Tuple4<Byte>(data[0], data[1], data[2], data[3]); 1341 } 1342 1343 @Override 1344 public void setV4c(Tuple4<Byte> v) { 1345 byte[] data = new byte[] { v._0, v._1, v._2, v._3 }; 1346 mat.put(indices, data); 1347 } 1348 } 1349 1350 private static class AtableDouble extends AtableBase implements Atable<Double> { 1351 1352 public AtableDouble(Mat mat, int row, int col) { 1353 super(mat, row, col); 1354 } 1355 1356 public AtableDouble(Mat mat, int[] indices) { 1357 super(mat, indices); 1358 } 1359 1360 @Override 1361 public Double getV() { 1362 double[] data = new double[1]; 1363 mat.get(indices, data); 1364 return data[0]; 1365 } 1366 1367 @Override 1368 public void setV(Double v) { 1369 double[] data = new double[] { v }; 1370 mat.put(indices, data); 1371 } 1372 1373 @Override 1374 public Tuple2<Double> getV2c() { 1375 double[] data = new double[2]; 1376 mat.get(indices, data); 1377 return new Tuple2<Double>(data[0], data[1]); 1378 } 1379 1380 @Override 1381 public void setV2c(Tuple2<Double> v) { 1382 double[] data = new double[] { v._0, v._1 }; 1383 mat.put(indices, data); 1384 } 1385 1386 @Override 1387 public Tuple3<Double> getV3c() { 1388 double[] data = new double[3]; 1389 mat.get(indices, data); 1390 return new Tuple3<Double>(data[0], data[1], data[2]); 1391 } 1392 1393 @Override 1394 public void setV3c(Tuple3<Double> v) { 1395 double[] data = new double[] { v._0, v._1, v._2 }; 1396 mat.put(indices, data); 1397 } 1398 1399 @Override 1400 public Tuple4<Double> getV4c() { 1401 double[] data = new double[4]; 1402 mat.get(indices, data); 1403 return new Tuple4<Double>(data[0], data[1], data[2], data[3]); 1404 } 1405 1406 @Override 1407 public void setV4c(Tuple4<Double> v) { 1408 double[] data = new double[] { v._0, v._1, v._2, v._3 }; 1409 mat.put(indices, data); 1410 } 1411 } 1412 1413 private static class AtableFloat extends AtableBase implements Atable<Float> { 1414 1415 public AtableFloat(Mat mat, int row, int col) { 1416 super(mat, row, col); 1417 } 1418 1419 public AtableFloat(Mat mat, int[] indices) { 1420 super(mat, indices); 1421 } 1422 1423 @Override 1424 public Float getV() { 1425 float[] data = new float[1]; 1426 mat.get(indices, data); 1427 return data[0]; 1428 } 1429 1430 @Override 1431 public void setV(Float v) { 1432 float[] data = new float[] { v }; 1433 mat.put(indices, data); 1434 } 1435 1436 @Override 1437 public Tuple2<Float> getV2c() { 1438 float[] data = new float[2]; 1439 mat.get(indices, data); 1440 return new Tuple2<Float>(data[0], data[1]); 1441 } 1442 1443 @Override 1444 public void setV2c(Tuple2<Float> v) { 1445 float[] data = new float[] { v._0, v._1 }; 1446 mat.put(indices, data); 1447 } 1448 1449 @Override 1450 public Tuple3<Float> getV3c() { 1451 float[] data = new float[3]; 1452 mat.get(indices, data); 1453 return new Tuple3<Float>(data[0], data[1], data[2]); 1454 } 1455 1456 @Override 1457 public void setV3c(Tuple3<Float> v) { 1458 float[] data = new float[] { v._0, v._1, v._2 }; 1459 mat.put(indices, data); 1460 } 1461 1462 @Override 1463 public Tuple4<Float> getV4c() { 1464 float[] data = new float[4]; 1465 mat.get(indices, data); 1466 return new Tuple4<Float>(data[0], data[1], data[2], data[3]); 1467 } 1468 1469 @Override 1470 public void setV4c(Tuple4<Float> v) { 1471 double[] data = new double[] { v._0, v._1, v._2, v._3 }; 1472 mat.put(indices, data); 1473 } 1474 } 1475 1476 private static class AtableInteger extends AtableBase implements Atable<Integer> { 1477 1478 public AtableInteger(Mat mat, int row, int col) { 1479 super(mat, row, col); 1480 } 1481 1482 public AtableInteger(Mat mat, int[] indices) { 1483 super(mat, indices); 1484 } 1485 1486 @Override 1487 public Integer getV() { 1488 int[] data = new int[1]; 1489 mat.get(indices, data); 1490 return data[0]; 1491 } 1492 1493 @Override 1494 public void setV(Integer v) { 1495 int[] data = new int[] { v }; 1496 mat.put(indices, data); 1497 } 1498 1499 @Override 1500 public Tuple2<Integer> getV2c() { 1501 int[] data = new int[2]; 1502 mat.get(indices, data); 1503 return new Tuple2<Integer>(data[0], data[1]); 1504 } 1505 1506 @Override 1507 public void setV2c(Tuple2<Integer> v) { 1508 int[] data = new int[] { v._0, v._1 }; 1509 mat.put(indices, data); 1510 } 1511 1512 @Override 1513 public Tuple3<Integer> getV3c() { 1514 int[] data = new int[3]; 1515 mat.get(indices, data); 1516 return new Tuple3<Integer>(data[0], data[1], data[2]); 1517 } 1518 1519 @Override 1520 public void setV3c(Tuple3<Integer> v) { 1521 int[] data = new int[] { v._0, v._1, v._2 }; 1522 mat.put(indices, data); 1523 } 1524 1525 @Override 1526 public Tuple4<Integer> getV4c() { 1527 int[] data = new int[4]; 1528 mat.get(indices, data); 1529 return new Tuple4<Integer>(data[0], data[1], data[2], data[3]); 1530 } 1531 1532 @Override 1533 public void setV4c(Tuple4<Integer> v) { 1534 int[] data = new int[] { v._0, v._1, v._2, v._3 }; 1535 mat.put(indices, data); 1536 } 1537 } 1538 1539 private static class AtableShort extends AtableBase implements Atable<Short> { 1540 1541 public AtableShort(Mat mat, int row, int col) { 1542 super(mat, row, col); 1543 } 1544 1545 public AtableShort(Mat mat, int[] indices) { 1546 super(mat, indices); 1547 } 1548 1549 @Override 1550 public Short getV() { 1551 short[] data = new short[1]; 1552 mat.get(indices, data); 1553 return data[0]; 1554 } 1555 1556 @Override 1557 public void setV(Short v) { 1558 short[] data = new short[] { v }; 1559 mat.put(indices, data); 1560 } 1561 1562 @Override 1563 public Tuple2<Short> getV2c() { 1564 short[] data = new short[2]; 1565 mat.get(indices, data); 1566 return new Tuple2<Short>(data[0], data[1]); 1567 } 1568 1569 @Override 1570 public void setV2c(Tuple2<Short> v) { 1571 short[] data = new short[] { v._0, v._1 }; 1572 mat.put(indices, data); 1573 } 1574 1575 @Override 1576 public Tuple3<Short> getV3c() { 1577 short[] data = new short[3]; 1578 mat.get(indices, data); 1579 return new Tuple3<Short>(data[0], data[1], data[2]); 1580 } 1581 1582 @Override 1583 public void setV3c(Tuple3<Short> v) { 1584 short[] data = new short[] { v._0, v._1, v._2 }; 1585 mat.put(indices, data); 1586 } 1587 1588 @Override 1589 public Tuple4<Short> getV4c() { 1590 short[] data = new short[4]; 1591 mat.get(indices, data); 1592 return new Tuple4<Short>(data[0], data[1], data[2], data[3]); 1593 } 1594 1595 @Override 1596 public void setV4c(Tuple4<Short> v) { 1597 short[] data = new short[] { v._0, v._1, v._2, v._3 }; 1598 mat.put(indices, data); 1599 } 1600 } 1601 1602 // javadoc:Mat::getNativeObjAddr() 1603 public long getNativeObjAddr() { 1604 return nativeObj; 1605 } 1606 1607 // C++: Mat::Mat() 1608 private static native long n_Mat(); 1609 1610 // C++: Mat::Mat(int rows, int cols, int type) 1611 private static native long n_Mat(int rows, int cols, int type); 1612 1613 // C++: Mat::Mat(int ndims, const int* sizes, int type) 1614 private static native long n_Mat(int ndims, int[] sizes, int type); 1615 1616 // C++: Mat::Mat(int rows, int cols, int type, void* data) 1617 private static native long n_Mat(int rows, int cols, int type, ByteBuffer data); 1618 1619 // C++: Mat::Mat(int rows, int cols, int type, void* data, size_t step) 1620 private static native long n_Mat(int rows, int cols, int type, ByteBuffer data, long step); 1621 1622 // C++: Mat::Mat(Size size, int type) 1623 private static native long n_Mat(double size_width, double size_height, int type); 1624 1625 // C++: Mat::Mat(int rows, int cols, int type, Scalar s) 1626 private static native long n_Mat(int rows, int cols, int type, double s_val0, double s_val1, double s_val2, double s_val3); 1627 1628 // C++: Mat::Mat(Size size, int type, Scalar s) 1629 private static native long n_Mat(double size_width, double size_height, int type, double s_val0, double s_val1, double s_val2, double s_val3); 1630 1631 // C++: Mat::Mat(int ndims, const int* sizes, int type, Scalar s) 1632 private static native long n_Mat(int ndims, int[] sizes, int type, double s_val0, double s_val1, double s_val2, double s_val3); 1633 1634 // C++: Mat::Mat(Mat m, Range rowRange, Range colRange = Range::all()) 1635 private static native long n_Mat(long m_nativeObj, int rowRange_start, int rowRange_end, int colRange_start, int colRange_end); 1636 1637 private static native long n_Mat(long m_nativeObj, int rowRange_start, int rowRange_end); 1638 1639 // C++: Mat::Mat(const Mat& m, const std::vector<Range>& ranges) 1640 private static native long n_Mat(long m_nativeObj, Range[] ranges); 1641 1642 // C++: Mat Mat::adjustROI(int dtop, int dbottom, int dleft, int dright) 1643 private static native long n_adjustROI(long nativeObj, int dtop, int dbottom, int dleft, int dright); 1644 1645 // C++: void Mat::assignTo(Mat m, int type = -1) 1646 private static native void n_assignTo(long nativeObj, long m_nativeObj, int type); 1647 1648 private static native void n_assignTo(long nativeObj, long m_nativeObj); 1649 1650 // C++: int Mat::channels() 1651 private static native int n_channels(long nativeObj); 1652 1653 // C++: int Mat::checkVector(int elemChannels, int depth = -1, bool 1654 // requireContinuous = true) 1655 private static native int n_checkVector(long nativeObj, int elemChannels, int depth, boolean requireContinuous); 1656 1657 private static native int n_checkVector(long nativeObj, int elemChannels, int depth); 1658 1659 private static native int n_checkVector(long nativeObj, int elemChannels); 1660 1661 // C++: Mat Mat::clone() 1662 private static native long n_clone(long nativeObj); 1663 1664 // C++: Mat Mat::col(int x) 1665 private static native long n_col(long nativeObj, int x); 1666 1667 // C++: Mat Mat::colRange(int startcol, int endcol) 1668 private static native long n_colRange(long nativeObj, int startcol, int endcol); 1669 1670 // C++: int Mat::dims() 1671 private static native int n_dims(long nativeObj); 1672 1673 // C++: int Mat::cols() 1674 private static native int n_cols(long nativeObj); 1675 1676 // C++: void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta 1677 // = 0) 1678 private static native void n_convertTo(long nativeObj, long m_nativeObj, int rtype, double alpha, double beta); 1679 1680 private static native void n_convertTo(long nativeObj, long m_nativeObj, int rtype, double alpha); 1681 1682 private static native void n_convertTo(long nativeObj, long m_nativeObj, int rtype); 1683 1684 // C++: void Mat::copyTo(Mat& m) 1685 private static native void n_copyTo(long nativeObj, long m_nativeObj); 1686 1687 // C++: void Mat::copyTo(Mat& m, Mat mask) 1688 private static native void n_copyTo(long nativeObj, long m_nativeObj, long mask_nativeObj); 1689 1690 // C++: void Mat::create(int rows, int cols, int type) 1691 private static native void n_create(long nativeObj, int rows, int cols, int type); 1692 1693 // C++: void Mat::create(Size size, int type) 1694 private static native void n_create(long nativeObj, double size_width, double size_height, int type); 1695 1696 // C++: void Mat::create(int ndims, const int* sizes, int type) 1697 private static native void n_create(long nativeObj, int ndims, int[] sizes, int type); 1698 1699 // C++: void Mat::copySize(const Mat& m) 1700 private static native void n_copySize(long nativeObj, long m_nativeObj); 1701 1702 // C++: Mat Mat::cross(Mat m) 1703 private static native long n_cross(long nativeObj, long m_nativeObj); 1704 1705 // C++: long Mat::dataAddr() 1706 private static native long n_dataAddr(long nativeObj); 1707 1708 // C++: int Mat::depth() 1709 private static native int n_depth(long nativeObj); 1710 1711 // C++: Mat Mat::diag(int d = 0) 1712 private static native long n_diag(long nativeObj, int d); 1713 1714 // C++: static Mat Mat::diag(Mat d) 1715 private static native long n_diag(long d_nativeObj); 1716 1717 // C++: double Mat::dot(Mat m) 1718 private static native double n_dot(long nativeObj, long m_nativeObj); 1719 1720 // C++: size_t Mat::elemSize() 1721 private static native long n_elemSize(long nativeObj); 1722 1723 // C++: size_t Mat::elemSize1() 1724 private static native long n_elemSize1(long nativeObj); 1725 1726 // C++: bool Mat::empty() 1727 private static native boolean n_empty(long nativeObj); 1728 1729 // C++: static Mat Mat::eye(int rows, int cols, int type) 1730 private static native long n_eye(int rows, int cols, int type); 1731 1732 // C++: static Mat Mat::eye(Size size, int type) 1733 private static native long n_eye(double size_width, double size_height, int type); 1734 1735 // C++: Mat Mat::inv(int method = DECOMP_LU) 1736 private static native long n_inv(long nativeObj, int method); 1737 1738 private static native long n_inv(long nativeObj); 1739 1740 // C++: bool Mat::isContinuous() 1741 private static native boolean n_isContinuous(long nativeObj); 1742 1743 // C++: bool Mat::isSubmatrix() 1744 private static native boolean n_isSubmatrix(long nativeObj); 1745 1746 // C++: void Mat::locateROI(Size wholeSize, Point ofs) 1747 private static native void locateROI_0(long nativeObj, double[] wholeSize_out, double[] ofs_out); 1748 1749 // C++: Mat Mat::mul(Mat m, double scale = 1) 1750 private static native long n_mul(long nativeObj, long m_nativeObj, double scale); 1751 1752 private static native long n_mul(long nativeObj, long m_nativeObj); 1753 1754 private static native long n_matMul(long nativeObj, long m_nativeObj); 1755 1756 // C++: static Mat Mat::ones(int rows, int cols, int type) 1757 private static native long n_ones(int rows, int cols, int type); 1758 1759 // C++: static Mat Mat::ones(Size size, int type) 1760 private static native long n_ones(double size_width, double size_height, int type); 1761 1762 // C++: static Mat Mat::ones(int ndims, const int* sizes, int type) 1763 private static native long n_ones(int ndims, int[] sizes, int type); 1764 1765 // C++: void Mat::push_back(Mat m) 1766 private static native void n_push_back(long nativeObj, long m_nativeObj); 1767 1768 // C++: void Mat::release() 1769 private static native void n_release(long nativeObj); 1770 1771 // C++: Mat Mat::reshape(int cn, int rows = 0) 1772 private static native long n_reshape(long nativeObj, int cn, int rows); 1773 1774 private static native long n_reshape(long nativeObj, int cn); 1775 1776 // C++: Mat Mat::reshape(int cn, int newndims, const int* newsz) 1777 private static native long n_reshape_1(long nativeObj, int cn, int newndims, int[] newsz); 1778 1779 // C++: Mat Mat::row(int y) 1780 private static native long n_row(long nativeObj, int y); 1781 1782 // C++: Mat Mat::rowRange(int startrow, int endrow) 1783 private static native long n_rowRange(long nativeObj, int startrow, int endrow); 1784 1785 // C++: int Mat::rows() 1786 private static native int n_rows(long nativeObj); 1787 1788 // C++: Mat Mat::operator =(Scalar s) 1789 private static native long n_setTo(long nativeObj, double s_val0, double s_val1, double s_val2, double s_val3); 1790 1791 // C++: Mat Mat::setTo(Scalar value, Mat mask = Mat()) 1792 private static native long n_setTo(long nativeObj, double s_val0, double s_val1, double s_val2, double s_val3, long mask_nativeObj); 1793 1794 // C++: Mat Mat::setTo(Mat value, Mat mask = Mat()) 1795 private static native long n_setTo(long nativeObj, long value_nativeObj, long mask_nativeObj); 1796 1797 private static native long n_setTo(long nativeObj, long value_nativeObj); 1798 1799 // C++: Size Mat::size() 1800 private static native double[] n_size(long nativeObj); 1801 1802 // C++: int Mat::size(int i) 1803 private static native int n_size_i(long nativeObj, int i); 1804 1805 // C++: size_t Mat::step1(int i = 0) 1806 private static native long n_step1(long nativeObj, int i); 1807 1808 private static native long n_step1(long nativeObj); 1809 1810 // C++: Mat Mat::operator()(Range rowRange, Range colRange) 1811 private static native long n_submat_rr(long nativeObj, int rowRange_start, int rowRange_end, int colRange_start, int colRange_end); 1812 1813 // C++: Mat Mat::operator()(const std::vector<Range>& ranges) 1814 private static native long n_submat_ranges(long nativeObj, Range[] ranges); 1815 1816 // C++: Mat Mat::operator()(Rect roi) 1817 private static native long n_submat(long nativeObj, int roi_x, int roi_y, int roi_width, int roi_height); 1818 1819 // C++: Mat Mat::t() 1820 private static native long n_t(long nativeObj); 1821 1822 // C++: size_t Mat::total() 1823 private static native long n_total(long nativeObj); 1824 1825 // C++: int Mat::type() 1826 private static native int n_type(long nativeObj); 1827 1828 // C++: static Mat Mat::zeros(int rows, int cols, int type) 1829 private static native long n_zeros(int rows, int cols, int type); 1830 1831 // C++: static Mat Mat::zeros(Size size, int type) 1832 private static native long n_zeros(double size_width, double size_height, int type); 1833 1834 // C++: static Mat Mat::zeros(int ndims, const int* sizes, int type) 1835 private static native long n_zeros(int ndims, int[] sizes, int type); 1836 1837 // native support for java finalize() 1838 private static native void n_delete(long nativeObj); 1839 1840 private static native int nPutD(long self, int row, int col, int count, double[] data); 1841 1842 private static native int nPutDIdx(long self, int[] idx, int count, double[] data); 1843 1844 private static native int nPutF(long self, int row, int col, int count, float[] data); 1845 1846 private static native int nPutFIdx(long self, int[] idx, int count, float[] data); 1847 1848 private static native int nPutI(long self, int row, int col, int count, int[] data); 1849 1850 private static native int nPutIIdx(long self, int[] idx, int count, int[] data); 1851 1852 private static native int nPutS(long self, int row, int col, int count, short[] data); 1853 1854 private static native int nPutSIdx(long self, int[] idx, int count, short[] data); 1855 1856 private static native int nPutB(long self, int row, int col, int count, byte[] data); 1857 1858 private static native int nPutBIdx(long self, int[] idx, int count, byte[] data); 1859 1860 private static native int nPutBwOffset(long self, int row, int col, int count, int offset, byte[] data); 1861 1862 private static native int nPutBwIdxOffset(long self, int[] idx, int count, int offset, byte[] data); 1863 1864 private static native int nGetB(long self, int row, int col, int count, byte[] vals); 1865 1866 private static native int nGetBIdx(long self, int[] idx, int count, byte[] vals); 1867 1868 private static native int nGetS(long self, int row, int col, int count, short[] vals); 1869 1870 private static native int nGetSIdx(long self, int[] idx, int count, short[] vals); 1871 1872 private static native int nGetI(long self, int row, int col, int count, int[] vals); 1873 1874 private static native int nGetIIdx(long self, int[] idx, int count, int[] vals); 1875 1876 private static native int nGetF(long self, int row, int col, int count, float[] vals); 1877 1878 private static native int nGetFIdx(long self, int[] idx, int count, float[] vals); 1879 1880 private static native int nGetD(long self, int row, int col, int count, double[] vals); 1881 1882 private static native int nGetDIdx(long self, int[] idx, int count, double[] vals); 1883 1884 private static native double[] nGet(long self, int row, int col); 1885 1886 private static native double[] nGetIdx(long self, int[] idx); 1887 1888 private static native String nDump(long self); 1889}