Java API: (per code review) renaming and moving utility classes
Testing: 1079/0/584
This commit is contained in:
@@ -3,7 +3,7 @@ package org.opencv.test;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.opencv.Converters;
|
import org.opencv.utils.Converters;
|
||||||
import org.opencv.core.CvType;
|
import org.opencv.core.CvType;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.core.Point;
|
import org.opencv.core.Point;
|
||||||
|
@@ -5,7 +5,7 @@ import android.test.AndroidTestRunner;
|
|||||||
import android.test.InstrumentationTestRunner;
|
import android.test.InstrumentationTestRunner;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.opencv.Android;
|
import org.opencv.android.Utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -50,9 +50,9 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
context = getContext();
|
context = getContext();
|
||||||
LENA_PATH = Android.ExportResource(context, R.drawable.lena);
|
LENA_PATH = Utils.ExportResource(context, R.drawable.lena);
|
||||||
CHESS_PATH = Android.ExportResource(context, R.drawable.chessboard);
|
CHESS_PATH = Utils.ExportResource(context, R.drawable.chessboard);
|
||||||
LBPCASCADE_FRONTALFACE_PATH = Android.ExportResource(context, R.raw.lbpcascade_frontalface);
|
LBPCASCADE_FRONTALFACE_PATH = Utils.ExportResource(context, R.raw.lbpcascade_frontalface);
|
||||||
|
|
||||||
// List<TestCase> testCases = androidTestRunner.getTestCases();
|
// List<TestCase> testCases = androidTestRunner.getTestCases();
|
||||||
// Collections.shuffle(testCases); //shuffle the tests order
|
// Collections.shuffle(testCases); //shuffle the tests order
|
||||||
|
@@ -3,7 +3,7 @@ package org.opencv.test.core;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.opencv.Converters;
|
import org.opencv.utils.Converters;
|
||||||
import org.opencv.core.Core;
|
import org.opencv.core.Core;
|
||||||
import org.opencv.core.CvException;
|
import org.opencv.core.CvException;
|
||||||
import org.opencv.core.CvType;
|
import org.opencv.core.CvType;
|
||||||
|
@@ -811,7 +811,7 @@ extern "C" {
|
|||||||
if ctype.startswith('vector'):
|
if ctype.startswith('vector'):
|
||||||
imports.add("java.util.List")
|
imports.add("java.util.List")
|
||||||
imports.add("org.opencv.core.Mat")
|
imports.add("org.opencv.core.Mat")
|
||||||
imports.add("org.opencv.Converters")
|
imports.add("org.opencv.utils.Converters")
|
||||||
ctype = ctype.replace('vector_', '')
|
ctype = ctype.replace('vector_', '')
|
||||||
j_type = ''
|
j_type = ''
|
||||||
if ctype in type_dict:
|
if ctype in type_dict:
|
||||||
|
@@ -9,12 +9,12 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_opencv_Android
|
* Class: org_opencv_android_Utils
|
||||||
* Method: nBitmapToMat(Bitmap b)
|
* Method: nBitmapToMat(Bitmap b)
|
||||||
* Signature: (L)J
|
* Signature: (L)J
|
||||||
*/
|
*/
|
||||||
|
|
||||||
JNIEXPORT jlong JNICALL Java_org_opencv_Android_nBitmapToMat
|
JNIEXPORT jlong JNICALL Java_org_opencv_android_Utils_nBitmapToMat
|
||||||
(JNIEnv * env, jclass cls, jobject bitmap)
|
(JNIEnv * env, jclass cls, jobject bitmap)
|
||||||
{
|
{
|
||||||
AndroidBitmapInfo info;
|
AndroidBitmapInfo info;
|
||||||
@@ -40,11 +40,11 @@ JNIEXPORT jlong JNICALL Java_org_opencv_Android_nBitmapToMat
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_opencv_Android
|
* Class: org_opencv_android_Utils
|
||||||
* Method: nBitmapToMat(long m, Bitmap b)
|
* Method: nBitmapToMat(long m, Bitmap b)
|
||||||
* Signature: (JL)Z
|
* Signature: (JL)Z
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jboolean JNICALL Java_org_opencv_Android_nMatToBitmap
|
JNIEXPORT jboolean JNICALL Java_org_opencv_android_Utils_nMatToBitmap
|
||||||
(JNIEnv * env, jclass cls, jlong m, jobject bitmap)
|
(JNIEnv * env, jclass cls, jlong m, jobject bitmap)
|
||||||
{
|
{
|
||||||
AndroidBitmapInfo info;
|
AndroidBitmapInfo info;
|
@@ -1,62 +1,62 @@
|
|||||||
package org.opencv;
|
package org.opencv.android;
|
||||||
|
|
||||||
import org.opencv.core.CvException;
|
import org.opencv.core.CvException;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
public class Android {
|
public class Utils {
|
||||||
|
|
||||||
public static String ExportResource(Context context, int resourceId) {
|
public static String ExportResource(Context context, int resourceId) {
|
||||||
return ExportResource(context, resourceId, "OpenCV_data");
|
return ExportResource(context, resourceId, "OpenCV_data");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String ExportResource(Context context, int resourceId, String dirname) {
|
public static String ExportResource(Context context, int resourceId, String dirname) {
|
||||||
String fullname = context.getResources().getString(resourceId);
|
String fullname = context.getResources().getString(resourceId);
|
||||||
String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
|
String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
|
||||||
try {
|
try {
|
||||||
InputStream is = context.getResources().openRawResource(resourceId);
|
InputStream is = context.getResources().openRawResource(resourceId);
|
||||||
File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
|
File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
|
||||||
File resFile = new File(resDir, resName);
|
File resFile = new File(resDir, resName);
|
||||||
|
|
||||||
FileOutputStream os = new FileOutputStream(resFile);
|
FileOutputStream os = new FileOutputStream(resFile);
|
||||||
|
|
||||||
byte[] buffer = new byte[4096];
|
byte[] buffer = new byte[4096];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
while ((bytesRead = is.read(buffer)) != -1) {
|
while ((bytesRead = is.read(buffer)) != -1) {
|
||||||
os.write(buffer, 0, bytesRead);
|
os.write(buffer, 0, bytesRead);
|
||||||
}
|
}
|
||||||
is.close();
|
is.close();
|
||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
return resFile.getAbsolutePath();
|
return resFile.getAbsolutePath();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new CvException("Failed to export resource " + resName
|
throw new CvException("Failed to export resource " + resName
|
||||||
+ ". Exception thrown: " + e);
|
+ ". Exception thrown: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Mat BitmapToMat(Bitmap b) {
|
public static Mat BitmapToMat(Bitmap b) {
|
||||||
return new Mat(nBitmapToMat(b));
|
return new Mat(nBitmapToMat(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean MatToBitmap(Mat m, Bitmap b) {
|
public static boolean MatToBitmap(Mat m, Bitmap b) {
|
||||||
return nMatToBitmap(m.nativeObj, b);
|
return nMatToBitmap(m.nativeObj, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// native stuff
|
// native stuff
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("opencv_java");
|
System.loadLibrary("opencv_java");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native long nBitmapToMat(Bitmap b);
|
private static native long nBitmapToMat(Bitmap b);
|
||||||
|
|
||||||
private static native boolean nMatToBitmap(long m, Bitmap b);
|
private static native boolean nMatToBitmap(long m, Bitmap b);
|
||||||
}
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package org.opencv;
|
package org.opencv.utils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -475,7 +475,7 @@ public class Converters {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Mat vector_DMatch_to_Mat(List<DMatch> matches) {
|
public static Mat vector_DMatch_to_Mat(List<DMatch> matches) {
|
||||||
Mat res;
|
Mat res;
|
||||||
int count = (matches!=null) ? matches.size() : 0;
|
int count = (matches!=null) ? matches.size() : 0;
|
||||||
if(count>0){
|
if(count>0){
|
||||||
@@ -493,8 +493,8 @@ public class Converters {
|
|||||||
res = new Mat();
|
res = new Mat();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
|
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
|
||||||
if(matches == null)
|
if(matches == null)
|
||||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||||
@@ -507,7 +507,7 @@ public class Converters {
|
|||||||
double[] buff = new double[4*count];
|
double[] buff = new double[4*count];
|
||||||
m.get(0, 0, buff);
|
m.get(0, 0, buff);
|
||||||
for(int i=0; i<count; i++) {
|
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] ) );
|
matches.add( new DMatch( (int)buff[4*i], (int)buff[4*i+1], (int)buff[4*i+2], (float)buff[4*i+3] ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user