Added image-manipulations android sample, other samples are updated; added Mat.size method to java API.

This commit is contained in:
Andrey Kamaev
2011-07-18 16:17:07 +00:00
parent 3119af1c72
commit 72541721a1
18 changed files with 463 additions and 58 deletions

View File

@@ -47,6 +47,38 @@ JNIEXPORT jboolean JNICALL Java_org_opencv_Mat_nIsEmpty
return me->empty();
}
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_Mat_nSize
(JNIEnv* env, jclass cls, jlong self)
{
try {
#ifdef DEBUG
LOGD("core::Mat::nSize()");
#endif // DEBUG
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
cv::Size _retval_ = me->size();
jdoubleArray _da_retval_ = env->NewDoubleArray(2);
jdouble _tmp_retval_[4] = {_retval_.width, _retval_.height};
env->SetDoubleArrayRegion(_da_retval_, 0, 2, _tmp_retval_);
return _da_retval_;
} catch(cv::Exception e) {
#ifdef DEBUG
LOGD("core::Mat::nSize() catched cv::Exception: %s", e.what());
#endif // DEBUG
jclass je = env->FindClass("org/opencv/CvException");
if(!je) je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, e.what());
return 0;
} catch (...) {
#ifdef DEBUG
LOGD("core::Mat::nSize() catched unknown exception (...)");
#endif // DEBUG
jclass je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, "Unknown exception in JNI code {core::n_1mean__JJ()}");
return 0;
}
}
JNIEXPORT jboolean JNICALL Java_org_opencv_Mat_nIsCont
(JNIEnv* env, jclass cls, jlong self)
{

View File

@@ -71,6 +71,12 @@ public class Mat {
return nIsEmpty(nativeObj);
}
//javadoc:Mat::size()
public Size Size() {
if(nativeObj == 0) return new Size();
return new Size(nSize(nativeObj));
}
private void checkNull() {
if(nativeObj == 0)
throw new java.lang.UnsupportedOperationException("Native object address is NULL");
@@ -334,6 +340,7 @@ public class Mat {
private static native boolean nIsEmpty(long self);
private static native boolean nIsCont(long self);
private static native boolean nIsSubmat(long self);
private static native double[] nSize(long self);
private static native long nSubmat(long self, int rowStart, int rowEnd, int colStart, int colEnd);
private static native long nClone(long self);
private static native int nPutD(long self, int row, int col, int count, double[] data);