Java: fixed Mats comparison; added resahpe mathod to core.Mat; fixed test resources extraction.
This commit is contained in:
@@ -13,42 +13,42 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nType
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(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_core_Mat_nRows
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(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_core_Mat_nCols
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(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_core_Mat_nData
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(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_core_Mat_nIsEmpty
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
{
|
||||
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
|
||||
return me->empty();
|
||||
}
|
||||
|
||||
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nSize
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
@@ -58,8 +58,8 @@ JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nSize
|
||||
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_);
|
||||
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
|
||||
@@ -80,32 +80,32 @@ JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nSize
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_nIsCont
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(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_core_Mat_nIsSubmat
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(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_core_Mat_nSubmat
|
||||
(JNIEnv* env, jclass cls, jlong self, jint r1, jint r2, jint c1, jint c2)
|
||||
(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_core_Mat_nClone
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(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);
|
||||
me->copyTo(*it);
|
||||
return (jlong) it;
|
||||
}
|
||||
|
||||
@@ -113,47 +113,47 @@ JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_nClone
|
||||
#define PUT_ITEM(T, R, C) { T*dst = (T*)me->ptr(R, C); for(int ch=0; ch<me->channels() && count>0; count--,ch++,src++,dst++) *dst = cv::saturate_cast<T>(*src); }
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jdoubleArray vals)
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jdoubleArray vals)
|
||||
{
|
||||
cv::Mat* me = (cv::Mat*) self;
|
||||
if(!me || !me->data) return 0; // no native object behind
|
||||
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
|
||||
cv::Mat* me = (cv::Mat*) self;
|
||||
if(!me || !me->data) 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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
env->ReleasePrimitiveArrayCritical(vals, values, 0);
|
||||
return res;
|
||||
env->ReleasePrimitiveArrayCritical(vals, values, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -163,32 +163,32 @@ JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
|
||||
|
||||
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;
|
||||
if(! m) return 0;
|
||||
if(! buff) return 0;
|
||||
|
||||
count *= sizeof(T);
|
||||
int rest = ((m->rows - row) * m->cols - col) * m->channels() * sizeof(T);
|
||||
if(count>rest) count = rest;
|
||||
int res = count;
|
||||
count *= sizeof(T);
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,59 +197,59 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutB
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jbyteArray vals)
|
||||
(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;
|
||||
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_core_Mat_nPutS
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jshortArray vals)
|
||||
(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_16U && me->depth() != CV_16S) 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;
|
||||
cv::Mat* me = (cv::Mat*) self;
|
||||
if(! self) return 0; // no native object behind
|
||||
if(me->depth() != CV_16U && me->depth() != CV_16S) 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_core_Mat_nPutI
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jintArray vals)
|
||||
(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_32S) 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;
|
||||
cv::Mat* me = (cv::Mat*) self;
|
||||
if(! self) return 0; // no native object behind
|
||||
if(me->depth() != CV_32S) 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_core_Mat_nPutF
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jfloatArray vals)
|
||||
(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_32F) 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;
|
||||
cv::Mat* me = (cv::Mat*) self;
|
||||
if(! self) return 0; // no native object behind
|
||||
if(me->depth() != CV_32F) 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -260,32 +260,32 @@ JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutF
|
||||
|
||||
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;
|
||||
if(! m) return 0;
|
||||
if(! buff) return 0;
|
||||
|
||||
count *= sizeof(T);
|
||||
int rest = ((m->rows - row) * m->cols - col) * m->channels() * sizeof(T);
|
||||
if(count>rest) count = rest;
|
||||
int res = count;
|
||||
count *= sizeof(T);
|
||||
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){//TODO: recheck this cycle for the case col!=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;
|
||||
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){//TODO: recheck this cycle for the case col!=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;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -294,98 +294,98 @@ extern "C" {
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetB
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jbyteArray vals)
|
||||
(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;
|
||||
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_core_Mat_nGetS
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jshortArray vals)
|
||||
(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_16U && me->depth() != CV_16S) 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;
|
||||
cv::Mat* me = (cv::Mat*) self;
|
||||
if(! self) return 0; // no native object behind
|
||||
if(me->depth() != CV_16U && me->depth() != CV_16S) 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_core_Mat_nGetI
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jintArray vals)
|
||||
(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_32S) 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;
|
||||
cv::Mat* me = (cv::Mat*) self;
|
||||
if(! self) return 0; // no native object behind
|
||||
if(me->depth() != CV_32S) 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_core_Mat_nGetF
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jfloatArray vals)
|
||||
(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_32F) 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;
|
||||
cv::Mat* me = (cv::Mat*) self;
|
||||
if(! self) return 0; // no native object behind
|
||||
if(me->depth() != CV_32F) 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_core_Mat_nGetD
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jdoubleArray vals)
|
||||
(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_64F) 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;
|
||||
cv::Mat* me = (cv::Mat*) self;
|
||||
if(! self) return 0; // no native object behind
|
||||
if(me->depth() != CV_64F) 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 jdoubleArray JNICALL Java_org_opencv_core_Mat_nGet
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count)
|
||||
(JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count)
|
||||
{
|
||||
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
|
||||
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
|
||||
|
||||
jdoubleArray res = env->NewDoubleArray(me->channels());
|
||||
if(res){
|
||||
jdouble buff[me->channels()];
|
||||
int i;
|
||||
switch(me->depth()){
|
||||
case CV_8U: for(i=0; i<me->channels(); i++) buff[i] = *((unsigned char*) me->ptr(row, col) + i); break;
|
||||
case CV_8S: for(i=0; i<me->channels(); i++) buff[i] = *((signed char*) me->ptr(row, col) + i); break;
|
||||
case CV_16U: for(i=0; i<me->channels(); i++) buff[i] = *((unsigned short*)me->ptr(row, col) + i); break;
|
||||
case CV_16S: for(i=0; i<me->channels(); i++) buff[i] = *((signed short*) me->ptr(row, col) + i); break;
|
||||
case CV_32S: for(i=0; i<me->channels(); i++) buff[i] = *((int*) me->ptr(row, col) + i); break;
|
||||
case CV_32F: for(i=0; i<me->channels(); i++) buff[i] = *((float*) me->ptr(row, col) + i); break;
|
||||
case CV_64F: for(i=0; i<me->channels(); i++) buff[i] = *((double*) me->ptr(row, col) + i); break;
|
||||
}
|
||||
env->SetDoubleArrayRegion(res, 0, me->channels(), buff);
|
||||
}
|
||||
return res;
|
||||
jdoubleArray res = env->NewDoubleArray(me->channels());
|
||||
if(res){
|
||||
jdouble buff[me->channels()];
|
||||
int i;
|
||||
switch(me->depth()){
|
||||
case CV_8U: for(i=0; i<me->channels(); i++) buff[i] = *((unsigned char*) me->ptr(row, col) + i); break;
|
||||
case CV_8S: for(i=0; i<me->channels(); i++) buff[i] = *((signed char*) me->ptr(row, col) + i); break;
|
||||
case CV_16U: for(i=0; i<me->channels(); i++) buff[i] = *((unsigned short*)me->ptr(row, col) + i); break;
|
||||
case CV_16S: for(i=0; i<me->channels(); i++) buff[i] = *((signed short*) me->ptr(row, col) + i); break;
|
||||
case CV_32S: for(i=0; i<me->channels(); i++) buff[i] = *((int*) me->ptr(row, col) + i); break;
|
||||
case CV_32F: for(i=0; i<me->channels(); i++) buff[i] = *((float*) me->ptr(row, col) + i); break;
|
||||
case CV_64F: for(i=0; i<me->channels(); i++) buff[i] = *((double*) me->ptr(row, col) + i); break;
|
||||
}
|
||||
env->SetDoubleArrayRegion(res, 0, me->channels(), buff);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_nSetTo
|
||||
@@ -412,7 +412,7 @@ JNIEXPORT jdouble JNICALL Java_org_opencv_core_Mat_nDot
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_nCross
|
||||
(JNIEnv* env, jclass cls, jlong self, jlong m)
|
||||
(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
|
||||
@@ -420,10 +420,17 @@ JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_nCross
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_nInv
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
(JNIEnv* env, jclass cls, jlong self)
|
||||
{
|
||||
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
|
||||
return (jlong) new cv::Mat(me->inv());
|
||||
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
|
||||
return (jlong) new cv::Mat(me->inv());
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_nReshape
|
||||
(JNIEnv* env, jclass cls, jlong self, jint cn, jint rows)
|
||||
{
|
||||
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
|
||||
return (jlong) new cv::Mat(me->reshape(cn, rows));
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_nCreateMat__
|
||||
@@ -441,10 +448,10 @@ JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_nEye
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump
|
||||
(JNIEnv *env, jclass cls, jlong self)
|
||||
{
|
||||
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
|
||||
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
|
||||
std::stringstream s;
|
||||
s << *me;
|
||||
return env->NewStringUTF(s.str().c_str());
|
||||
return env->NewStringUTF(s.str().c_str());
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_nCreateMat__III
|
||||
|
@@ -275,6 +275,16 @@ public class Mat {
|
||||
public Mat inv() {
|
||||
return new Mat( nInv(nativeObj) );
|
||||
}
|
||||
|
||||
//javadoc:Mat::reshape(cn)
|
||||
public Mat reshape(int cn) {
|
||||
return new Mat( nReshape(nativeObj, cn, 0) );
|
||||
}
|
||||
|
||||
//javadoc:Mat::reshape(cn, rows)
|
||||
public Mat reshape(int cn, int rows) {
|
||||
return new Mat( nReshape(nativeObj, cn, rows) );
|
||||
}
|
||||
|
||||
//javadoc:Mat::getNativeObjAddr()
|
||||
public long getNativeObjAddr() {
|
||||
@@ -315,6 +325,7 @@ public class 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);
|
||||
private static native long nReshape(long self, int cn, int rows);
|
||||
private static native long nEye(int rows, int cols, int type);
|
||||
private static native String nDump(long self);
|
||||
|
||||
|
Reference in New Issue
Block a user