diff --git a/modules/java/src/java/AsyncServiceHelper.java b/modules/java/src/java/AsyncServiceHelper.java deleted file mode 100644 index 0bcddb014b..0000000000 --- a/modules/java/src/java/AsyncServiceHelper.java +++ /dev/null @@ -1,165 +0,0 @@ -package org.opencv.android; - -import java.io.File; -import java.util.StringTokenizer; - -import org.opencv.engine.OpenCVEngineInterface; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.os.IBinder; -import android.os.RemoteException; -import android.util.Log; - -public class AsyncServiceHelper -{ - public static int initOpenCV(String Version, Context AppContext, - LoaderCallbackInterface Callback) - { - AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback); - if (AppContext.bindService(new Intent("org.opencv.engine.BIND"), - helper.mServiceConnection, Context.BIND_AUTO_CREATE)) - { - return OpenCVLoader.Success; - } - else - { - return OpenCVLoader.NoService; - } - } - - protected AsyncServiceHelper(String Version, Context AppContext, - LoaderCallbackInterface Callback) - { - mOpenCVersion = Version; - mUserAppCallback = Callback; - mAppContext = AppContext; - } - - protected static final String TAG = "OpenCvEngine/Helper"; - protected OpenCVEngineInterface mEngineService; - protected LoaderCallbackInterface mUserAppCallback; - protected String mOpenCVersion; - protected Context mAppContext; - protected int mStatus = OpenCVLoader.Success; - - protected ServiceConnection mServiceConnection = new ServiceConnection() - { - public void onServiceConnected(ComponentName className, IBinder service) - { - Log.d(TAG, "Service connection created"); - mEngineService = OpenCVEngineInterface.Stub.asInterface(service); - if (null == mEngineService) - { - Log.d(TAG, "Engine connection fails. May be service was not installed?"); - mStatus = OpenCVLoader.NoService; - } - else - { - try - { - Log.d(TAG, "Trying to get library path"); - String path = mEngineService.getLibPathByVersion(mOpenCVersion); - if ((null == path) || (path.length() == 0)) - { - if (mEngineService.installVersion(mOpenCVersion)) - { - mStatus = OpenCVLoader.RestartRequired; - } - else - { - Log.d(TAG, "OpenCV package was not installed!"); - mStatus = OpenCVLoader.MarketError; - } - } - else - { - Log.d(TAG, "Trying to get library list"); - String libs = mEngineService.getLibraryList(mOpenCVersion); - Log.d(TAG, "Library list: \"" + libs + "\""); - Log.d(TAG, "First attempt to load libs"); - if (initOpenCVLibs(path, libs)) - { - Log.d(TAG, "First attempt to load libs is OK"); - mStatus = OpenCVLoader.Success; - } - else - { - Log.d(TAG, "First attempt to load libs fails"); - mStatus = OpenCVLoader.InitFailed; - } - } - } - catch (RemoteException e) - { - e.printStackTrace(); - mStatus = OpenCVLoader.InitFailed; - } - } - Log.d(TAG, "Init finished with status " + mStatus); - Log.d(TAG, "Unbind from service"); - mAppContext.unbindService(mServiceConnection); - Log.d(TAG, "Calling using callback"); - mUserAppCallback.onEngineConnected(mStatus); - } - - private boolean loadLibrary(String AbsPath) - { - boolean result = true; - - Log.d(TAG, "Trying to load library " + AbsPath); - try - { - System.load(AbsPath); - Log.d(TAG, "OpenCV libs init was ok!"); - } - catch(Exception e) - { - Log.d(TAG, "Cannot load library \"" + AbsPath + "\""); - e.printStackTrace(); - result &= false; - } - - return result; - } - - private boolean initOpenCVLibs(String Path, String Libs) - { - Log.d(TAG, "Trying to init OpenCV libs"); - if ((null != Path) && (Path.length() != 0)) - { - boolean result = true; - if ((null != Libs) && (Libs.length() != 0)) - { - Log.d(TAG, "Trying to load libs by dependency list"); - StringTokenizer splitter = new StringTokenizer(Libs, ";"); - while(splitter.hasMoreTokens()) - { - String AbsLibraryPath = Path + File.separator + splitter.nextToken(); - result &= loadLibrary(AbsLibraryPath); - } - } - else - { - // If dependencies list is not defined or empty - String AbsLibraryPath = Path + File.separator + "libopencv_java.so"; - result &= loadLibrary(AbsLibraryPath); - } - - return result; - } - else - { - Log.d(TAG, "Library path \"" + Path + "\" is empty"); - return false; - } - } - - public void onServiceDisconnected(ComponentName className) - { - mEngineService = null; - } - }; -} diff --git a/modules/java/src/java/LoaderCallbackInterface.java b/modules/java/src/java/LoaderCallbackInterface.java deleted file mode 100644 index db8317b130..0000000000 --- a/modules/java/src/java/LoaderCallbackInterface.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.opencv.android; - -public interface LoaderCallbackInterface -{ - public void onEngineConnected(int status); -}; diff --git a/modules/java/src/java/OpenCVLoader.java b/modules/java/src/java/OpenCVLoader.java deleted file mode 100644 index 76ac6b12a6..0000000000 --- a/modules/java/src/java/OpenCVLoader.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.opencv.android; - -import android.content.Context; -import android.util.Log; - -public class OpenCVLoader -{ - public static final int Success = 0; - public static final int NoService = 1; - public static final int RestartRequired = 2; - public static final int MarketError = 3; - public static final int InitFailed = 0xff; - - public static int initStatic() - { - int result; - - try - { - System.loadLibrary("opencv_java"); - result = Success; - } - catch(Exception e) - { - Log.e(TAG, "OpenCV error: Cannot load native library"); - e.printStackTrace(); - result = InitFailed; - } - - return result; - } - - public static int initAsync(String Version, Context AppContext, - LoaderCallbackInterface Callback) - { - return AsyncServiceHelper.initOpenCV(Version, AppContext, Callback); - } - - private static final String TAG = "OpenCV/Helper"; -} diff --git a/modules/java/src/java/android+Utils.java b/modules/java/src/java/android+Utils.java index 7a3c915a0a..756bd6dd85 100644 --- a/modules/java/src/java/android+Utils.java +++ b/modules/java/src/java/android+Utils.java @@ -113,6 +113,11 @@ public class Utils { nMatToBitmap(m.nativeObj, b); } + // native stuff + static { + System.loadLibrary("opencv_java"); + } + private static native void nBitmapToMat(Bitmap b, long m_addr); private static native void nMatToBitmap(long m_addr, Bitmap b); diff --git a/modules/java/src/java/core+Mat.java b/modules/java/src/java/core+Mat.java index c283c4428b..3943380795 100644 --- a/modules/java/src/java/core+Mat.java +++ b/modules/java/src/java/core+Mat.java @@ -1,1284 +1,1291 @@ -package org.opencv.core; - -// C++: class Mat -//javadoc: Mat -public class Mat { - - public final long nativeObj; - - public Mat(long addr) - { - if (addr == 0) - throw new java.lang.UnsupportedOperationException("Native object address is NULL"); - nativeObj = addr; - } - - // - // C++: Mat::Mat() - // - - // javadoc: Mat::Mat() - public Mat() - { - - nativeObj = n_Mat(); - - return; - } - - // - // C++: Mat::Mat(int rows, int cols, int type) - // - - // javadoc: Mat::Mat(rows, cols, type) - public Mat(int rows, int cols, int type) - { - - nativeObj = n_Mat(rows, cols, type); - - return; - } - - // - // C++: Mat::Mat(Size size, int type) - // - - // javadoc: Mat::Mat(size, type) - public Mat(Size size, int type) - { - - nativeObj = n_Mat(size.width, size.height, type); - - return; - } - - // - // C++: Mat::Mat(int rows, int cols, int type, Scalar s) - // - - // javadoc: Mat::Mat(rows, cols, type, s) - public Mat(int rows, int cols, int type, Scalar s) - { - - nativeObj = n_Mat(rows, cols, type, s.val[0], s.val[1], s.val[2], s.val[3]); - - return; - } - - // - // C++: Mat::Mat(Size size, int type, Scalar s) - // - - // javadoc: Mat::Mat(size, type, s) - public Mat(Size size, int type, Scalar s) - { - - nativeObj = n_Mat(size.width, size.height, type, s.val[0], s.val[1], s.val[2], s.val[3]); - - return; - } - - // - // C++: Mat::Mat(Mat m, Range rowRange, Range colRange = Range::all()) - // - - // javadoc: Mat::Mat(m, rowRange, colRange) - public Mat(Mat m, Range rowRange, Range colRange) - { - - nativeObj = n_Mat(m.nativeObj, rowRange.start, rowRange.end, colRange.start, colRange.end); - - return; - } - - // javadoc: Mat::Mat(m, rowRange) - public Mat(Mat m, Range rowRange) - { - - nativeObj = n_Mat(m.nativeObj, rowRange.start, rowRange.end); - - return; - } - - // - // C++: Mat::Mat(Mat m, Rect roi) - // - - // javadoc: Mat::Mat(m, roi) - public Mat(Mat m, Rect roi) - { - - nativeObj = n_Mat(m.nativeObj, roi.x, roi.x + roi.width, roi.y, roi.y + roi.height); - - return; - } - - // - // C++: Mat Mat::adjustROI(int dtop, int dbottom, int dleft, int dright) - // - - // javadoc: Mat::adjustROI(dtop, dbottom, dleft, dright) - public Mat adjustROI(int dtop, int dbottom, int dleft, int dright) - { - - Mat retVal = new Mat(n_adjustROI(nativeObj, dtop, dbottom, dleft, dright)); - - return retVal; - } - - // - // C++: void Mat::assignTo(Mat m, int type = -1) - // - - // javadoc: Mat::assignTo(m, type) - public void assignTo(Mat m, int type) - { - - n_assignTo(nativeObj, m.nativeObj, type); - - return; - } - - // javadoc: Mat::assignTo(m) - public void assignTo(Mat m) - { - - n_assignTo(nativeObj, m.nativeObj); - - return; - } - - // - // C++: int Mat::channels() - // - - // javadoc: Mat::channels() - public int channels() - { - - int retVal = n_channels(nativeObj); - - return retVal; - } - - // - // C++: int Mat::checkVector(int elemChannels, int depth = -1, bool - // requireContinuous = true) - // - - // javadoc: Mat::checkVector(elemChannels, depth, requireContinuous) - public int checkVector(int elemChannels, int depth, boolean requireContinuous) - { - - int retVal = n_checkVector(nativeObj, elemChannels, depth, requireContinuous); - - return retVal; - } - - // javadoc: Mat::checkVector(elemChannels, depth) - public int checkVector(int elemChannels, int depth) - { - - int retVal = n_checkVector(nativeObj, elemChannels, depth); - - return retVal; - } - - // javadoc: Mat::checkVector(elemChannels) - public int checkVector(int elemChannels) - { - - int retVal = n_checkVector(nativeObj, elemChannels); - - return retVal; - } - - // - // C++: Mat Mat::clone() - // - - // javadoc: Mat::clone() - public Mat clone() - { - - Mat retVal = new Mat(n_clone(nativeObj)); - - return retVal; - } - - // - // C++: Mat Mat::col(int x) - // - - // javadoc: Mat::col(x) - public Mat col(int x) - { - - Mat retVal = new Mat(n_col(nativeObj, x)); - - return retVal; - } - - // - // C++: Mat Mat::colRange(int startcol, int endcol) - // - - // javadoc: Mat::colRange(startcol, endcol) - public Mat colRange(int startcol, int endcol) - { - - Mat retVal = new Mat(n_colRange(nativeObj, startcol, endcol)); - - return retVal; - } - - // - // C++: Mat Mat::colRange(Range r) - // - - // javadoc: Mat::colRange(r) - public Mat colRange(Range r) - { - - Mat retVal = new Mat(n_colRange(nativeObj, r.start, r.end)); - - return retVal; - } - - // - // C++: int Mat::cols() - // - - // javadoc: Mat::cols() - public int cols() - { - - int retVal = n_cols(nativeObj); - - return retVal; - } - - // - // C++: void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta - // = 0) - // - - // javadoc: Mat::convertTo(m, rtype, alpha, beta) - public void convertTo(Mat m, int rtype, double alpha, double beta) - { - - n_convertTo(nativeObj, m.nativeObj, rtype, alpha, beta); - - return; - } - - // javadoc: Mat::convertTo(m, rtype, alpha) - public void convertTo(Mat m, int rtype, double alpha) - { - - n_convertTo(nativeObj, m.nativeObj, rtype, alpha); - - return; - } - - // javadoc: Mat::convertTo(m, rtype) - public void convertTo(Mat m, int rtype) - { - - n_convertTo(nativeObj, m.nativeObj, rtype); - - return; - } - - // - // C++: void Mat::copyTo(Mat& m) - // - - // javadoc: Mat::copyTo(m) - public void copyTo(Mat m) - { - - n_copyTo(nativeObj, m.nativeObj); - - return; - } - - // - // C++: void Mat::copyTo(Mat& m, Mat mask) - // - - // javadoc: Mat::copyTo(m, mask) - public void copyTo(Mat m, Mat mask) - { - - n_copyTo(nativeObj, m.nativeObj, mask.nativeObj); - - return; - } - - // - // C++: void Mat::create(int rows, int cols, int type) - // - - // javadoc: Mat::create(rows, cols, type) - public void create(int rows, int cols, int type) - { - - n_create(nativeObj, rows, cols, type); - - return; - } - - // - // C++: void Mat::create(Size size, int type) - // - - // javadoc: Mat::create(size, type) - public void create(Size size, int type) - { - - n_create(nativeObj, size.width, size.height, type); - - return; - } - - // - // C++: Mat Mat::cross(Mat m) - // - - // javadoc: Mat::cross(m) - public Mat cross(Mat m) - { - - Mat retVal = new Mat(n_cross(nativeObj, m.nativeObj)); - - return retVal; - } - - // - // C++: long Mat::dataAddr() - // - - // javadoc: Mat::dataAddr() - public long dataAddr() - { - - long retVal = n_dataAddr(nativeObj); - - return retVal; - } - - // - // C++: int Mat::depth() - // - - // javadoc: Mat::depth() - public int depth() - { - - int retVal = n_depth(nativeObj); - - return retVal; - } - - // - // C++: Mat Mat::diag(int d = 0) - // - - // javadoc: Mat::diag(d) - public Mat diag(int d) - { - - Mat retVal = new Mat(n_diag(nativeObj, d)); - - return retVal; - } - - // javadoc: Mat::diag() - public Mat diag() - { - - Mat retVal = new Mat(n_diag(nativeObj, 0)); - - return retVal; - } - - // - // C++: static Mat Mat::diag(Mat d) - // - - // javadoc: Mat::diag(d) - public static Mat diag(Mat d) - { - - Mat retVal = new Mat(n_diag(d.nativeObj)); - - return retVal; - } - - // - // C++: double Mat::dot(Mat m) - // - - // javadoc: Mat::dot(m) - public double dot(Mat m) - { - - double retVal = n_dot(nativeObj, m.nativeObj); - - return retVal; - } - - // - // C++: size_t Mat::elemSize() - // - - // javadoc: Mat::elemSize() - public long elemSize() - { - - long retVal = n_elemSize(nativeObj); - - return retVal; - } - - // - // C++: size_t Mat::elemSize1() - // - - // javadoc: Mat::elemSize1() - public long elemSize1() - { - - long retVal = n_elemSize1(nativeObj); - - return retVal; - } - - // - // C++: bool Mat::empty() - // - - // javadoc: Mat::empty() - public boolean empty() - { - - boolean retVal = n_empty(nativeObj); - - return retVal; - } - - // - // C++: static Mat Mat::eye(int rows, int cols, int type) - // - - // javadoc: Mat::eye(rows, cols, type) - public static Mat eye(int rows, int cols, int type) - { - - Mat retVal = new Mat(n_eye(rows, cols, type)); - - return retVal; - } - - // - // C++: static Mat Mat::eye(Size size, int type) - // - - // javadoc: Mat::eye(size, type) - public static Mat eye(Size size, int type) - { - - Mat retVal = new Mat(n_eye(size.width, size.height, type)); - - return retVal; - } - - // - // C++: Mat Mat::inv(int method = DECOMP_LU) - // - - // javadoc: Mat::inv(method) - public Mat inv(int method) - { - - Mat retVal = new Mat(n_inv(nativeObj, method)); - - return retVal; - } - - // javadoc: Mat::inv() - public Mat inv() - { - - Mat retVal = new Mat(n_inv(nativeObj)); - - return retVal; - } - - // - // C++: bool Mat::isContinuous() - // - - // javadoc: Mat::isContinuous() - public boolean isContinuous() - { - - boolean retVal = n_isContinuous(nativeObj); - - return retVal; - } - - // - // C++: bool Mat::isSubmatrix() - // - - // javadoc: Mat::isSubmatrix() - public boolean isSubmatrix() - { - - boolean retVal = n_isSubmatrix(nativeObj); - - return retVal; - } - - // - // C++: void Mat::locateROI(Size wholeSize, Point ofs) - // - - // javadoc: Mat::locateROI(wholeSize, ofs) - public void locateROI(Size wholeSize, Point ofs) - { - double[] wholeSize_out = new double[2]; - double[] ofs_out = new double[2]; - locateROI_0(nativeObj, wholeSize_out, ofs_out); - if(wholeSize!=null){ wholeSize.width = wholeSize_out[0]; wholeSize.height = wholeSize_out[1]; } - if(ofs!=null){ ofs.x = ofs_out[0]; ofs.y = ofs_out[1]; } - return; - } - - // - // C++: Mat Mat::mul(Mat m, double scale = 1) - // - - // javadoc: Mat::mul(m, scale) - public Mat mul(Mat m, double scale) - { - - Mat retVal = new Mat(n_mul(nativeObj, m.nativeObj, scale)); - - return retVal; - } - - // javadoc: Mat::mul(m) - public Mat mul(Mat m) - { - - Mat retVal = new Mat(n_mul(nativeObj, m.nativeObj)); - - return retVal; - } - - // - // C++: static Mat Mat::ones(int rows, int cols, int type) - // - - // javadoc: Mat::ones(rows, cols, type) - public static Mat ones(int rows, int cols, int type) - { - - Mat retVal = new Mat(n_ones(rows, cols, type)); - - return retVal; - } - - // - // C++: static Mat Mat::ones(Size size, int type) - // - - // javadoc: Mat::ones(size, type) - public static Mat ones(Size size, int type) - { - - Mat retVal = new Mat(n_ones(size.width, size.height, type)); - - return retVal; - } - - // - // C++: void Mat::push_back(Mat m) - // - - // javadoc: Mat::push_back(m) - public void push_back(Mat m) - { - - n_push_back(nativeObj, m.nativeObj); - - return; - } - - // - // C++: void Mat::release() - // - - // javadoc: Mat::release() - public void release() - { - - n_release(nativeObj); - - return; - } - - // - // C++: Mat Mat::reshape(int cn, int rows = 0) - // - - // javadoc: Mat::reshape(cn, rows) - public Mat reshape(int cn, int rows) - { - - Mat retVal = new Mat(n_reshape(nativeObj, cn, rows)); - - return retVal; - } - - // javadoc: Mat::reshape(cn) - public Mat reshape(int cn) - { - - Mat retVal = new Mat(n_reshape(nativeObj, cn)); - - return retVal; - } - - // - // C++: Mat Mat::row(int y) - // - - // javadoc: Mat::row(y) - public Mat row(int y) - { - - Mat retVal = new Mat(n_row(nativeObj, y)); - - return retVal; - } - - // - // C++: Mat Mat::rowRange(int startrow, int endrow) - // - - // javadoc: Mat::rowRange(startrow, endrow) - public Mat rowRange(int startrow, int endrow) - { - - Mat retVal = new Mat(n_rowRange(nativeObj, startrow, endrow)); - - return retVal; - } - - // - // C++: Mat Mat::rowRange(Range r) - // - - // javadoc: Mat::rowRange(r) - public Mat rowRange(Range r) - { - - Mat retVal = new Mat(n_rowRange(nativeObj, r.start, r.end)); - - return retVal; - } - - // - // C++: int Mat::rows() - // - - // javadoc: Mat::rows() - public int rows() - { - - int retVal = n_rows(nativeObj); - - return retVal; - } - - // - // C++: Mat Mat::operator =(Scalar s) - // - - // javadoc: Mat::operator =(s) - public Mat setTo(Scalar s) - { - - Mat retVal = new Mat(n_setTo(nativeObj, s.val[0], s.val[1], s.val[2], s.val[3])); - - return retVal; - } - - // - // C++: Mat Mat::setTo(Mat value, Mat mask = Mat()) - // - - // javadoc: Mat::setTo(value, mask) - public Mat setTo(Mat value, Mat mask) - { - - Mat retVal = new Mat(n_setTo(nativeObj, value.nativeObj, mask.nativeObj)); - - return retVal; - } - - // javadoc: Mat::setTo(value) - public Mat setTo(Mat value) - { - - Mat retVal = new Mat(n_setTo(nativeObj, value.nativeObj)); - - return retVal; - } - - // - // C++: Size Mat::size() - // - - // javadoc: Mat::size() - public Size size() - { - - Size retVal = new Size(n_size(nativeObj)); - - return retVal; - } - - // - // C++: size_t Mat::step1(int i = 0) - // - - // javadoc: Mat::step1(i) - public long step1(int i) - { - - long retVal = n_step1(nativeObj, i); - - return retVal; - } - - // javadoc: Mat::step1() - public long step1() - { - - long retVal = n_step1(nativeObj); - - return retVal; - } - - // - // C++: Mat Mat::operator()(int rowStart, int rowEnd, int colStart, int - // colEnd) - // - - // javadoc: Mat::operator()(rowStart, rowEnd, colStart, colEnd) - public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) - { - - Mat retVal = new Mat(n_submat_rr(nativeObj, rowStart, rowEnd, colStart, colEnd)); - - return retVal; - } - - // - // C++: Mat Mat::operator()(Range rowRange, Range colRange) - // - - // javadoc: Mat::operator()(rowRange, colRange) - public Mat submat(Range rowRange, Range colRange) - { - - Mat retVal = new Mat(n_submat_rr(nativeObj, rowRange.start, rowRange.end, colRange.start, colRange.end)); - - return retVal; - } - - // - // C++: Mat Mat::operator()(Rect roi) - // - - // javadoc: Mat::operator()(roi) - public Mat submat(Rect roi) - { - - Mat retVal = new Mat(n_submat(nativeObj, roi.x, roi.y, roi.width, roi.height)); - - return retVal; - } - - // - // C++: Mat Mat::t() - // - - // javadoc: Mat::t() - public Mat t() - { - - Mat retVal = new Mat(n_t(nativeObj)); - - return retVal; - } - - // - // C++: size_t Mat::total() - // - - // javadoc: Mat::total() - public long total() - { - - long retVal = n_total(nativeObj); - - return retVal; - } - - // - // C++: int Mat::type() - // - - // javadoc: Mat::type() - public int type() - { - - int retVal = n_type(nativeObj); - - return retVal; - } - - // - // C++: static Mat Mat::zeros(int rows, int cols, int type) - // - - // javadoc: Mat::zeros(rows, cols, type) - public static Mat zeros(int rows, int cols, int type) - { - - Mat retVal = new Mat(n_zeros(rows, cols, type)); - - return retVal; - } - - // - // C++: static Mat Mat::zeros(Size size, int type) - // - - // javadoc: Mat::zeros(size, type) - public static Mat zeros(Size size, int type) - { - - Mat retVal = new Mat(n_zeros(size.width, size.height, type)); - - return retVal; - } - - @Override - protected void finalize() throws Throwable { - n_delete(nativeObj); - super.finalize(); - } - - // javadoc:Mat::toString() - @Override - public String toString() { - return "Mat [ " + - rows() + "*" + cols() + "*" + CvType.typeToString(type()) + - ", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() + - ", nativeObj=0x" + Long.toHexString(nativeObj) + - ", dataAddr=0x" + Long.toHexString(dataAddr()) + - " ]"; - } - - // javadoc:Mat::dump() - public String dump() { - return nDump(nativeObj); - } - - // javadoc:Mat::put(row,col,data) - public int put(int row, int col, double... data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - return nPutD(nativeObj, row, col, data.length, data); - } - - // javadoc:Mat::put(row,col,data) - public int put(int row, int col, float[] data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - if (CvType.depth(t) == CvType.CV_32F) { - return nPutF(nativeObj, row, col, data.length, data); - } - throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); - } - - // javadoc:Mat::put(row,col,data) - public int put(int row, int col, int[] data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - if (CvType.depth(t) == CvType.CV_32S) { - return nPutI(nativeObj, row, col, data.length, data); - } - throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); - } - - // javadoc:Mat::put(row,col,data) - public int put(int row, int col, short[] data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - if (CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { - return nPutS(nativeObj, row, col, data.length, data); - } - throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); - } - - // javadoc:Mat::put(row,col,data) - public int put(int row, int col, byte[] data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { - return nPutB(nativeObj, row, col, data.length, data); - } - throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); - } - - // javadoc:Mat::get(row,col,data) - public int get(int row, int col, byte[] data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { - return nGetB(nativeObj, row, col, data.length, data); - } - throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); - } - - // javadoc:Mat::get(row,col,data) - public int get(int row, int col, short[] data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - if (CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { - return nGetS(nativeObj, row, col, data.length, data); - } - throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); - } - - // javadoc:Mat::get(row,col,data) - public int get(int row, int col, int[] data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - if (CvType.depth(t) == CvType.CV_32S) { - return nGetI(nativeObj, row, col, data.length, data); - } - throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); - } - - // javadoc:Mat::get(row,col,data) - public int get(int row, int col, float[] data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - if (CvType.depth(t) == CvType.CV_32F) { - return nGetF(nativeObj, row, col, data.length, data); - } - throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); - } - - // javadoc:Mat::get(row,col,data) - public int get(int row, int col, double[] data) { - int t = type(); - if (data == null || data.length % CvType.channels(t) != 0) - throw new java.lang.UnsupportedOperationException( - "Provided data element number (" + - (data == null ? 0 : data.length) + - ") should be multiple of the Mat channels count (" + - CvType.channels(t) + ")"); - if (CvType.depth(t) == CvType.CV_64F) { - return nGetD(nativeObj, row, col, data.length, data); - } - throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); - } - - // javadoc:Mat::get(row,col) - public double[] get(int row, int col) { - return nGet(nativeObj, row, col); - } - - // javadoc:Mat::height() - public int height() { - return rows(); - } - - // javadoc:Mat::width() - public int width() { - return cols(); - } - - // javadoc:Mat::getNativeObjAddr() - public long getNativeObjAddr() { - return nativeObj; - } - - // C++: Mat::Mat() - private static native long n_Mat(); - - // C++: Mat::Mat(int rows, int cols, int type) - private static native long n_Mat(int rows, int cols, int type); - - // C++: Mat::Mat(Size size, int type) - private static native long n_Mat(double size_width, double size_height, int type); - - // C++: Mat::Mat(int rows, int cols, int type, Scalar s) - private static native long n_Mat(int rows, int cols, int type, double s_val0, double s_val1, double s_val2, double s_val3); - - // C++: Mat::Mat(Size size, int type, Scalar s) - 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); - - // C++: Mat::Mat(Mat m, Range rowRange, Range colRange = Range::all()) - private static native long n_Mat(long m_nativeObj, int rowRange_start, int rowRange_end, int colRange_start, int colRange_end); - - private static native long n_Mat(long m_nativeObj, int rowRange_start, int rowRange_end); - - // C++: Mat Mat::adjustROI(int dtop, int dbottom, int dleft, int dright) - private static native long n_adjustROI(long nativeObj, int dtop, int dbottom, int dleft, int dright); - - // C++: void Mat::assignTo(Mat m, int type = -1) - private static native void n_assignTo(long nativeObj, long m_nativeObj, int type); - - private static native void n_assignTo(long nativeObj, long m_nativeObj); - - // C++: int Mat::channels() - private static native int n_channels(long nativeObj); - - // C++: int Mat::checkVector(int elemChannels, int depth = -1, bool - // requireContinuous = true) - private static native int n_checkVector(long nativeObj, int elemChannels, int depth, boolean requireContinuous); - - private static native int n_checkVector(long nativeObj, int elemChannels, int depth); - - private static native int n_checkVector(long nativeObj, int elemChannels); - - // C++: Mat Mat::clone() - private static native long n_clone(long nativeObj); - - // C++: Mat Mat::col(int x) - private static native long n_col(long nativeObj, int x); - - // C++: Mat Mat::colRange(int startcol, int endcol) - private static native long n_colRange(long nativeObj, int startcol, int endcol); - - // C++: int Mat::cols() - private static native int n_cols(long nativeObj); - - // C++: void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta - // = 0) - private static native void n_convertTo(long nativeObj, long m_nativeObj, int rtype, double alpha, double beta); - - private static native void n_convertTo(long nativeObj, long m_nativeObj, int rtype, double alpha); - - private static native void n_convertTo(long nativeObj, long m_nativeObj, int rtype); - - // C++: void Mat::copyTo(Mat& m) - private static native void n_copyTo(long nativeObj, long m_nativeObj); - - // C++: void Mat::copyTo(Mat& m, Mat mask) - private static native void n_copyTo(long nativeObj, long m_nativeObj, long mask_nativeObj); - - // C++: void Mat::create(int rows, int cols, int type) - private static native void n_create(long nativeObj, int rows, int cols, int type); - - // C++: void Mat::create(Size size, int type) - private static native void n_create(long nativeObj, double size_width, double size_height, int type); - - // C++: Mat Mat::cross(Mat m) - private static native long n_cross(long nativeObj, long m_nativeObj); - - // C++: long Mat::dataAddr() - private static native long n_dataAddr(long nativeObj); - - // C++: int Mat::depth() - private static native int n_depth(long nativeObj); - - // C++: Mat Mat::diag(int d = 0) - private static native long n_diag(long nativeObj, int d); - - // C++: static Mat Mat::diag(Mat d) - private static native long n_diag(long d_nativeObj); - - // C++: double Mat::dot(Mat m) - private static native double n_dot(long nativeObj, long m_nativeObj); - - // C++: size_t Mat::elemSize() - private static native long n_elemSize(long nativeObj); - - // C++: size_t Mat::elemSize1() - private static native long n_elemSize1(long nativeObj); - - // C++: bool Mat::empty() - private static native boolean n_empty(long nativeObj); - - // C++: static Mat Mat::eye(int rows, int cols, int type) - private static native long n_eye(int rows, int cols, int type); - - // C++: static Mat Mat::eye(Size size, int type) - private static native long n_eye(double size_width, double size_height, int type); - - // C++: Mat Mat::inv(int method = DECOMP_LU) - private static native long n_inv(long nativeObj, int method); - - private static native long n_inv(long nativeObj); - - // C++: bool Mat::isContinuous() - private static native boolean n_isContinuous(long nativeObj); - - // C++: bool Mat::isSubmatrix() - private static native boolean n_isSubmatrix(long nativeObj); - - // C++: void Mat::locateROI(Size wholeSize, Point ofs) - private static native void locateROI_0(long nativeObj, double[] wholeSize_out, double[] ofs_out); - - // C++: Mat Mat::mul(Mat m, double scale = 1) - private static native long n_mul(long nativeObj, long m_nativeObj, double scale); - - private static native long n_mul(long nativeObj, long m_nativeObj); - - // C++: static Mat Mat::ones(int rows, int cols, int type) - private static native long n_ones(int rows, int cols, int type); - - // C++: static Mat Mat::ones(Size size, int type) - private static native long n_ones(double size_width, double size_height, int type); - - // C++: void Mat::push_back(Mat m) - private static native void n_push_back(long nativeObj, long m_nativeObj); - - // C++: void Mat::release() - private static native void n_release(long nativeObj); - - // C++: Mat Mat::reshape(int cn, int rows = 0) - private static native long n_reshape(long nativeObj, int cn, int rows); - - private static native long n_reshape(long nativeObj, int cn); - - // C++: Mat Mat::row(int y) - private static native long n_row(long nativeObj, int y); - - // C++: Mat Mat::rowRange(int startrow, int endrow) - private static native long n_rowRange(long nativeObj, int startrow, int endrow); - - // C++: int Mat::rows() - private static native int n_rows(long nativeObj); - - // C++: Mat Mat::operator =(Scalar s) - private static native long n_setTo(long nativeObj, double s_val0, double s_val1, double s_val2, double s_val3); - - // C++: Mat Mat::setTo(Mat value, Mat mask = Mat()) - private static native long n_setTo(long nativeObj, long value_nativeObj, long mask_nativeObj); - - private static native long n_setTo(long nativeObj, long value_nativeObj); - - // C++: Size Mat::size() - private static native double[] n_size(long nativeObj); - - // C++: size_t Mat::step1(int i = 0) - private static native long n_step1(long nativeObj, int i); - - private static native long n_step1(long nativeObj); - - // C++: Mat Mat::operator()(Range rowRange, Range colRange) - private static native long n_submat_rr(long nativeObj, int rowRange_start, int rowRange_end, int colRange_start, int colRange_end); - - // C++: Mat Mat::operator()(Rect roi) - private static native long n_submat(long nativeObj, int roi_x, int roi_y, int roi_width, int roi_height); - - // C++: Mat Mat::t() - private static native long n_t(long nativeObj); - - // C++: size_t Mat::total() - private static native long n_total(long nativeObj); - - // C++: int Mat::type() - private static native int n_type(long nativeObj); - - // C++: static Mat Mat::zeros(int rows, int cols, int type) - private static native long n_zeros(int rows, int cols, int type); - - // C++: static Mat Mat::zeros(Size size, int type) - private static native long n_zeros(double size_width, double size_height, int type); - - // native support for java finalize() - private static native void n_delete(long nativeObj); - - private static native int nPutD(long self, int row, int col, int count, double[] data); - - private static native int nPutF(long self, int row, int col, int count, float[] data); - - private static native int nPutI(long self, int row, int col, int count, int[] data); - - private static native int nPutS(long self, int row, int col, int count, short[] data); - - private static native int nPutB(long self, int row, int col, int count, byte[] data); - - private static native int nGetB(long self, int row, int col, int count, byte[] vals); - - private static native int nGetS(long self, int row, int col, int count, short[] vals); - - private static native int nGetI(long self, int row, int col, int count, int[] vals); - - private static native int nGetF(long self, int row, int col, int count, float[] vals); - - private static native int nGetD(long self, int row, int col, int count, double[] vals); - - private static native double[] nGet(long self, int row, int col); - - private static native String nDump(long self); -} +package org.opencv.core; + +// C++: class Mat +//javadoc: Mat +public class Mat { + + public final long nativeObj; + + public Mat(long addr) + { + if (addr == 0) + throw new java.lang.UnsupportedOperationException("Native object address is NULL"); + nativeObj = addr; + } + + // + // C++: Mat::Mat() + // + + // javadoc: Mat::Mat() + public Mat() + { + + nativeObj = n_Mat(); + + return; + } + + // + // C++: Mat::Mat(int rows, int cols, int type) + // + + // javadoc: Mat::Mat(rows, cols, type) + public Mat(int rows, int cols, int type) + { + + nativeObj = n_Mat(rows, cols, type); + + return; + } + + // + // C++: Mat::Mat(Size size, int type) + // + + // javadoc: Mat::Mat(size, type) + public Mat(Size size, int type) + { + + nativeObj = n_Mat(size.width, size.height, type); + + return; + } + + // + // C++: Mat::Mat(int rows, int cols, int type, Scalar s) + // + + // javadoc: Mat::Mat(rows, cols, type, s) + public Mat(int rows, int cols, int type, Scalar s) + { + + nativeObj = n_Mat(rows, cols, type, s.val[0], s.val[1], s.val[2], s.val[3]); + + return; + } + + // + // C++: Mat::Mat(Size size, int type, Scalar s) + // + + // javadoc: Mat::Mat(size, type, s) + public Mat(Size size, int type, Scalar s) + { + + nativeObj = n_Mat(size.width, size.height, type, s.val[0], s.val[1], s.val[2], s.val[3]); + + return; + } + + // + // C++: Mat::Mat(Mat m, Range rowRange, Range colRange = Range::all()) + // + + // javadoc: Mat::Mat(m, rowRange, colRange) + public Mat(Mat m, Range rowRange, Range colRange) + { + + nativeObj = n_Mat(m.nativeObj, rowRange.start, rowRange.end, colRange.start, colRange.end); + + return; + } + + // javadoc: Mat::Mat(m, rowRange) + public Mat(Mat m, Range rowRange) + { + + nativeObj = n_Mat(m.nativeObj, rowRange.start, rowRange.end); + + return; + } + + // + // C++: Mat::Mat(Mat m, Rect roi) + // + + // javadoc: Mat::Mat(m, roi) + public Mat(Mat m, Rect roi) + { + + nativeObj = n_Mat(m.nativeObj, roi.x, roi.x + roi.width, roi.y, roi.y + roi.height); + + return; + } + + // + // C++: Mat Mat::adjustROI(int dtop, int dbottom, int dleft, int dright) + // + + // javadoc: Mat::adjustROI(dtop, dbottom, dleft, dright) + public Mat adjustROI(int dtop, int dbottom, int dleft, int dright) + { + + Mat retVal = new Mat(n_adjustROI(nativeObj, dtop, dbottom, dleft, dright)); + + return retVal; + } + + // + // C++: void Mat::assignTo(Mat m, int type = -1) + // + + // javadoc: Mat::assignTo(m, type) + public void assignTo(Mat m, int type) + { + + n_assignTo(nativeObj, m.nativeObj, type); + + return; + } + + // javadoc: Mat::assignTo(m) + public void assignTo(Mat m) + { + + n_assignTo(nativeObj, m.nativeObj); + + return; + } + + // + // C++: int Mat::channels() + // + + // javadoc: Mat::channels() + public int channels() + { + + int retVal = n_channels(nativeObj); + + return retVal; + } + + // + // C++: int Mat::checkVector(int elemChannels, int depth = -1, bool + // requireContinuous = true) + // + + // javadoc: Mat::checkVector(elemChannels, depth, requireContinuous) + public int checkVector(int elemChannels, int depth, boolean requireContinuous) + { + + int retVal = n_checkVector(nativeObj, elemChannels, depth, requireContinuous); + + return retVal; + } + + // javadoc: Mat::checkVector(elemChannels, depth) + public int checkVector(int elemChannels, int depth) + { + + int retVal = n_checkVector(nativeObj, elemChannels, depth); + + return retVal; + } + + // javadoc: Mat::checkVector(elemChannels) + public int checkVector(int elemChannels) + { + + int retVal = n_checkVector(nativeObj, elemChannels); + + return retVal; + } + + // + // C++: Mat Mat::clone() + // + + // javadoc: Mat::clone() + public Mat clone() + { + + Mat retVal = new Mat(n_clone(nativeObj)); + + return retVal; + } + + // + // C++: Mat Mat::col(int x) + // + + // javadoc: Mat::col(x) + public Mat col(int x) + { + + Mat retVal = new Mat(n_col(nativeObj, x)); + + return retVal; + } + + // + // C++: Mat Mat::colRange(int startcol, int endcol) + // + + // javadoc: Mat::colRange(startcol, endcol) + public Mat colRange(int startcol, int endcol) + { + + Mat retVal = new Mat(n_colRange(nativeObj, startcol, endcol)); + + return retVal; + } + + // + // C++: Mat Mat::colRange(Range r) + // + + // javadoc: Mat::colRange(r) + public Mat colRange(Range r) + { + + Mat retVal = new Mat(n_colRange(nativeObj, r.start, r.end)); + + return retVal; + } + + // + // C++: int Mat::cols() + // + + // javadoc: Mat::cols() + public int cols() + { + + int retVal = n_cols(nativeObj); + + return retVal; + } + + // + // C++: void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta + // = 0) + // + + // javadoc: Mat::convertTo(m, rtype, alpha, beta) + public void convertTo(Mat m, int rtype, double alpha, double beta) + { + + n_convertTo(nativeObj, m.nativeObj, rtype, alpha, beta); + + return; + } + + // javadoc: Mat::convertTo(m, rtype, alpha) + public void convertTo(Mat m, int rtype, double alpha) + { + + n_convertTo(nativeObj, m.nativeObj, rtype, alpha); + + return; + } + + // javadoc: Mat::convertTo(m, rtype) + public void convertTo(Mat m, int rtype) + { + + n_convertTo(nativeObj, m.nativeObj, rtype); + + return; + } + + // + // C++: void Mat::copyTo(Mat& m) + // + + // javadoc: Mat::copyTo(m) + public void copyTo(Mat m) + { + + n_copyTo(nativeObj, m.nativeObj); + + return; + } + + // + // C++: void Mat::copyTo(Mat& m, Mat mask) + // + + // javadoc: Mat::copyTo(m, mask) + public void copyTo(Mat m, Mat mask) + { + + n_copyTo(nativeObj, m.nativeObj, mask.nativeObj); + + return; + } + + // + // C++: void Mat::create(int rows, int cols, int type) + // + + // javadoc: Mat::create(rows, cols, type) + public void create(int rows, int cols, int type) + { + + n_create(nativeObj, rows, cols, type); + + return; + } + + // + // C++: void Mat::create(Size size, int type) + // + + // javadoc: Mat::create(size, type) + public void create(Size size, int type) + { + + n_create(nativeObj, size.width, size.height, type); + + return; + } + + // + // C++: Mat Mat::cross(Mat m) + // + + // javadoc: Mat::cross(m) + public Mat cross(Mat m) + { + + Mat retVal = new Mat(n_cross(nativeObj, m.nativeObj)); + + return retVal; + } + + // + // C++: long Mat::dataAddr() + // + + // javadoc: Mat::dataAddr() + public long dataAddr() + { + + long retVal = n_dataAddr(nativeObj); + + return retVal; + } + + // + // C++: int Mat::depth() + // + + // javadoc: Mat::depth() + public int depth() + { + + int retVal = n_depth(nativeObj); + + return retVal; + } + + // + // C++: Mat Mat::diag(int d = 0) + // + + // javadoc: Mat::diag(d) + public Mat diag(int d) + { + + Mat retVal = new Mat(n_diag(nativeObj, d)); + + return retVal; + } + + // javadoc: Mat::diag() + public Mat diag() + { + + Mat retVal = new Mat(n_diag(nativeObj, 0)); + + return retVal; + } + + // + // C++: static Mat Mat::diag(Mat d) + // + + // javadoc: Mat::diag(d) + public static Mat diag(Mat d) + { + + Mat retVal = new Mat(n_diag(d.nativeObj)); + + return retVal; + } + + // + // C++: double Mat::dot(Mat m) + // + + // javadoc: Mat::dot(m) + public double dot(Mat m) + { + + double retVal = n_dot(nativeObj, m.nativeObj); + + return retVal; + } + + // + // C++: size_t Mat::elemSize() + // + + // javadoc: Mat::elemSize() + public long elemSize() + { + + long retVal = n_elemSize(nativeObj); + + return retVal; + } + + // + // C++: size_t Mat::elemSize1() + // + + // javadoc: Mat::elemSize1() + public long elemSize1() + { + + long retVal = n_elemSize1(nativeObj); + + return retVal; + } + + // + // C++: bool Mat::empty() + // + + // javadoc: Mat::empty() + public boolean empty() + { + + boolean retVal = n_empty(nativeObj); + + return retVal; + } + + // + // C++: static Mat Mat::eye(int rows, int cols, int type) + // + + // javadoc: Mat::eye(rows, cols, type) + public static Mat eye(int rows, int cols, int type) + { + + Mat retVal = new Mat(n_eye(rows, cols, type)); + + return retVal; + } + + // + // C++: static Mat Mat::eye(Size size, int type) + // + + // javadoc: Mat::eye(size, type) + public static Mat eye(Size size, int type) + { + + Mat retVal = new Mat(n_eye(size.width, size.height, type)); + + return retVal; + } + + // + // C++: Mat Mat::inv(int method = DECOMP_LU) + // + + // javadoc: Mat::inv(method) + public Mat inv(int method) + { + + Mat retVal = new Mat(n_inv(nativeObj, method)); + + return retVal; + } + + // javadoc: Mat::inv() + public Mat inv() + { + + Mat retVal = new Mat(n_inv(nativeObj)); + + return retVal; + } + + // + // C++: bool Mat::isContinuous() + // + + // javadoc: Mat::isContinuous() + public boolean isContinuous() + { + + boolean retVal = n_isContinuous(nativeObj); + + return retVal; + } + + // + // C++: bool Mat::isSubmatrix() + // + + // javadoc: Mat::isSubmatrix() + public boolean isSubmatrix() + { + + boolean retVal = n_isSubmatrix(nativeObj); + + return retVal; + } + + // + // C++: void Mat::locateROI(Size wholeSize, Point ofs) + // + + // javadoc: Mat::locateROI(wholeSize, ofs) + public void locateROI(Size wholeSize, Point ofs) + { + double[] wholeSize_out = new double[2]; + double[] ofs_out = new double[2]; + locateROI_0(nativeObj, wholeSize_out, ofs_out); + if(wholeSize!=null){ wholeSize.width = wholeSize_out[0]; wholeSize.height = wholeSize_out[1]; } + if(ofs!=null){ ofs.x = ofs_out[0]; ofs.y = ofs_out[1]; } + return; + } + + // + // C++: Mat Mat::mul(Mat m, double scale = 1) + // + + // javadoc: Mat::mul(m, scale) + public Mat mul(Mat m, double scale) + { + + Mat retVal = new Mat(n_mul(nativeObj, m.nativeObj, scale)); + + return retVal; + } + + // javadoc: Mat::mul(m) + public Mat mul(Mat m) + { + + Mat retVal = new Mat(n_mul(nativeObj, m.nativeObj)); + + return retVal; + } + + // + // C++: static Mat Mat::ones(int rows, int cols, int type) + // + + // javadoc: Mat::ones(rows, cols, type) + public static Mat ones(int rows, int cols, int type) + { + + Mat retVal = new Mat(n_ones(rows, cols, type)); + + return retVal; + } + + // + // C++: static Mat Mat::ones(Size size, int type) + // + + // javadoc: Mat::ones(size, type) + public static Mat ones(Size size, int type) + { + + Mat retVal = new Mat(n_ones(size.width, size.height, type)); + + return retVal; + } + + // + // C++: void Mat::push_back(Mat m) + // + + // javadoc: Mat::push_back(m) + public void push_back(Mat m) + { + + n_push_back(nativeObj, m.nativeObj); + + return; + } + + // + // C++: void Mat::release() + // + + // javadoc: Mat::release() + public void release() + { + + n_release(nativeObj); + + return; + } + + // + // C++: Mat Mat::reshape(int cn, int rows = 0) + // + + // javadoc: Mat::reshape(cn, rows) + public Mat reshape(int cn, int rows) + { + + Mat retVal = new Mat(n_reshape(nativeObj, cn, rows)); + + return retVal; + } + + // javadoc: Mat::reshape(cn) + public Mat reshape(int cn) + { + + Mat retVal = new Mat(n_reshape(nativeObj, cn)); + + return retVal; + } + + // + // C++: Mat Mat::row(int y) + // + + // javadoc: Mat::row(y) + public Mat row(int y) + { + + Mat retVal = new Mat(n_row(nativeObj, y)); + + return retVal; + } + + // + // C++: Mat Mat::rowRange(int startrow, int endrow) + // + + // javadoc: Mat::rowRange(startrow, endrow) + public Mat rowRange(int startrow, int endrow) + { + + Mat retVal = new Mat(n_rowRange(nativeObj, startrow, endrow)); + + return retVal; + } + + // + // C++: Mat Mat::rowRange(Range r) + // + + // javadoc: Mat::rowRange(r) + public Mat rowRange(Range r) + { + + Mat retVal = new Mat(n_rowRange(nativeObj, r.start, r.end)); + + return retVal; + } + + // + // C++: int Mat::rows() + // + + // javadoc: Mat::rows() + public int rows() + { + + int retVal = n_rows(nativeObj); + + return retVal; + } + + // + // C++: Mat Mat::operator =(Scalar s) + // + + // javadoc: Mat::operator =(s) + public Mat setTo(Scalar s) + { + + Mat retVal = new Mat(n_setTo(nativeObj, s.val[0], s.val[1], s.val[2], s.val[3])); + + return retVal; + } + + // + // C++: Mat Mat::setTo(Mat value, Mat mask = Mat()) + // + + // javadoc: Mat::setTo(value, mask) + public Mat setTo(Mat value, Mat mask) + { + + Mat retVal = new Mat(n_setTo(nativeObj, value.nativeObj, mask.nativeObj)); + + return retVal; + } + + // javadoc: Mat::setTo(value) + public Mat setTo(Mat value) + { + + Mat retVal = new Mat(n_setTo(nativeObj, value.nativeObj)); + + return retVal; + } + + // + // C++: Size Mat::size() + // + + // javadoc: Mat::size() + public Size size() + { + + Size retVal = new Size(n_size(nativeObj)); + + return retVal; + } + + // + // C++: size_t Mat::step1(int i = 0) + // + + // javadoc: Mat::step1(i) + public long step1(int i) + { + + long retVal = n_step1(nativeObj, i); + + return retVal; + } + + // javadoc: Mat::step1() + public long step1() + { + + long retVal = n_step1(nativeObj); + + return retVal; + } + + // + // C++: Mat Mat::operator()(int rowStart, int rowEnd, int colStart, int + // colEnd) + // + + // javadoc: Mat::operator()(rowStart, rowEnd, colStart, colEnd) + public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) + { + + Mat retVal = new Mat(n_submat_rr(nativeObj, rowStart, rowEnd, colStart, colEnd)); + + return retVal; + } + + // + // C++: Mat Mat::operator()(Range rowRange, Range colRange) + // + + // javadoc: Mat::operator()(rowRange, colRange) + public Mat submat(Range rowRange, Range colRange) + { + + Mat retVal = new Mat(n_submat_rr(nativeObj, rowRange.start, rowRange.end, colRange.start, colRange.end)); + + return retVal; + } + + // + // C++: Mat Mat::operator()(Rect roi) + // + + // javadoc: Mat::operator()(roi) + public Mat submat(Rect roi) + { + + Mat retVal = new Mat(n_submat(nativeObj, roi.x, roi.y, roi.width, roi.height)); + + return retVal; + } + + // + // C++: Mat Mat::t() + // + + // javadoc: Mat::t() + public Mat t() + { + + Mat retVal = new Mat(n_t(nativeObj)); + + return retVal; + } + + // + // C++: size_t Mat::total() + // + + // javadoc: Mat::total() + public long total() + { + + long retVal = n_total(nativeObj); + + return retVal; + } + + // + // C++: int Mat::type() + // + + // javadoc: Mat::type() + public int type() + { + + int retVal = n_type(nativeObj); + + return retVal; + } + + // + // C++: static Mat Mat::zeros(int rows, int cols, int type) + // + + // javadoc: Mat::zeros(rows, cols, type) + public static Mat zeros(int rows, int cols, int type) + { + + Mat retVal = new Mat(n_zeros(rows, cols, type)); + + return retVal; + } + + // + // C++: static Mat Mat::zeros(Size size, int type) + // + + // javadoc: Mat::zeros(size, type) + public static Mat zeros(Size size, int type) + { + + Mat retVal = new Mat(n_zeros(size.width, size.height, type)); + + return retVal; + } + + @Override + protected void finalize() throws Throwable { + n_delete(nativeObj); + super.finalize(); + } + + // javadoc:Mat::toString() + @Override + public String toString() { + return "Mat [ " + + rows() + "*" + cols() + "*" + CvType.typeToString(type()) + + ", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() + + ", nativeObj=0x" + Long.toHexString(nativeObj) + + ", dataAddr=0x" + Long.toHexString(dataAddr()) + + " ]"; + } + + // javadoc:Mat::dump() + public String dump() { + return nDump(nativeObj); + } + + // javadoc:Mat::put(row,col,data) + public int put(int row, int col, double... data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + return nPutD(nativeObj, row, col, data.length, data); + } + + // javadoc:Mat::put(row,col,data) + public int put(int row, int col, float[] data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + if (CvType.depth(t) == CvType.CV_32F) { + return nPutF(nativeObj, row, col, data.length, data); + } + throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); + } + + // javadoc:Mat::put(row,col,data) + public int put(int row, int col, int[] data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + if (CvType.depth(t) == CvType.CV_32S) { + return nPutI(nativeObj, row, col, data.length, data); + } + throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); + } + + // javadoc:Mat::put(row,col,data) + public int put(int row, int col, short[] data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + if (CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { + return nPutS(nativeObj, row, col, data.length, data); + } + throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); + } + + // javadoc:Mat::put(row,col,data) + public int put(int row, int col, byte[] data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { + return nPutB(nativeObj, row, col, data.length, data); + } + throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); + } + + // javadoc:Mat::get(row,col,data) + public int get(int row, int col, byte[] data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + if (CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { + return nGetB(nativeObj, row, col, data.length, data); + } + throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); + } + + // javadoc:Mat::get(row,col,data) + public int get(int row, int col, short[] data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + if (CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { + return nGetS(nativeObj, row, col, data.length, data); + } + throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); + } + + // javadoc:Mat::get(row,col,data) + public int get(int row, int col, int[] data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + if (CvType.depth(t) == CvType.CV_32S) { + return nGetI(nativeObj, row, col, data.length, data); + } + throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); + } + + // javadoc:Mat::get(row,col,data) + public int get(int row, int col, float[] data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + if (CvType.depth(t) == CvType.CV_32F) { + return nGetF(nativeObj, row, col, data.length, data); + } + throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); + } + + // javadoc:Mat::get(row,col,data) + public int get(int row, int col, double[] data) { + int t = type(); + if (data == null || data.length % CvType.channels(t) != 0) + throw new java.lang.UnsupportedOperationException( + "Provided data element number (" + + (data == null ? 0 : data.length) + + ") should be multiple of the Mat channels count (" + + CvType.channels(t) + ")"); + if (CvType.depth(t) == CvType.CV_64F) { + return nGetD(nativeObj, row, col, data.length, data); + } + throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); + } + + // javadoc:Mat::get(row,col) + public double[] get(int row, int col) { + return nGet(nativeObj, row, col); + } + + // javadoc:Mat::height() + public int height() { + return rows(); + } + + // javadoc:Mat::width() + public int width() { + return cols(); + } + + // javadoc:Mat::getNativeObjAddr() + public long getNativeObjAddr() { + return nativeObj; + } + + // + // native stuff + // + static { + System.loadLibrary("opencv_java"); + } + + // C++: Mat::Mat() + private static native long n_Mat(); + + // C++: Mat::Mat(int rows, int cols, int type) + private static native long n_Mat(int rows, int cols, int type); + + // C++: Mat::Mat(Size size, int type) + private static native long n_Mat(double size_width, double size_height, int type); + + // C++: Mat::Mat(int rows, int cols, int type, Scalar s) + private static native long n_Mat(int rows, int cols, int type, double s_val0, double s_val1, double s_val2, double s_val3); + + // C++: Mat::Mat(Size size, int type, Scalar s) + 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); + + // C++: Mat::Mat(Mat m, Range rowRange, Range colRange = Range::all()) + private static native long n_Mat(long m_nativeObj, int rowRange_start, int rowRange_end, int colRange_start, int colRange_end); + + private static native long n_Mat(long m_nativeObj, int rowRange_start, int rowRange_end); + + // C++: Mat Mat::adjustROI(int dtop, int dbottom, int dleft, int dright) + private static native long n_adjustROI(long nativeObj, int dtop, int dbottom, int dleft, int dright); + + // C++: void Mat::assignTo(Mat m, int type = -1) + private static native void n_assignTo(long nativeObj, long m_nativeObj, int type); + + private static native void n_assignTo(long nativeObj, long m_nativeObj); + + // C++: int Mat::channels() + private static native int n_channels(long nativeObj); + + // C++: int Mat::checkVector(int elemChannels, int depth = -1, bool + // requireContinuous = true) + private static native int n_checkVector(long nativeObj, int elemChannels, int depth, boolean requireContinuous); + + private static native int n_checkVector(long nativeObj, int elemChannels, int depth); + + private static native int n_checkVector(long nativeObj, int elemChannels); + + // C++: Mat Mat::clone() + private static native long n_clone(long nativeObj); + + // C++: Mat Mat::col(int x) + private static native long n_col(long nativeObj, int x); + + // C++: Mat Mat::colRange(int startcol, int endcol) + private static native long n_colRange(long nativeObj, int startcol, int endcol); + + // C++: int Mat::cols() + private static native int n_cols(long nativeObj); + + // C++: void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta + // = 0) + private static native void n_convertTo(long nativeObj, long m_nativeObj, int rtype, double alpha, double beta); + + private static native void n_convertTo(long nativeObj, long m_nativeObj, int rtype, double alpha); + + private static native void n_convertTo(long nativeObj, long m_nativeObj, int rtype); + + // C++: void Mat::copyTo(Mat& m) + private static native void n_copyTo(long nativeObj, long m_nativeObj); + + // C++: void Mat::copyTo(Mat& m, Mat mask) + private static native void n_copyTo(long nativeObj, long m_nativeObj, long mask_nativeObj); + + // C++: void Mat::create(int rows, int cols, int type) + private static native void n_create(long nativeObj, int rows, int cols, int type); + + // C++: void Mat::create(Size size, int type) + private static native void n_create(long nativeObj, double size_width, double size_height, int type); + + // C++: Mat Mat::cross(Mat m) + private static native long n_cross(long nativeObj, long m_nativeObj); + + // C++: long Mat::dataAddr() + private static native long n_dataAddr(long nativeObj); + + // C++: int Mat::depth() + private static native int n_depth(long nativeObj); + + // C++: Mat Mat::diag(int d = 0) + private static native long n_diag(long nativeObj, int d); + + // C++: static Mat Mat::diag(Mat d) + private static native long n_diag(long d_nativeObj); + + // C++: double Mat::dot(Mat m) + private static native double n_dot(long nativeObj, long m_nativeObj); + + // C++: size_t Mat::elemSize() + private static native long n_elemSize(long nativeObj); + + // C++: size_t Mat::elemSize1() + private static native long n_elemSize1(long nativeObj); + + // C++: bool Mat::empty() + private static native boolean n_empty(long nativeObj); + + // C++: static Mat Mat::eye(int rows, int cols, int type) + private static native long n_eye(int rows, int cols, int type); + + // C++: static Mat Mat::eye(Size size, int type) + private static native long n_eye(double size_width, double size_height, int type); + + // C++: Mat Mat::inv(int method = DECOMP_LU) + private static native long n_inv(long nativeObj, int method); + + private static native long n_inv(long nativeObj); + + // C++: bool Mat::isContinuous() + private static native boolean n_isContinuous(long nativeObj); + + // C++: bool Mat::isSubmatrix() + private static native boolean n_isSubmatrix(long nativeObj); + + // C++: void Mat::locateROI(Size wholeSize, Point ofs) + private static native void locateROI_0(long nativeObj, double[] wholeSize_out, double[] ofs_out); + + // C++: Mat Mat::mul(Mat m, double scale = 1) + private static native long n_mul(long nativeObj, long m_nativeObj, double scale); + + private static native long n_mul(long nativeObj, long m_nativeObj); + + // C++: static Mat Mat::ones(int rows, int cols, int type) + private static native long n_ones(int rows, int cols, int type); + + // C++: static Mat Mat::ones(Size size, int type) + private static native long n_ones(double size_width, double size_height, int type); + + // C++: void Mat::push_back(Mat m) + private static native void n_push_back(long nativeObj, long m_nativeObj); + + // C++: void Mat::release() + private static native void n_release(long nativeObj); + + // C++: Mat Mat::reshape(int cn, int rows = 0) + private static native long n_reshape(long nativeObj, int cn, int rows); + + private static native long n_reshape(long nativeObj, int cn); + + // C++: Mat Mat::row(int y) + private static native long n_row(long nativeObj, int y); + + // C++: Mat Mat::rowRange(int startrow, int endrow) + private static native long n_rowRange(long nativeObj, int startrow, int endrow); + + // C++: int Mat::rows() + private static native int n_rows(long nativeObj); + + // C++: Mat Mat::operator =(Scalar s) + private static native long n_setTo(long nativeObj, double s_val0, double s_val1, double s_val2, double s_val3); + + // C++: Mat Mat::setTo(Mat value, Mat mask = Mat()) + private static native long n_setTo(long nativeObj, long value_nativeObj, long mask_nativeObj); + + private static native long n_setTo(long nativeObj, long value_nativeObj); + + // C++: Size Mat::size() + private static native double[] n_size(long nativeObj); + + // C++: size_t Mat::step1(int i = 0) + private static native long n_step1(long nativeObj, int i); + + private static native long n_step1(long nativeObj); + + // C++: Mat Mat::operator()(Range rowRange, Range colRange) + private static native long n_submat_rr(long nativeObj, int rowRange_start, int rowRange_end, int colRange_start, int colRange_end); + + // C++: Mat Mat::operator()(Rect roi) + private static native long n_submat(long nativeObj, int roi_x, int roi_y, int roi_width, int roi_height); + + // C++: Mat Mat::t() + private static native long n_t(long nativeObj); + + // C++: size_t Mat::total() + private static native long n_total(long nativeObj); + + // C++: int Mat::type() + private static native int n_type(long nativeObj); + + // C++: static Mat Mat::zeros(int rows, int cols, int type) + private static native long n_zeros(int rows, int cols, int type); + + // C++: static Mat Mat::zeros(Size size, int type) + private static native long n_zeros(double size_width, double size_height, int type); + + // native support for java finalize() + private static native void n_delete(long nativeObj); + + private static native int nPutD(long self, int row, int col, int count, double[] data); + + private static native int nPutF(long self, int row, int col, int count, float[] data); + + private static native int nPutI(long self, int row, int col, int count, int[] data); + + private static native int nPutS(long self, int row, int col, int count, short[] data); + + private static native int nPutB(long self, int row, int col, int count, byte[] data); + + private static native int nGetB(long self, int row, int col, int count, byte[] vals); + + private static native int nGetS(long self, int row, int col, int count, short[] vals); + + private static native int nGetI(long self, int row, int col, int count, int[] vals); + + private static native int nGetF(long self, int row, int col, int count, float[] vals); + + private static native int nGetD(long self, int row, int col, int count, double[] vals); + + private static native double[] nGet(long self, int row, int col); + + private static native String nDump(long self); +} diff --git a/modules/java/src/java/highgui+VideoCapture.java b/modules/java/src/java/highgui+VideoCapture.java index bb71fc0410..9540f58e81 100644 --- a/modules/java/src/java/highgui+VideoCapture.java +++ b/modules/java/src/java/highgui+VideoCapture.java @@ -194,6 +194,12 @@ public class VideoCapture { super.finalize(); } + // native stuff + + static { + System.loadLibrary("opencv_java"); + } + // C++: VideoCapture::VideoCapture() private static native long n_VideoCapture(); diff --git a/modules/java/src/java/utils+Converters.java b/modules/java/src/java/utils+Converters.java index 7734841954..006edff09a 100644 --- a/modules/java/src/java/utils+Converters.java +++ b/modules/java/src/java/utils+Converters.java @@ -1,724 +1,730 @@ -package org.opencv.utils; - -import java.util.ArrayList; -import java.util.List; - -import org.opencv.core.CvType; -import org.opencv.core.Mat; -import org.opencv.core.MatOfByte; -import org.opencv.core.MatOfDMatch; -import org.opencv.core.MatOfKeyPoint; -import org.opencv.core.MatOfPoint; -import org.opencv.core.MatOfPoint2f; -import org.opencv.core.MatOfPoint3f; -import org.opencv.core.Point; -import org.opencv.core.Point3; -import org.opencv.core.Rect; -import org.opencv.features2d.DMatch; -import org.opencv.features2d.KeyPoint; - -public class Converters { - - public static Mat vector_Point_to_Mat(List pts) { - return vector_Point_to_Mat(pts, CvType.CV_32S); - } - - public static Mat vector_Point2f_to_Mat(List pts) { - return vector_Point_to_Mat(pts, CvType.CV_32F); - } - - public static Mat vector_Point2d_to_Mat(List pts) { - return vector_Point_to_Mat(pts, CvType.CV_64F); - } - - public static Mat vector_Point_to_Mat(List pts, int typeDepth) { - Mat res; - int count = (pts != null) ? pts.size() : 0; - if (count > 0) { - switch (typeDepth) { - case CvType.CV_32S: { - res = new Mat(count, 1, CvType.CV_32SC2); - int[] buff = new int[count * 2]; - for (int i = 0; i < count; i++) { - Point p = pts.get(i); - buff[i * 2] = (int) p.x; - buff[i * 2 + 1] = (int) p.y; - } - res.put(0, 0, buff); - } - break; - - case CvType.CV_32F: { - res = new Mat(count, 1, CvType.CV_32FC2); - float[] buff = new float[count * 2]; - for (int i = 0; i < count; i++) { - Point p = pts.get(i); - buff[i * 2] = (float) p.x; - buff[i * 2 + 1] = (float) p.y; - } - res.put(0, 0, buff); - } - break; - - case CvType.CV_64F: { - res = new Mat(count, 1, CvType.CV_64FC2); - double[] buff = new double[count * 2]; - for (int i = 0; i < count; i++) { - Point p = pts.get(i); - buff[i * 2] = p.x; - buff[i * 2 + 1] = p.y; - } - res.put(0, 0, buff); - } - break; - - default: - throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F"); - } - } else { - res = new Mat(); - } - return res; - } - - public static Mat vector_Point3i_to_Mat(List pts) { - return vector_Point3_to_Mat(pts, CvType.CV_32S); - } - - public static Mat vector_Point3f_to_Mat(List pts) { - return vector_Point3_to_Mat(pts, CvType.CV_32F); - } - - public static Mat vector_Point3d_to_Mat(List pts) { - return vector_Point3_to_Mat(pts, CvType.CV_64F); - } - - public static Mat vector_Point3_to_Mat(List pts, int typeDepth) { - Mat res; - int count = (pts != null) ? pts.size() : 0; - if (count > 0) { - switch (typeDepth) { - case CvType.CV_32S: { - res = new Mat(count, 1, CvType.CV_32SC3); - int[] buff = new int[count * 3]; - for (int i = 0; i < count; i++) { - Point3 p = pts.get(i); - buff[i * 3] = (int) p.x; - buff[i * 3 + 1] = (int) p.y; - buff[i * 3 + 2] = (int) p.z; - } - res.put(0, 0, buff); - } - break; - - case CvType.CV_32F: { - res = new Mat(count, 1, CvType.CV_32FC3); - float[] buff = new float[count * 3]; - for (int i = 0; i < count; i++) { - Point3 p = pts.get(i); - buff[i * 3] = (float) p.x; - buff[i * 3 + 1] = (float) p.y; - buff[i * 3 + 2] = (float) p.z; - } - res.put(0, 0, buff); - } - break; - - case CvType.CV_64F: { - res = new Mat(count, 1, CvType.CV_64FC3); - double[] buff = new double[count * 3]; - for (int i = 0; i < count; i++) { - Point3 p = pts.get(i); - buff[i * 3] = p.x; - buff[i * 3 + 1] = p.y; - buff[i * 3 + 2] = p.z; - } - res.put(0, 0, buff); - } - break; - - default: - throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F"); - } - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_Point2f(Mat m, List pts) { - Mat_to_vector_Point(m, pts); - } - - public static void Mat_to_vector_Point2d(Mat m, List pts) { - Mat_to_vector_Point(m, pts); - } - - public static void Mat_to_vector_Point(Mat m, List pts) { - if (pts == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - int count = m.rows(); - int type = m.type(); - if (m.cols() != 1) - throw new java.lang.IllegalArgumentException("Input Mat should have one column\n" + m); - - pts.clear(); - if (type == CvType.CV_32SC2) { - int[] buff = new int[2 * count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - pts.add(new Point(buff[i * 2], buff[i * 2 + 1])); - } - } else if (type == CvType.CV_32FC2) { - float[] buff = new float[2 * count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - pts.add(new Point(buff[i * 2], buff[i * 2 + 1])); - } - } else if (type == CvType.CV_64FC2) { - double[] buff = new double[2 * count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - pts.add(new Point(buff[i * 2], buff[i * 2 + 1])); - } - } else { - throw new java.lang.IllegalArgumentException( - "Input Mat should be of CV_32SC2, CV_32FC2 or CV_64FC2 type\n" + m); - } - } - - public static void Mat_to_vector_Point3i(Mat m, List pts) { - Mat_to_vector_Point3(m, pts); - } - - public static void Mat_to_vector_Point3f(Mat m, List pts) { - Mat_to_vector_Point3(m, pts); - } - - public static void Mat_to_vector_Point3d(Mat m, List pts) { - Mat_to_vector_Point3(m, pts); - } - - public static void Mat_to_vector_Point3(Mat m, List pts) { - if (pts == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - int count = m.rows(); - int type = m.type(); - if (m.cols() != 1) - throw new java.lang.IllegalArgumentException("Input Mat should have one column\n" + m); - - pts.clear(); - if (type == CvType.CV_32SC3) { - int[] buff = new int[3 * count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2])); - } - } else if (type == CvType.CV_32FC3) { - float[] buff = new float[3 * count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2])); - } - } else if (type == CvType.CV_64FC3) { - double[] buff = new double[3 * count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2])); - } - } else { - throw new java.lang.IllegalArgumentException( - "Input Mat should be of CV_32SC3, CV_32FC3 or CV_64FC3 type\n" + m); - } - } - - public static Mat vector_Mat_to_Mat(List mats) { - Mat res; - int count = (mats != null) ? mats.size() : 0; - if (count > 0) { - res = new Mat(count, 1, CvType.CV_32SC2); - int[] buff = new int[count * 2]; - for (int i = 0; i < count; i++) { - long addr = mats.get(i).nativeObj; - buff[i * 2] = (int) (addr >> 32); - buff[i * 2 + 1] = (int) (addr & 0xffffffff); - } - res.put(0, 0, buff); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_Mat(Mat m, List mats) { - if (mats == null) - throw new java.lang.IllegalArgumentException("mats == null"); - int count = m.rows(); - if (CvType.CV_32SC2 != m.type() || m.cols() != 1) - throw new java.lang.IllegalArgumentException( - "CvType.CV_32SC2 != m.type() || m.cols()!=1\n" + m); - - mats.clear(); - int[] buff = new int[count * 2]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - long addr = (((long) buff[i * 2]) << 32) | ((long) buff[i * 2 + 1]); - mats.add(new Mat(addr)); - } - } - - public static Mat vector_float_to_Mat(List fs) { - Mat res; - int count = (fs != null) ? fs.size() : 0; - if (count > 0) { - res = new Mat(count, 1, CvType.CV_32FC1); - float[] buff = new float[count]; - for (int i = 0; i < count; i++) { - float f = fs.get(i); - buff[i] = f; - } - res.put(0, 0, buff); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_float(Mat m, List fs) { - if (fs == null) - throw new java.lang.IllegalArgumentException("fs == null"); - int count = m.rows(); - if (CvType.CV_32FC1 != m.type() || m.cols() != 1) - throw new java.lang.IllegalArgumentException( - "CvType.CV_32FC1 != m.type() || m.cols()!=1\n" + m); - - fs.clear(); - float[] buff = new float[count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - fs.add(buff[i]); - } - } - - public static Mat vector_uchar_to_Mat(List bs) { - Mat res; - int count = (bs != null) ? bs.size() : 0; - if (count > 0) { - res = new Mat(count, 1, CvType.CV_8UC1); - byte[] buff = new byte[count]; - for (int i = 0; i < count; i++) { - byte b = bs.get(i); - buff[i] = b; - } - res.put(0, 0, buff); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_uchar(Mat m, List us) { - if (us == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - int count = m.rows(); - if (CvType.CV_8UC1 != m.type() || m.cols() != 1) - throw new java.lang.IllegalArgumentException( - "CvType.CV_8UC1 != m.type() || m.cols()!=1\n" + m); - - us.clear(); - byte[] buff = new byte[count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - us.add(buff[i]); - } - } - - public static Mat vector_char_to_Mat(List bs) { - Mat res; - int count = (bs != null) ? bs.size() : 0; - if (count > 0) { - res = new Mat(count, 1, CvType.CV_8SC1); - byte[] buff = new byte[count]; - for (int i = 0; i < count; i++) { - byte b = bs.get(i); - buff[i] = b; - } - res.put(0, 0, buff); - } else { - res = new Mat(); - } - return res; - } - - public static Mat vector_int_to_Mat(List is) { - Mat res; - int count = (is != null) ? is.size() : 0; - if (count > 0) { - res = new Mat(count, 1, CvType.CV_32SC1); - int[] buff = new int[count]; - for (int i = 0; i < count; i++) { - int v = is.get(i); - buff[i] = v; - } - res.put(0, 0, buff); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_int(Mat m, List is) { - if (is == null) - throw new java.lang.IllegalArgumentException("is == null"); - int count = m.rows(); - if (CvType.CV_32SC1 != m.type() || m.cols() != 1) - throw new java.lang.IllegalArgumentException( - "CvType.CV_32SC1 != m.type() || m.cols()!=1\n" + m); - - is.clear(); - int[] buff = new int[count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - is.add(buff[i]); - } - } - - public static void Mat_to_vector_char(Mat m, List bs) { - if (bs == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - int count = m.rows(); - if (CvType.CV_8SC1 != m.type() || m.cols() != 1) - throw new java.lang.IllegalArgumentException( - "CvType.CV_8SC1 != m.type() || m.cols()!=1\n" + m); - - bs.clear(); - byte[] buff = new byte[count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - bs.add(buff[i]); - } - } - - public static Mat vector_Rect_to_Mat(List rs) { - Mat res; - int count = (rs != null) ? rs.size() : 0; - if (count > 0) { - res = new Mat(count, 1, CvType.CV_32SC4); - int[] buff = new int[4 * count]; - for (int i = 0; i < count; i++) { - Rect r = rs.get(i); - buff[4 * i] = r.x; - buff[4 * i + 1] = r.y; - buff[4 * i + 2] = r.width; - buff[4 * i + 3] = r.height; - } - res.put(0, 0, buff); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_Rect(Mat m, List rs) { - if (rs == null) - throw new java.lang.IllegalArgumentException("rs == null"); - int count = m.rows(); - if (CvType.CV_32SC4 != m.type() || m.cols() != 1) - throw new java.lang.IllegalArgumentException( - "CvType.CV_32SC4 != m.type() || m.rows()!=1\n" + m); - - rs.clear(); - int[] buff = new int[4 * count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - rs.add(new Rect(buff[4 * i], buff[4 * i + 1], buff[4 * i + 2], buff[4 * i + 3])); - } - } - - public static Mat vector_KeyPoint_to_Mat(List kps) { - Mat res; - int count = (kps != null) ? kps.size() : 0; - if (count > 0) { - res = new Mat(count, 1, CvType.CV_64FC(7)); - double[] buff = new double[count * 7]; - for (int i = 0; i < count; i++) { - KeyPoint kp = kps.get(i); - buff[7 * i] = kp.pt.x; - buff[7 * i + 1] = kp.pt.y; - buff[7 * i + 2] = kp.size; - buff[7 * i + 3] = kp.angle; - buff[7 * i + 4] = kp.response; - buff[7 * i + 5] = kp.octave; - buff[7 * i + 6] = kp.class_id; - } - res.put(0, 0, buff); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_KeyPoint(Mat m, List kps) { - if (kps == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - int count = m.rows(); - if (CvType.CV_64FC(7) != m.type() || m.cols() != 1) - throw new java.lang.IllegalArgumentException( - "CvType.CV_64FC(7) != m.type() || m.cols()!=1\n" + m); - - kps.clear(); - double[] buff = new double[7 * count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - kps.add(new KeyPoint((float) buff[7 * i], (float) buff[7 * i + 1], (float) buff[7 * i + 2], (float) buff[7 * i + 3], - (float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6])); - } - } - - // vector_vector_Point - public static Mat vector_vector_Point_to_Mat(List pts, List mats) { - Mat res; - int lCount = (pts != null) ? pts.size() : 0; - if (lCount > 0) { - for (MatOfPoint vpt : pts) - mats.add(vpt); - res = vector_Mat_to_Mat(mats); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_vector_Point(Mat m, List pts) { - if (pts == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - - if (m == null) - throw new java.lang.IllegalArgumentException("Input Mat can't be null"); - - List mats = new ArrayList(m.rows()); - Mat_to_vector_Mat(m, mats); - for (Mat mi : mats) { - MatOfPoint pt = new MatOfPoint(mi); - pts.add(pt); - } - } - - // vector_vector_Point2f - public static void Mat_to_vector_vector_Point2f(Mat m, List pts) { - if (pts == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - - if (m == null) - throw new java.lang.IllegalArgumentException("Input Mat can't be null"); - - List mats = new ArrayList(m.rows()); - Mat_to_vector_Mat(m, mats); - for (Mat mi : mats) { - MatOfPoint2f pt = new MatOfPoint2f(mi); - pts.add(pt); - } - } - - // vector_vector_Point2f - public static Mat vector_vector_Point2f_to_Mat(List pts, List mats) { - Mat res; - int lCount = (pts != null) ? pts.size() : 0; - if (lCount > 0) { - for (MatOfPoint2f vpt : pts) - mats.add(vpt); - res = vector_Mat_to_Mat(mats); - } else { - res = new Mat(); - } - return res; - } - - // vector_vector_Point3f - public static void Mat_to_vector_vector_Point3f(Mat m, List pts) { - if (pts == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - - if (m == null) - throw new java.lang.IllegalArgumentException("Input Mat can't be null"); - - List mats = new ArrayList(m.rows()); - Mat_to_vector_Mat(m, mats); - for (Mat mi : mats) { - MatOfPoint3f pt = new MatOfPoint3f(mi); - pts.add(pt); - } - } - - // vector_vector_Point3f - public static Mat vector_vector_Point3f_to_Mat(List pts, List mats) { - Mat res; - int lCount = (pts != null) ? pts.size() : 0; - if (lCount > 0) { - for (MatOfPoint3f vpt : pts) - mats.add(vpt); - res = vector_Mat_to_Mat(mats); - } else { - res = new Mat(); - } - return res; - } - - // vector_vector_KeyPoint - public static Mat vector_vector_KeyPoint_to_Mat(List kps, List mats) { - Mat res; - int lCount = (kps != null) ? kps.size() : 0; - if (lCount > 0) { - for (MatOfKeyPoint vkp : kps) - mats.add(vkp); - res = vector_Mat_to_Mat(mats); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_vector_KeyPoint(Mat m, List kps) { - if (kps == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - - if (m == null) - throw new java.lang.IllegalArgumentException("Input Mat can't be null"); - - List mats = new ArrayList(m.rows()); - Mat_to_vector_Mat(m, mats); - for (Mat mi : mats) { - MatOfKeyPoint vkp = new MatOfKeyPoint(mi); - kps.add(vkp); - } - } - - public static Mat vector_double_to_Mat(List ds) { - Mat res; - int count = (ds != null) ? ds.size() : 0; - if (count > 0) { - res = new Mat(count, 1, CvType.CV_64FC1); - double[] buff = new double[count]; - for (int i = 0; i < count; i++) { - double v = ds.get(i); - buff[i] = v; - } - res.put(0, 0, buff); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_double(Mat m, List ds) { - if (ds == null) - throw new java.lang.IllegalArgumentException("ds == null"); - int count = m.rows(); - if (CvType.CV_64FC1 != m.type() || m.cols() != 1) - throw new java.lang.IllegalArgumentException( - "CvType.CV_64FC1 != m.type() || m.cols()!=1\n" + m); - - ds.clear(); - double[] buff = new double[count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - ds.add(buff[i]); - } - } - - public static Mat vector_DMatch_to_Mat(List matches) { - Mat res; - int count = (matches != null) ? matches.size() : 0; - if (count > 0) { - res = new Mat(count, 1, CvType.CV_64FC4); - double[] buff = new double[count * 4]; - for (int i = 0; i < count; i++) { - DMatch m = matches.get(i); - buff[4 * i] = m.queryIdx; - buff[4 * i + 1] = m.trainIdx; - buff[4 * i + 2] = m.imgIdx; - buff[4 * i + 3] = m.distance; - } - res.put(0, 0, buff); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_DMatch(Mat m, List matches) { - if (matches == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - int count = m.rows(); - if (CvType.CV_64FC4 != m.type() || m.cols() != 1) - throw new java.lang.IllegalArgumentException( - "CvType.CV_64FC4 != m.type() || m.cols()!=1\n" + m); - - matches.clear(); - double[] buff = new double[4 * count]; - m.get(0, 0, buff); - for (int i = 0; i < count; i++) { - matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3])); - } - } - - // vector_vector_DMatch - public static Mat vector_vector_DMatch_to_Mat(List lvdm, List mats) { - Mat res; - int lCount = (lvdm != null) ? lvdm.size() : 0; - if (lCount > 0) { - for (MatOfDMatch vdm : lvdm) - mats.add(vdm); - res = vector_Mat_to_Mat(mats); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_vector_DMatch(Mat m, List lvdm) { - if (lvdm == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - - if (m == null) - throw new java.lang.IllegalArgumentException("Input Mat can't be null"); - - List mats = new ArrayList(m.rows()); - Mat_to_vector_Mat(m, mats); - lvdm.clear(); - for (Mat mi : mats) { - MatOfDMatch vdm = new MatOfDMatch(mi); - lvdm.add(vdm); - } - } - - // vector_vector_char - public static Mat vector_vector_char_to_Mat(List lvb, List mats) { - Mat res; - int lCount = (lvb != null) ? lvb.size() : 0; - if (lCount > 0) { - for (MatOfByte vb : lvb) - mats.add(vb); - res = vector_Mat_to_Mat(mats); - } else { - res = new Mat(); - } - return res; - } - - public static void Mat_to_vector_vector_char(Mat m, List> llb) { - if (llb == null) - throw new java.lang.IllegalArgumentException("Output List can't be null"); - - if (m == null) - throw new java.lang.IllegalArgumentException("Input Mat can't be null"); - - List mats = new ArrayList(m.rows()); - Mat_to_vector_Mat(m, mats); - for (Mat mi : mats) { - List lb = new ArrayList(); - Mat_to_vector_char(mi, lb); - llb.add(lb); - } - } -} +package org.opencv.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.opencv.core.CvType; +import org.opencv.core.Mat; +import org.opencv.core.MatOfByte; +import org.opencv.core.MatOfDMatch; +import org.opencv.core.MatOfKeyPoint; +import org.opencv.core.MatOfPoint; +import org.opencv.core.MatOfPoint2f; +import org.opencv.core.MatOfPoint3f; +import org.opencv.core.Point; +import org.opencv.core.Point3; +import org.opencv.core.Rect; +import org.opencv.features2d.DMatch; +import org.opencv.features2d.KeyPoint; + +public class Converters { + + public static Mat vector_Point_to_Mat(List pts) { + return vector_Point_to_Mat(pts, CvType.CV_32S); + } + + public static Mat vector_Point2f_to_Mat(List pts) { + return vector_Point_to_Mat(pts, CvType.CV_32F); + } + + public static Mat vector_Point2d_to_Mat(List pts) { + return vector_Point_to_Mat(pts, CvType.CV_64F); + } + + public static Mat vector_Point_to_Mat(List pts, int typeDepth) { + Mat res; + int count = (pts != null) ? pts.size() : 0; + if (count > 0) { + switch (typeDepth) { + case CvType.CV_32S: { + res = new Mat(count, 1, CvType.CV_32SC2); + int[] buff = new int[count * 2]; + for (int i = 0; i < count; i++) { + Point p = pts.get(i); + buff[i * 2] = (int) p.x; + buff[i * 2 + 1] = (int) p.y; + } + res.put(0, 0, buff); + } + break; + + case CvType.CV_32F: { + res = new Mat(count, 1, CvType.CV_32FC2); + float[] buff = new float[count * 2]; + for (int i = 0; i < count; i++) { + Point p = pts.get(i); + buff[i * 2] = (float) p.x; + buff[i * 2 + 1] = (float) p.y; + } + res.put(0, 0, buff); + } + break; + + case CvType.CV_64F: { + res = new Mat(count, 1, CvType.CV_64FC2); + double[] buff = new double[count * 2]; + for (int i = 0; i < count; i++) { + Point p = pts.get(i); + buff[i * 2] = p.x; + buff[i * 2 + 1] = p.y; + } + res.put(0, 0, buff); + } + break; + + default: + throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F"); + } + } else { + res = new Mat(); + } + return res; + } + + public static Mat vector_Point3i_to_Mat(List pts) { + return vector_Point3_to_Mat(pts, CvType.CV_32S); + } + + public static Mat vector_Point3f_to_Mat(List pts) { + return vector_Point3_to_Mat(pts, CvType.CV_32F); + } + + public static Mat vector_Point3d_to_Mat(List pts) { + return vector_Point3_to_Mat(pts, CvType.CV_64F); + } + + public static Mat vector_Point3_to_Mat(List pts, int typeDepth) { + Mat res; + int count = (pts != null) ? pts.size() : 0; + if (count > 0) { + switch (typeDepth) { + case CvType.CV_32S: { + res = new Mat(count, 1, CvType.CV_32SC3); + int[] buff = new int[count * 3]; + for (int i = 0; i < count; i++) { + Point3 p = pts.get(i); + buff[i * 3] = (int) p.x; + buff[i * 3 + 1] = (int) p.y; + buff[i * 3 + 2] = (int) p.z; + } + res.put(0, 0, buff); + } + break; + + case CvType.CV_32F: { + res = new Mat(count, 1, CvType.CV_32FC3); + float[] buff = new float[count * 3]; + for (int i = 0; i < count; i++) { + Point3 p = pts.get(i); + buff[i * 3] = (float) p.x; + buff[i * 3 + 1] = (float) p.y; + buff[i * 3 + 2] = (float) p.z; + } + res.put(0, 0, buff); + } + break; + + case CvType.CV_64F: { + res = new Mat(count, 1, CvType.CV_64FC3); + double[] buff = new double[count * 3]; + for (int i = 0; i < count; i++) { + Point3 p = pts.get(i); + buff[i * 3] = p.x; + buff[i * 3 + 1] = p.y; + buff[i * 3 + 2] = p.z; + } + res.put(0, 0, buff); + } + break; + + default: + throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F"); + } + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_Point2f(Mat m, List pts) { + Mat_to_vector_Point(m, pts); + } + + public static void Mat_to_vector_Point2d(Mat m, List pts) { + Mat_to_vector_Point(m, pts); + } + + public static void Mat_to_vector_Point(Mat m, List pts) { + if (pts == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + int count = m.rows(); + int type = m.type(); + if (m.cols() != 1) + throw new java.lang.IllegalArgumentException("Input Mat should have one column\n" + m); + + pts.clear(); + if (type == CvType.CV_32SC2) { + int[] buff = new int[2 * count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + pts.add(new Point(buff[i * 2], buff[i * 2 + 1])); + } + } else if (type == CvType.CV_32FC2) { + float[] buff = new float[2 * count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + pts.add(new Point(buff[i * 2], buff[i * 2 + 1])); + } + } else if (type == CvType.CV_64FC2) { + double[] buff = new double[2 * count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + pts.add(new Point(buff[i * 2], buff[i * 2 + 1])); + } + } else { + throw new java.lang.IllegalArgumentException( + "Input Mat should be of CV_32SC2, CV_32FC2 or CV_64FC2 type\n" + m); + } + } + + public static void Mat_to_vector_Point3i(Mat m, List pts) { + Mat_to_vector_Point3(m, pts); + } + + public static void Mat_to_vector_Point3f(Mat m, List pts) { + Mat_to_vector_Point3(m, pts); + } + + public static void Mat_to_vector_Point3d(Mat m, List pts) { + Mat_to_vector_Point3(m, pts); + } + + public static void Mat_to_vector_Point3(Mat m, List pts) { + if (pts == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + int count = m.rows(); + int type = m.type(); + if (m.cols() != 1) + throw new java.lang.IllegalArgumentException("Input Mat should have one column\n" + m); + + pts.clear(); + if (type == CvType.CV_32SC3) { + int[] buff = new int[3 * count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2])); + } + } else if (type == CvType.CV_32FC3) { + float[] buff = new float[3 * count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2])); + } + } else if (type == CvType.CV_64FC3) { + double[] buff = new double[3 * count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2])); + } + } else { + throw new java.lang.IllegalArgumentException( + "Input Mat should be of CV_32SC3, CV_32FC3 or CV_64FC3 type\n" + m); + } + } + + public static Mat vector_Mat_to_Mat(List mats) { + Mat res; + int count = (mats != null) ? mats.size() : 0; + if (count > 0) { + res = new Mat(count, 1, CvType.CV_32SC2); + int[] buff = new int[count * 2]; + for (int i = 0; i < count; i++) { + long addr = mats.get(i).nativeObj; + buff[i * 2] = (int) (addr >> 32); + buff[i * 2 + 1] = (int) (addr & 0xffffffff); + } + res.put(0, 0, buff); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_Mat(Mat m, List mats) { + if (mats == null) + throw new java.lang.IllegalArgumentException("mats == null"); + int count = m.rows(); + if (CvType.CV_32SC2 != m.type() || m.cols() != 1) + throw new java.lang.IllegalArgumentException( + "CvType.CV_32SC2 != m.type() || m.cols()!=1\n" + m); + + mats.clear(); + int[] buff = new int[count * 2]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + long addr = (((long) buff[i * 2]) << 32) | ((long) buff[i * 2 + 1]); + mats.add(new Mat(addr)); + } + } + + public static Mat vector_float_to_Mat(List fs) { + Mat res; + int count = (fs != null) ? fs.size() : 0; + if (count > 0) { + res = new Mat(count, 1, CvType.CV_32FC1); + float[] buff = new float[count]; + for (int i = 0; i < count; i++) { + float f = fs.get(i); + buff[i] = f; + } + res.put(0, 0, buff); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_float(Mat m, List fs) { + if (fs == null) + throw new java.lang.IllegalArgumentException("fs == null"); + int count = m.rows(); + if (CvType.CV_32FC1 != m.type() || m.cols() != 1) + throw new java.lang.IllegalArgumentException( + "CvType.CV_32FC1 != m.type() || m.cols()!=1\n" + m); + + fs.clear(); + float[] buff = new float[count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + fs.add(buff[i]); + } + } + + public static Mat vector_uchar_to_Mat(List bs) { + Mat res; + int count = (bs != null) ? bs.size() : 0; + if (count > 0) { + res = new Mat(count, 1, CvType.CV_8UC1); + byte[] buff = new byte[count]; + for (int i = 0; i < count; i++) { + byte b = bs.get(i); + buff[i] = b; + } + res.put(0, 0, buff); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_uchar(Mat m, List us) { + if (us == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + int count = m.rows(); + if (CvType.CV_8UC1 != m.type() || m.cols() != 1) + throw new java.lang.IllegalArgumentException( + "CvType.CV_8UC1 != m.type() || m.cols()!=1\n" + m); + + us.clear(); + byte[] buff = new byte[count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + us.add(buff[i]); + } + } + + public static Mat vector_char_to_Mat(List bs) { + Mat res; + int count = (bs != null) ? bs.size() : 0; + if (count > 0) { + res = new Mat(count, 1, CvType.CV_8SC1); + byte[] buff = new byte[count]; + for (int i = 0; i < count; i++) { + byte b = bs.get(i); + buff[i] = b; + } + res.put(0, 0, buff); + } else { + res = new Mat(); + } + return res; + } + + public static Mat vector_int_to_Mat(List is) { + Mat res; + int count = (is != null) ? is.size() : 0; + if (count > 0) { + res = new Mat(count, 1, CvType.CV_32SC1); + int[] buff = new int[count]; + for (int i = 0; i < count; i++) { + int v = is.get(i); + buff[i] = v; + } + res.put(0, 0, buff); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_int(Mat m, List is) { + if (is == null) + throw new java.lang.IllegalArgumentException("is == null"); + int count = m.rows(); + if (CvType.CV_32SC1 != m.type() || m.cols() != 1) + throw new java.lang.IllegalArgumentException( + "CvType.CV_32SC1 != m.type() || m.cols()!=1\n" + m); + + is.clear(); + int[] buff = new int[count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + is.add(buff[i]); + } + } + + public static void Mat_to_vector_char(Mat m, List bs) { + if (bs == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + int count = m.rows(); + if (CvType.CV_8SC1 != m.type() || m.cols() != 1) + throw new java.lang.IllegalArgumentException( + "CvType.CV_8SC1 != m.type() || m.cols()!=1\n" + m); + + bs.clear(); + byte[] buff = new byte[count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + bs.add(buff[i]); + } + } + + public static Mat vector_Rect_to_Mat(List rs) { + Mat res; + int count = (rs != null) ? rs.size() : 0; + if (count > 0) { + res = new Mat(count, 1, CvType.CV_32SC4); + int[] buff = new int[4 * count]; + for (int i = 0; i < count; i++) { + Rect r = rs.get(i); + buff[4 * i] = r.x; + buff[4 * i + 1] = r.y; + buff[4 * i + 2] = r.width; + buff[4 * i + 3] = r.height; + } + res.put(0, 0, buff); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_Rect(Mat m, List rs) { + if (rs == null) + throw new java.lang.IllegalArgumentException("rs == null"); + int count = m.rows(); + if (CvType.CV_32SC4 != m.type() || m.cols() != 1) + throw new java.lang.IllegalArgumentException( + "CvType.CV_32SC4 != m.type() || m.rows()!=1\n" + m); + + rs.clear(); + int[] buff = new int[4 * count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + rs.add(new Rect(buff[4 * i], buff[4 * i + 1], buff[4 * i + 2], buff[4 * i + 3])); + } + } + + public static Mat vector_KeyPoint_to_Mat(List kps) { + Mat res; + int count = (kps != null) ? kps.size() : 0; + if (count > 0) { + res = new Mat(count, 1, CvType.CV_64FC(7)); + double[] buff = new double[count * 7]; + for (int i = 0; i < count; i++) { + KeyPoint kp = kps.get(i); + buff[7 * i] = kp.pt.x; + buff[7 * i + 1] = kp.pt.y; + buff[7 * i + 2] = kp.size; + buff[7 * i + 3] = kp.angle; + buff[7 * i + 4] = kp.response; + buff[7 * i + 5] = kp.octave; + buff[7 * i + 6] = kp.class_id; + } + res.put(0, 0, buff); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_KeyPoint(Mat m, List kps) { + if (kps == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + int count = m.rows(); + if (CvType.CV_64FC(7) != m.type() || m.cols() != 1) + throw new java.lang.IllegalArgumentException( + "CvType.CV_64FC(7) != m.type() || m.cols()!=1\n" + m); + + kps.clear(); + double[] buff = new double[7 * count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + kps.add(new KeyPoint((float) buff[7 * i], (float) buff[7 * i + 1], (float) buff[7 * i + 2], (float) buff[7 * i + 3], + (float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6])); + } + } + + // vector_vector_Point + public static Mat vector_vector_Point_to_Mat(List pts, List mats) { + Mat res; + int lCount = (pts != null) ? pts.size() : 0; + if (lCount > 0) { + for (MatOfPoint vpt : pts) + mats.add(vpt); + res = vector_Mat_to_Mat(mats); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_vector_Point(Mat m, List pts) { + if (pts == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + + if (m == null) + throw new java.lang.IllegalArgumentException("Input Mat can't be null"); + + List mats = new ArrayList(m.rows()); + Mat_to_vector_Mat(m, mats); + for (Mat mi : mats) { + MatOfPoint pt = new MatOfPoint(mi); + pts.add(pt); + } + } + + // vector_vector_Point2f + public static void Mat_to_vector_vector_Point2f(Mat m, List pts) { + if (pts == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + + if (m == null) + throw new java.lang.IllegalArgumentException("Input Mat can't be null"); + + List mats = new ArrayList(m.rows()); + Mat_to_vector_Mat(m, mats); + for (Mat mi : mats) { + MatOfPoint2f pt = new MatOfPoint2f(mi); + pts.add(pt); + } + } + + // vector_vector_Point2f + public static Mat vector_vector_Point2f_to_Mat(List pts, List mats) { + Mat res; + int lCount = (pts != null) ? pts.size() : 0; + if (lCount > 0) { + for (MatOfPoint2f vpt : pts) + mats.add(vpt); + res = vector_Mat_to_Mat(mats); + } else { + res = new Mat(); + } + return res; + } + + // vector_vector_Point3f + public static void Mat_to_vector_vector_Point3f(Mat m, List pts) { + if (pts == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + + if (m == null) + throw new java.lang.IllegalArgumentException("Input Mat can't be null"); + + List mats = new ArrayList(m.rows()); + Mat_to_vector_Mat(m, mats); + for (Mat mi : mats) { + MatOfPoint3f pt = new MatOfPoint3f(mi); + pts.add(pt); + } + } + + // vector_vector_Point3f + public static Mat vector_vector_Point3f_to_Mat(List pts, List mats) { + Mat res; + int lCount = (pts != null) ? pts.size() : 0; + if (lCount > 0) { + for (MatOfPoint3f vpt : pts) + mats.add(vpt); + res = vector_Mat_to_Mat(mats); + } else { + res = new Mat(); + } + return res; + } + + // vector_vector_KeyPoint + public static Mat vector_vector_KeyPoint_to_Mat(List kps, List mats) { + Mat res; + int lCount = (kps != null) ? kps.size() : 0; + if (lCount > 0) { + for (MatOfKeyPoint vkp : kps) + mats.add(vkp); + res = vector_Mat_to_Mat(mats); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_vector_KeyPoint(Mat m, List kps) { + if (kps == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + + if (m == null) + throw new java.lang.IllegalArgumentException("Input Mat can't be null"); + + List mats = new ArrayList(m.rows()); + Mat_to_vector_Mat(m, mats); + for (Mat mi : mats) { + MatOfKeyPoint vkp = new MatOfKeyPoint(mi); + kps.add(vkp); + } + } + + public static Mat vector_double_to_Mat(List ds) { + Mat res; + int count = (ds != null) ? ds.size() : 0; + if (count > 0) { + res = new Mat(count, 1, CvType.CV_64FC1); + double[] buff = new double[count]; + for (int i = 0; i < count; i++) { + double v = ds.get(i); + buff[i] = v; + } + res.put(0, 0, buff); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_double(Mat m, List ds) { + if (ds == null) + throw new java.lang.IllegalArgumentException("ds == null"); + int count = m.rows(); + if (CvType.CV_64FC1 != m.type() || m.cols() != 1) + throw new java.lang.IllegalArgumentException( + "CvType.CV_64FC1 != m.type() || m.cols()!=1\n" + m); + + ds.clear(); + double[] buff = new double[count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + ds.add(buff[i]); + } + } + + public static Mat vector_DMatch_to_Mat(List matches) { + Mat res; + int count = (matches != null) ? matches.size() : 0; + if (count > 0) { + res = new Mat(count, 1, CvType.CV_64FC4); + double[] buff = new double[count * 4]; + for (int i = 0; i < count; i++) { + DMatch m = matches.get(i); + buff[4 * i] = m.queryIdx; + buff[4 * i + 1] = m.trainIdx; + buff[4 * i + 2] = m.imgIdx; + buff[4 * i + 3] = m.distance; + } + res.put(0, 0, buff); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_DMatch(Mat m, List matches) { + if (matches == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + int count = m.rows(); + if (CvType.CV_64FC4 != m.type() || m.cols() != 1) + throw new java.lang.IllegalArgumentException( + "CvType.CV_64FC4 != m.type() || m.cols()!=1\n" + m); + + matches.clear(); + double[] buff = new double[4 * count]; + m.get(0, 0, buff); + for (int i = 0; i < count; i++) { + matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3])); + } + } + + // vector_vector_DMatch + public static Mat vector_vector_DMatch_to_Mat(List lvdm, List mats) { + Mat res; + int lCount = (lvdm != null) ? lvdm.size() : 0; + if (lCount > 0) { + for (MatOfDMatch vdm : lvdm) + mats.add(vdm); + res = vector_Mat_to_Mat(mats); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_vector_DMatch(Mat m, List lvdm) { + if (lvdm == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + + if (m == null) + throw new java.lang.IllegalArgumentException("Input Mat can't be null"); + + List mats = new ArrayList(m.rows()); + Mat_to_vector_Mat(m, mats); + lvdm.clear(); + for (Mat mi : mats) { + MatOfDMatch vdm = new MatOfDMatch(mi); + lvdm.add(vdm); + } + } + + // vector_vector_char + public static Mat vector_vector_char_to_Mat(List lvb, List mats) { + Mat res; + int lCount = (lvb != null) ? lvb.size() : 0; + if (lCount > 0) { + for (MatOfByte vb : lvb) + mats.add(vb); + res = vector_Mat_to_Mat(mats); + } else { + res = new Mat(); + } + return res; + } + + public static void Mat_to_vector_vector_char(Mat m, List> llb) { + if (llb == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + + if (m == null) + throw new java.lang.IllegalArgumentException("Input Mat can't be null"); + + List mats = new ArrayList(m.rows()); + Mat_to_vector_Mat(m, mats); + for (Mat mi : mats) { + List lb = new ArrayList(); + Mat_to_vector_char(mi, lb); + llb.add(lb); + } + } + + + static { + System.loadLibrary("opencv_java"); + } + +}