Commit 3159bd1a authored by Andrey Pavlenko's avatar Andrey Pavlenko

#863: 'string' args support added

parent 6c8a2b88
This diff is collapsed.
...@@ -292,7 +292,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nClone ...@@ -292,7 +292,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nClone
} }
// unlike other nPut()-s this one (with double[]) should convert input values to correct type // 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)) #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 JNIEXPORT jint JNICALL Java_org_opencv_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)
{ {
...@@ -306,7 +306,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutD ...@@ -306,7 +306,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutD
double* values = (double*)env->GetPrimitiveArrayCritical(vals, 0); double* values = (double*)env->GetPrimitiveArrayCritical(vals, 0);
double* src = values; double* src = values;
int r, c; int r, c;
for(c=col; c<me->cols & count>0; c++) for(c=col; c<me->cols && count>0; c++)
{ {
switch(me->depth()) { switch(me->depth()) {
case CV_8U: PUT_ITEM(uchar, row, c); break; case CV_8U: PUT_ITEM(uchar, row, c); break;
...@@ -320,8 +320,8 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutD ...@@ -320,8 +320,8 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutD
src++; src++;
} }
for(r=row+1; r<me->rows & count>0; r++) for(r=row+1; r<me->rows && count>0; r++)
for(c=0; c<me->cols & count>0; c++) for(c=0; c<me->cols && count>0; c++)
{ {
switch(me->depth()) { switch(me->depth()) {
case CV_8U: PUT_ITEM(uchar, r, c); break; case CV_8U: PUT_ITEM(uchar, r, c); break;
...@@ -475,7 +475,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetS ...@@ -475,7 +475,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetS
{ {
cv::Mat* me = (cv::Mat*) self; cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type 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 if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0); char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
...@@ -489,7 +489,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetI ...@@ -489,7 +489,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetI
{ {
cv::Mat* me = (cv::Mat*) self; cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type if(me->depth() != CV_32S) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0); char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
...@@ -503,7 +503,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetF ...@@ -503,7 +503,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetF
{ {
cv::Mat* me = (cv::Mat*) self; cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type if(me->depth() != CV_32F) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0); char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
...@@ -517,7 +517,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetD ...@@ -517,7 +517,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetD
{ {
cv::Mat* me = (cv::Mat*) self; cv::Mat* me = (cv::Mat*) self;
if(! self) return 0; // no native object behind if(! self) return 0; // no native object behind
if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type if(me->depth() != CV_64F) return 0; // incompatible type
if(me->rows<=row || me->cols<=col) return 0; // indexes out of range if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0); char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
...@@ -526,12 +526,36 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetD ...@@ -526,12 +526,36 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetD
return res; return res;
} }
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_Mat_nGet
(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
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_Mat_nSetTo JNIEXPORT void JNICALL Java_org_opencv_Mat_nSetTo
(JNIEnv* env, jclass cls, jlong self, jdouble v0, jdouble v1, jdouble v2, jdouble v3) (JNIEnv* env, jclass cls, jlong self, jdouble v0, jdouble v1, jdouble v2, jdouble v3)
{ {
cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
me->setTo( cv::Scalar(v0, v1, v2, v3), cv::Mat() ); me->setTo( cv::Scalar(v0, v1, v2, v3) );
} }
JNIEXPORT void JNICALL Java_org_opencv_Mat_nCopyTo JNIEXPORT void JNICALL Java_org_opencv_Mat_nCopyTo
......
...@@ -339,6 +339,15 @@ public class Mat { ...@@ -339,6 +339,15 @@ public class Mat {
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
} }
public double[] get(int row, int col) {
checkNull();
//CvType t = type();
//if(t.depth() == CvType.CV_64F) {
return nGet(nativeObj, row, col);
//}
//throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
public void setTo(double v0, double v1, double v2, double v3) { public void setTo(double v0, double v1, double v2, double v3) {
checkNull(); checkNull();
...@@ -399,6 +408,7 @@ public class Mat { ...@@ -399,6 +408,7 @@ public class Mat {
private static native int nGetI(long self, int row, int col, int count, int[] 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 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 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 void nSetTo(long self, double v0, double v1, double v2, double v3); 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 void nCopyTo(long self, long mat);
private static native double nDot(long self, long mat); private static native double nDot(long self, long mat);
......
...@@ -10,6 +10,8 @@ import android.view.SurfaceHolder; ...@@ -10,6 +10,8 @@ import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import org.opencv.Mat; import org.opencv.Mat;
import org.opencv.Point;
import org.opencv.Scalar;
import org.opencv.Size; import org.opencv.Size;
import org.opencv.core; import org.opencv.core;
import org.opencv.imgproc; import org.opencv.imgproc;
...@@ -142,6 +144,7 @@ class Sample1View extends SurfaceView implements SurfaceHolder.Callback, Runnabl ...@@ -142,6 +144,7 @@ class Sample1View extends SurfaceView implements SurfaceHolder.Callback, Runnabl
break; break;
case Sample1Java.VIEW_MODE_RGBA: case Sample1Java.VIEW_MODE_RGBA:
imgproc.cvtColor(mYuv, mRgba, imgproc.CV_YUV420i2RGB, 4); imgproc.cvtColor(mYuv, mRgba, imgproc.CV_YUV420i2RGB, 4);
core.putText(mRgba, "OpenCV + Android", new Point(10,100), 3/*CV_FONT_HERSHEY_COMPLEX*/, 2, new Scalar(0, 255,0, 255), 3);
break; break;
case Sample1Java.VIEW_MODE_CANNY: case Sample1Java.VIEW_MODE_CANNY:
imgproc.Canny(mGraySubmat, mIntermediateMat, 80, 100); imgproc.Canny(mGraySubmat, mIntermediateMat, 80, 100);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment