Updated build scripts for better Java module support

This commit is contained in:
Andrey Kamaev
2011-06-24 07:48:04 +00:00
parent 2ee4f0de31
commit 69b79f89c1
12 changed files with 41 additions and 13 deletions

View File

@@ -0,0 +1,583 @@
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_opencv_Mat
* Method: nCreateMat
* Signature: (III)J
*/
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCreateMat__III
(JNIEnv *, jclass, jint, jint, jint);
/*
* Class: org_opencv_Mat
* Method: nCreateMat
* Signature: (IIIDDDD)J
*/
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCreateMat__IIIDDDD
(JNIEnv *, jclass, jint, jint, jint, jdouble, jdouble, jdouble, jdouble);
/*
* Class: org_opencv_Mat
* Method: nDispose
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_opencv_Mat_nDispose
(JNIEnv *, jclass, jlong);
/*
* Class: org_opencv_Mat
* Method: nType
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nType
(JNIEnv *, jclass, jlong);
/*
* Class: org_opencv_Mat
* Method: nRows
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nRows
(JNIEnv *, jclass, jlong);
/*
* Class: org_opencv_Mat
* Method: nCols
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nCols
(JNIEnv *, jclass, jlong);
/*
* Class: org_opencv_Mat
* Method: nData
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nData
(JNIEnv *, jclass, jlong);
/*
* Class: org_opencv_Mat
* Method: nIsEmpty
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_org_opencv_Mat_nIsEmpty
(JNIEnv *, jclass, jlong);
/*
* Class: org_opencv_Mat
* Method: nIsCont
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_org_opencv_Mat_nIsCont
(JNIEnv *, jclass, jlong);
/*
* Class: org_opencv_Mat
* Method: nIsSubmat
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_org_opencv_Mat_nIsSubmat
(JNIEnv *, jclass, jlong);
/*
* Class: org_opencv_Mat
* Method: nSubmat
* Signature: (JIIII)J
*/
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nSubmat
(JNIEnv *, jclass, jlong, jint, jint, jint, jint);
/*
* Class: org_opencv_Mat
* Method: nClone
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nClone
(JNIEnv *, jclass, jlong);
/*
* Class: org_opencv_Mat
* Method: nPutD
* Signature: (JIII[D)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutD
(JNIEnv *, jclass, jlong, jint, jint, jint, jdoubleArray);
/*
* Class: org_opencv_Mat
* Method: nPutF
* Signature: (JIII[F)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutF
(JNIEnv *, jclass, jlong, jint, jint, jint, jfloatArray);
/*
* Class: org_opencv_Mat
* Method: nPutI
* Signature: (JIII[I)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutI
(JNIEnv *, jclass, jlong, jint, jint, jint, jintArray);
/*
* Class: org_opencv_Mat
* Method: nPutS
* Signature: (JIII[S)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutS
(JNIEnv *, jclass, jlong, jint, jint, jint, jshortArray);
/*
* Class: org_opencv_Mat
* Method: nPutB
* Signature: (JIII[B)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutB
(JNIEnv *, jclass, jlong, jint, jint, jint, jbyteArray);
/*
* Class: org_opencv_Mat
* Method: nGetB
* Signature: (JIII[B)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetB
(JNIEnv *, jclass, jlong, jint, jint, jint, jbyteArray);
/*
* Class: org_opencv_Mat
* Method: nGetS
* Signature: (JIII[S)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetS
(JNIEnv *, jclass, jlong, jint, jint, jint, jshortArray);
/*
* Class: org_opencv_Mat
* Method: nGetI
* Signature: (JIII[I)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetI
(JNIEnv *, jclass, jlong, jint, jint, jint, jintArray);
/*
* Class: org_opencv_Mat
* Method: nGetF
* Signature: (JIII[F)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetF
(JNIEnv *, jclass, jlong, jint, jint, jint, jfloatArray);
/*
* Class: org_opencv_Mat
* Method: nGetD
* Signature: (JIII[D)I
*/
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetD
(JNIEnv *, jclass, jlong, jint, jint, jint, jdoubleArray);
/*
* Class: org_opencv_Mat
* Method: nSetTo
* Signature: (JDDDD)V
*/
JNIEXPORT void JNICALL Java_org_opencv_Mat_nSetTo
(JNIEnv *, jclass, jlong, jdouble, jdouble, jdouble, jdouble);
/*
* Class: org_opencv_Mat
* Method: nCopyTo
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_org_opencv_Mat_nCopyTo
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: org_opencv_Mat
* Method: nDot
* Signature: (JJ)D
*/
JNIEXPORT jdouble JNICALL Java_org_opencv_Mat_nDot
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: org_opencv_Mat
* Method: nCross
* Signature: (JJ)J
*/
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCross
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: org_opencv_Mat
* Method: nInv
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nInv
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#endif
#include "opencv2/core/core.hpp"
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nType
(JNIEnv* env, jclass cls, jlong self)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
return me->type( );
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nRows
(JNIEnv* env, jclass cls, jlong self)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
return me->rows;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nCols
(JNIEnv* env, jclass cls, jlong self)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
return me->cols;
}
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nData
(JNIEnv* env, jclass cls, jlong self)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
return (jlong) me->data;
}
JNIEXPORT jboolean JNICALL Java_org_opencv_Mat_nIsEmpty
(JNIEnv* env, jclass cls, jlong self)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
return me->empty();
}
JNIEXPORT jboolean JNICALL Java_org_opencv_Mat_nIsCont
(JNIEnv* env, jclass cls, jlong self)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
return me->isContinuous();
}
JNIEXPORT jboolean JNICALL Java_org_opencv_Mat_nIsSubmat
(JNIEnv* env, jclass cls, jlong self)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
return me->isSubmatrix();
}
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nSubmat
(JNIEnv* env, jclass cls, jlong self, jint r1, jint r2, jint c1, jint c2)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
return (jlong) new cv::Mat(*me, cv::Range(r1, r2>0 ? r2 : me->rows), cv::Range(c1, c2>0 ? c2 : me->cols));
}
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nClone
(JNIEnv* env, jclass cls, jlong self)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
cv::Mat* it = new cv::Mat();
me->copyTo(*it);
return (jlong) it;
}
// unlike other nPut()-s this one (with double[]) should convert input values to correct type
#define PUT_ITEM(T, R, C) for(int ch=0; ch<me->channels() & count>0; ch++,count--) *((T*)me->ptr(R, C)+ch) = cv::saturate_cast<T>(*(src+ch))
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutD
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jdoubleArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
int rest = ((me->rows - row) * me->cols - col) * me->channels();
if(count>rest) count = rest;
int res = count;
double* values = (double*)env->GetPrimitiveArrayCritical(vals, 0);
double* src = values;
int r, c;
for(c=col; c<me->cols & count>0; c++)
{
switch(me->depth()) {
case CV_8U: PUT_ITEM(uchar, row, c); break;
case CV_8S: PUT_ITEM(schar, row, c); break;
case CV_16U: PUT_ITEM(ushort, row, c); break;
case CV_16S: PUT_ITEM(short, row, c); break;
case CV_32S: PUT_ITEM(int, row, c); break;
case CV_32F: PUT_ITEM(float, row, c); break;
case CV_64F: PUT_ITEM(double, row, c); break;
}
src++;
}
for(r=row+1; r<me->rows & count>0; r++)
for(c=0; c<me->cols & count>0; c++)
{
switch(me->depth()) {
case CV_8U: PUT_ITEM(uchar, r, c); break;
case CV_8S: PUT_ITEM(schar, r, c); break;
case CV_16U: PUT_ITEM(ushort, r, c); break;
case CV_16S: PUT_ITEM(short, r, c); break;
case CV_32S: PUT_ITEM(int, r, c); break;
case CV_32F: PUT_ITEM(float, r, c); break;
case CV_64F: PUT_ITEM(double, r, c); break;
}
src++;
}
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
template<typename T> static int mat_put(cv::Mat* m, int row, int col, int count, char* buff)
{
if(! m) return 0;
if(! buff) return 0;
int rest = ((m->rows - row) * m->cols - col) * m->channels() * sizeof(T);
if(count>rest) count = rest;
int res = count;
if( m->isContinuous() )
{
memcpy(m->ptr(row, col), buff, count);
} else {
// row by row
int num = (m->cols - col - 1) * m->channels() * sizeof(T); // 1st partial row
if(count<num) num = count;
uchar* data = m->ptr(row++, col);
while(count>0){
memcpy(data, buff, num);
count -= num;
buff += num;
num = m->cols * m->channels() * sizeof(T);
if(count<num) num = count;
data = m->ptr(row++, 0);
}
}
return res;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutB
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jbyteArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
int res = mat_put<char>(me, row, col, count, values);
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutS
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jshortArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
int res = mat_put<short>(me, row, col, count, values);
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutI
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jintArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
int res = mat_put<int>(me, row, col, count, values);
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutF
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jfloatArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
int res = mat_put<float>(me, row, col, count, values);
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
template<typename T> int mat_get(cv::Mat* m, int row, int col, int count, char* buff)
{
if(! m) return 0;
if(! buff) return 0;
int rest = ((m->rows - row) * m->cols - col) * m->channels() * sizeof(T);
if(count>rest) count = rest;
int res = count;
if( m->isContinuous() )
{
memcpy(buff, m->ptr(row, col), count);
} else {
// row by row
int num = (m->cols - col - 1) * m->channels() * sizeof(T); // 1st partial row
if(count<num) num = count;
uchar* data = m->ptr(row++, col);
while(count>0){
memcpy(buff, data, num);
count -= num;
buff += num;
num = m->cols * m->channels() * sizeof(T);
if(count<num) num = count;
data = m->ptr(row++, 0);
}
}
return res;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetB
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jbyteArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
int res = mat_get<char>(me, row, col, count, values);
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetS
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jshortArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
int res = mat_get<short>(me, row, col, count, values);
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetI
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jintArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
int res = mat_get<int>(me, row, col, count, values);
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetF
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jfloatArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
int res = mat_get<float>(me, row, col, count, values);
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetD
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jdoubleArray vals)
{
cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
int res = mat_get<double>(me, row, col, count, values);
env->ReleasePrimitiveArrayCritical(vals, values, 0);
return res;
}
JNIEXPORT void JNICALL Java_org_opencv_Mat_nSetTo
(JNIEnv* env, jclass cls, jlong self, jdouble v0, jdouble v1, jdouble v2, jdouble v3)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
me->setTo( cv::Scalar(v0, v1, v2, v3), cv::Mat() );
}
JNIEXPORT void JNICALL Java_org_opencv_Mat_nCopyTo
(JNIEnv* env, jclass cls, jlong self, jlong m)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
cv::Mat* _m = (cv::Mat*) m; //TODO: check for NULL
me->copyTo( *_m );
}
JNIEXPORT jdouble JNICALL Java_org_opencv_Mat_nDot
(JNIEnv* env, jclass cls, jlong self, jlong m)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
cv::Mat* _m = (cv::Mat*) m; //TODO: check for NULL
return me->dot( *_m );
}
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCross
(JNIEnv* env, jclass cls, jlong self, jlong it)
{
return 0; //NYI
}
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nInv
(JNIEnv* env, jclass cls, jlong self)
{
return 0; //NYI
}
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCreateMat__III
(JNIEnv* env, jclass cls, jint _rows, jint _cols, jint _type)
{
return (jlong) new cv::Mat( _rows, _cols, _type );
}
JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCreateMat__IIIDDDD
(JNIEnv* env, jclass cls, jint _rows, jint _cols, jint _type, jdouble v0, jdouble v1, jdouble v2, jdouble v3)
{
return (jlong) new cv::Mat( _rows, _cols, _type, cv::Scalar(v0, v1, v2, v3) );
}
JNIEXPORT void JNICALL Java_org_opencv_Mat_nDispose
(JNIEnv* env, jclass cls, jlong self)
{
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
delete me;
}

View File

@@ -0,0 +1,81 @@
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_opencv_utils
* Method: nBitmapToMat(Bitmap b)
* Signature: (L)J
*/
JNIEXPORT jlong JNICALL Java_org_opencv_utils_nBitmapToMat
(JNIEnv *, jclass, jobject);
/*
* Class: org_opencv_utils
* Method: nBitmapToMat(long m, Bitmap b)
* Signature: (JL)Z
*/
JNIEXPORT jboolean JNICALL Java_org_opencv_utils_nMatToBitmap
(JNIEnv *, jclass, jlong, jobject);
#ifdef __cplusplus
}
#endif
#include "opencv2/core/core.hpp"
#include <android/bitmap.h>
JNIEXPORT jlong JNICALL Java_org_opencv_utils_nBitmapToMat
(JNIEnv * env, jclass cls, jobject bitmap)
{
AndroidBitmapInfo info;
void* pixels;
cv::Mat* m = NULL;
if ( AndroidBitmap_getInfo(env, bitmap, &info) < 0 )
return 0; // can't get info
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
return 0; // incompatible format
if ( AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0 )
return 0; // can't get pixels
m = new cv::Mat(info.height, info.width, CV_8UC4);
memcpy(m->data, pixels, info.height * info.width * 4);
AndroidBitmap_unlockPixels(env, bitmap);
return (jlong)m;
}
JNIEXPORT jboolean JNICALL Java_org_opencv_utils_nMatToBitmap
(JNIEnv * env, jclass cls, jlong m, jobject bitmap)
{
AndroidBitmapInfo info;
void* pixels;
cv::Mat* mat = (cv::Mat*) m;
if ( m == 0 )
return false; // no native Mat behind
if ( AndroidBitmap_getInfo(env, bitmap, &info) < 0 )
return false; // can't get info
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
return false; // incompatible format
if ( AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0 )
return false; // can't get pixels
memcpy(pixels, mat->data, info.height * info.width * 4);
AndroidBitmap_unlockPixels(env, bitmap);
return true;
}

View File

@@ -0,0 +1,408 @@
package org.opencv;
public class Mat {
public static class CvType {
// predefined type constants
public static final CvType
CV_8UC1 = CV_8UC(1), CV_8UC2 = CV_8UC(2), CV_8UC3 = CV_8UC(3), CV_8UC4 = CV_8UC(4),
CV_8SC1 = CV_8SC(1), CV_8SC2 = CV_8SC(2), CV_8SC3 = CV_8SC(3), CV_8SC4 = CV_8SC(4),
CV_16UC1 = CV_16UC(1), CV_16UC2 = CV_16UC(2), CV_16UC3 = CV_16UC(3), CV_16UC4 = CV_16UC(4),
CV_16SC1 = CV_16SC(1), CV_16SC2 = CV_16SC(2), CV_16SC3 = CV_16SC(3), CV_16SC4 = CV_16SC(4),
CV_32SC1 = CV_32SC(1), CV_32SC2 = CV_32SC(2), CV_32SC3 = CV_32SC(3), CV_32SC4 = CV_32SC(4),
CV_32FC1 = CV_32FC(1), CV_32FC2 = CV_32FC(2), CV_32FC3 = CV_32FC(3), CV_32FC4 = CV_32FC(4),
CV_64FC1 = CV_64FC(1), CV_64FC2 = CV_64FC(2), CV_64FC3 = CV_64FC(3), CV_64FC4 = CV_64FC(4);
// type depth constants
public static final int CV_8U = 0,
CV_8S = 1,
CV_16U = 2,
CV_16S = 3,
CV_32S = 4,
CV_32F = 5,
CV_64F = 6,
CV_USRTYPE1=7;
private static final int CV_CN_MAX = 512, CV_CN_SHIFT = 3, CV_DEPTH_MAX = (1 << CV_CN_SHIFT);
private final int value;
protected CvType(int depth, int channels) {
if(channels<=0 || channels>=CV_CN_MAX) {
throw new java.lang.UnsupportedOperationException(
"Channels count should be 1.." + (CV_CN_MAX-1) );
}
if(depth<0 || depth>=CV_DEPTH_MAX) {
throw new java.lang.UnsupportedOperationException(
"Data type depth should be 0.." + (CV_DEPTH_MAX-1) );
}
value = (depth & (CV_DEPTH_MAX-1)) + ((channels-1) << CV_CN_SHIFT);
}
protected CvType(int val) { value = val; }
public static final CvType CV_8UC(int ch) { return new CvType(CV_8U, ch); }
public static final CvType CV_8SC(int ch) { return new CvType(CV_8S, ch); }
public static final CvType CV_16UC(int ch) { return new CvType(CV_16U, ch); }
public static final CvType CV_16SC(int ch) { return new CvType(CV_16S, ch); }
public static final CvType CV_32SC(int ch) { return new CvType(CV_32S, ch); }
public static final CvType CV_32FC(int ch) { return new CvType(CV_32F, ch); }
public static final CvType CV_64FC(int ch) { return new CvType(CV_64F, ch); }
public final int toInt() { return value; }
public final int channels() { return (value >> CV_CN_SHIFT) + 1; }
public final int depth() { return value & (CV_DEPTH_MAX-1); }
public final boolean isInteger() { return depth() < CV_32F; }
public final int CV_ELEM_SIZE() {
int depth = value & (CV_DEPTH_MAX-1);
switch (depth) {
case CV_8U:
case CV_8S:
return channels();
case CV_16U:
case CV_16S:
return 2 * channels();
case CV_32S:
case CV_32F:
return 4 * channels();
case CV_64F:
return 8 * channels();
default:
throw new java.lang.UnsupportedOperationException(
"Unsupported CvType value: " + value );
}
}
@Override
public final String toString() {
String s;
switch (depth()) {
case CV_8U:
s = "CV_8U";
break;
case CV_8S:
s = "CV_8S";
break;
case CV_16U:
s = "CV_16U";
break;
case CV_16S:
s = "CV_16S";
break;
case CV_32S:
s = "CV_32S";
break;
case CV_32F:
s = "CV_32F";
break;
case CV_64F:
s = "CV_64F";
break;
default:
s = "CV_USRTYPE1";
}
return s + "(" + channels() + ")";
}
// hashCode() has to be overridden if equals() is
@Override
public final int hashCode() { return value; }
@Override
public final boolean equals(Object obj) {
if (this == obj) return true;
if ( !(obj instanceof CvType) ) return false;
CvType other = (CvType) obj;
return value == other.value;
}
}
protected Mat(long nativeMat) {
/*if(nativeMat == 0)
throw new java.lang.UnsupportedOperationException("Native object address is NULL");*/
this.nativeObj = nativeMat;
}
public Mat(int rows, int cols, CvType type) {
this( nCreateMat(rows, cols, type.toInt()) );
}
public Mat(int rows, int cols, CvType type, double v0, double v1, double v2, double v3) {
this( nCreateMat(rows, cols, type.toInt(), v0, v1, v2, v3) );
}
public Mat(int rows, int cols, CvType type, double v0, double v1, double v2) {
this( nCreateMat(rows, cols, type.toInt(), v0, v1, v2, 0) );
}
public Mat(int rows, int cols, CvType type, double v0, double v1) {
this( nCreateMat(rows, cols, type.toInt(), v0, v1, 0, 0) );
}
public Mat(int rows, int cols, CvType type, double v0) {
this( nCreateMat(rows, cols, type.toInt(), v0, 0, 0, 0) );
}
public void dispose() {
if(nativeObj != 0)
nDispose(nativeObj);
nativeObj = 0;
}
@Override
protected void finalize() throws Throwable {
dispose();
super.finalize();
}
@Override
public String toString() {
if(nativeObj == 0) return "Mat [ nativeObj=NULL ]";
return "Mat [ " +
rows() + "*" + cols() + "*" + type() +
", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() +
", nativeObj=0x" + Long.toHexString(nativeObj) +
", dataAddr=0x" + Long.toHexString(dataAddr()) +
" ]";
}
public boolean empty() {
if(nativeObj == 0) return true;
return nIsEmpty(nativeObj);
}
private void checkNull() {
if(nativeObj == 0)
throw new java.lang.UnsupportedOperationException("Native object address is NULL");
}
public CvType type() {
checkNull();
return new CvType( nType(nativeObj) );
}
public int depth() { return type().depth(); }
public int channels() { return type().channels(); }
public int elemSize() { return type().CV_ELEM_SIZE(); }
public int rows() {
if(nativeObj == 0)
return 0;
return nRows(nativeObj);
}
public int height() { return rows(); }
public int cols() {
if(nativeObj == 0)
return 0;
return nCols(nativeObj);
}
public int width() { return cols(); }
public int total() { return rows() * cols(); }
public long dataAddr() {
if(nativeObj == 0)
return 0;
return nData(nativeObj);
}
public boolean isContinuous() {
if(nativeObj == 0)
return false; // maybe throw an exception instead?
return nIsCont(nativeObj);
}
public boolean isSubmatrix() {
if(nativeObj == 0)
return false; // maybe throw an exception instead?
return nIsSubmat(nativeObj);
}
public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) {
checkNull();
return new Mat( nSubmat(nativeObj, rowStart, rowEnd, colStart, colEnd) );
}
public Mat rowRange(int start, int end) { return submat(start, end, 0, -1); }
public Mat row(int num) { return submat(num, num+1, 0, -1); }
public Mat colRange(int start, int end) { return submat(0, -1, start, end); }
public Mat col(int num) { return submat(0, -1, num, num+1); }
public Mat clone() {
checkNull();
return new Mat( nClone(nativeObj) );
}
public int put(int row, int col, double...data) {
checkNull();
if(data != null)
return nPutD(nativeObj, row, col, data.length, data);
else
return 0;
}
public int put(int row, int col, float[] data) {
checkNull();
if(data != null) {
CvType t = type();
if(t.depth() == CvType.CV_32F) {
return nPutF(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
} else return 0;
}
public int put(int row, int col, int[] data) {
checkNull();
if(data != null) {
CvType t = type();
if(t.depth() == CvType.CV_32S) {
return nPutI(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
} else return 0;
}
public int put(int row, int col, short[] data) {
checkNull();
if(data != null) {
CvType t = type();
if(t.depth() == CvType.CV_16U || t.depth() == CvType.CV_16S) {
return nPutS(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
} else return 0;
}
public int put(int row, int col, byte[] data) {
checkNull();
if(data != null) {
CvType t = type();
if(t.depth() == CvType.CV_8U || t.depth() == CvType.CV_8S) {
return nPutB(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
} else return 0;
}
public int get(int row, int col, byte[] data) {
checkNull();
CvType t = type();
if(t.depth() == CvType.CV_8U || t.depth() == CvType.CV_8S) {
return nGetB(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
public int get(int row, int col, short[] data) {
checkNull();
CvType t = type();
if(t.depth() == CvType.CV_16U || t.depth() == CvType.CV_16S) {
return nGetS(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
public int get(int row, int col, int[] data) {
checkNull();
CvType t = type();
if(t.depth() == CvType.CV_32S) {
return nGetI(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
public int get(int row, int col, float[] data) {
checkNull();
CvType t = type();
if(t.depth() == CvType.CV_32F) {
return nGetF(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
public int get(int row, int col, double[] data) {
checkNull();
CvType t = type();
if(t.depth() == CvType.CV_64F) {
return nGetD(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
public void setTo(double v0, double v1, double v2, double v3) {
checkNull();
nSetTo(nativeObj, v0, v1, v2, v3);
}
public void setTo(double v0, double v1, double v2) { setTo(v0, v1, v2, 0); }
public void setTo(double v0, double v1) { setTo(v0, v1, 0, 0); }
public void setTo(double v0) { setTo(v0, 0, 0, 0); }
public void copyTo(Mat m) {
checkNull();
if(m.nativeObj == 0)
throw new java.lang.UnsupportedOperationException("Destination native object address is NULL");
nCopyTo(nativeObj, m.nativeObj);
}
public double dot(Mat m) {
checkNull();
return nDot(nativeObj, m.nativeObj);
}
public Mat cross(Mat m) {
checkNull();
return new Mat( nCross(nativeObj, m.nativeObj) );
}
public Mat inv() {
checkNull();
return new Mat( nInv(nativeObj) );
}
public long getNativeObjAddr() {
return nativeObj;
}
// native stuff
static { System.loadLibrary("opencv_java"); }
protected long nativeObj;
private static native long nCreateMat(int rows, int cols, int type);
private static native long nCreateMat(int rows, int cols, int type, double v0, double v1, double v2, double v3);
private static native void nDispose(long self);
private static native int nType(long self);
private static native int nRows(long self);
private static native int nCols(long self);
private static native long nData(long self);
private static native boolean nIsEmpty(long self);
private static native boolean nIsCont(long self);
private static native boolean nIsSubmat(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);
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 void nSetTo(long self, double v0, double v1, double v2, double v3);
private static native void nCopyTo(long self, long mat);
private static native double nDot(long self, long mat);
private static native long nCross(long self, long mat);
private static native long nInv(long self);
}

View File

@@ -0,0 +1,47 @@
package org.opencv;
public class Point {
public double x, y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public Point() {
this(0, 0);
}
public Point clone() {
return new Point(x, y);
}
public double dot(Point p) {
return x * p.x + y * p.y;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if ( ! (obj instanceof Point) ) return false;
Point it = (Point) obj;
return x == it.x && y == it.y;
}
public boolean inside(Rect r) {
return r.contains(this);
}
}

View File

@@ -0,0 +1,56 @@
package org.opencv;
public class Point3 {
public double x, y, z;
public Point3(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Point3() {
this(0, 0, 0);
}
public Point3(Point p) {
x = p.x;
y = p.y;
z = 0;
}
public Point3 clone() {
return new Point3(x, y, z);
}
public double dot(Point3 p) {
return x * p.x + y * p.y + z * p.z;
}
public Point3 cross(Point3 p) {
return new Point3(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(z);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Point3)) return false;
Point3 it = (Point3) obj;
return x == it.x && y == it.y && z == it.z;
}
}

View File

@@ -0,0 +1,76 @@
package org.opencv;
public class Rect {
int x, y, width, height;
public Rect(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public Rect() {
this(0, 0, 0, 0);
}
public Rect(Point p1, Point p2) {
x = (int) (p1.x < p2.x ? p1.x : p2.x);
y = (int) (p1.y < p2.y ? p1.y : p2.y);
width = (int) (p1.x > p2.x ? p1.x : p2.x) - x;
height = (int) (p1.y > p2.y ? p1.y : p2.y) - y;
}
public Rect(Point p, Size s) {
this((int)p.x, (int)p.y, s.width, s.height);
}
public Rect clone() {
return new Rect(x, y, width, height);
}
public Point tl() {
return new Point(x, y);
}
public Point br() {
return new Point(x + width, y + height);
}
public Size size() {
return new Size(width, height);
}
public double area() {
return width * height;
}
public boolean contains(Point p) {
return x <= p.x && p.x < x + width && y <= p.y && p.y < y + height;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(width);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Rect)) return false;
Rect it = (Rect) obj;
return x == it.x && y == it.y && width == it.width && height == it.height;
}
}

View File

@@ -0,0 +1,73 @@
package org.opencv;
public class Scalar {
public double v0, v1, v2, v3;
public Scalar(double v0, double v1, double v2, double v3) {
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
}
public Scalar(double v0, double v1, double v2) {
this(v0, v1, v2, 0);
}
public Scalar(double v0, double v1) {
this(v0, v1, 0, 0);
}
public Scalar(double v0) {
this(v0, 0, 0, 0);
}
public static Scalar all(double v) {
return new Scalar(v, v, v, v);
}
public Scalar clone() {
return new Scalar(v0, v1, v2, v3);
}
public Scalar mul(Scalar it, double scale) {
return new Scalar( v0 * it.v0 * scale, v1 * it.v1 * scale,
v2 * it.v2 * scale, v3 * it.v3 * scale );
}
public Scalar mul(Scalar it) {
return mul(it, 1);
}
public Scalar conj() {
return new Scalar(v0, -v1, -v2, -v3);
}
public boolean isReal() {
return v1 == 0 && v2 == 0 && v3 == 0;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(v0);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(v1);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(v2);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(v3);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Scalar)) return false;
Scalar it = (Scalar) obj;
return v0 == it.v0 && v1 == it.v1 && v2 == it.v2 && v3 == it.v3;
}
}

View File

@@ -0,0 +1,49 @@
package org.opencv;
public class Size {
public int width, height;
public Size(int width, int height) {
this.width = width;
this.height = height;
}
public Size() {
this(0, 0);
}
public Size(Point p) {
width = (int) p.x;
height = (int) p.y;
}
public double area() {
return width * height;
}
public Size clone() {
return new Size(width, height);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(width);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Size)) return false;
Size it = (Size) obj;
return width == it.width && height == it.height;
}
}

View File

@@ -0,0 +1,19 @@
package org.opencv;
import android.graphics.Bitmap;
public class utils {
public static Mat BitmapToMat(Bitmap b) {
return new Mat( nBitmapToMat(b) );
}
public static boolean MatToBitmap(Mat m, Bitmap b) {
return nMatToBitmap(m.nativeObj, b);
}
// native stuff
static { System.loadLibrary("opencv_java"); }
private static native long nBitmapToMat(Bitmap b);
private static native boolean nMatToBitmap(long m, Bitmap b);
}