Java API: added support for read/write functions in features2d
This commit is contained in:
parent
d86605f6a7
commit
d5d897b7cb
@ -5,10 +5,7 @@ import android.test.AndroidTestRunner;
|
|||||||
import android.test.InstrumentationTestRunner;
|
import android.test.InstrumentationTestRunner;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import org.opencv.Android;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This only class is Android specific. The original idea about test order
|
* This only class is Android specific. The original idea about test order
|
||||||
@ -22,6 +19,7 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
|
|||||||
public static String LENA_PATH;
|
public static String LENA_PATH;
|
||||||
public static String CHESS_PATH;
|
public static String CHESS_PATH;
|
||||||
public static String LBPCASCADE_FRONTALFACE_PATH;
|
public static String LBPCASCADE_FRONTALFACE_PATH;
|
||||||
|
public static Context context;
|
||||||
|
|
||||||
private AndroidTestRunner androidTestRunner;
|
private AndroidTestRunner androidTestRunner;
|
||||||
private static String TAG = "opencv_test_java";
|
private static String TAG = "opencv_test_java";
|
||||||
@ -32,9 +30,10 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
LENA_PATH = ExportResource(R.drawable.lena);
|
context = getContext();
|
||||||
CHESS_PATH = ExportResource(R.drawable.chessboard);
|
LENA_PATH = Android.ExportResource(context, R.drawable.lena);
|
||||||
LBPCASCADE_FRONTALFACE_PATH = ExportResource(R.raw.lbpcascade_frontalface);
|
CHESS_PATH = Android.ExportResource(context, R.drawable.chessboard);
|
||||||
|
LBPCASCADE_FRONTALFACE_PATH = Android.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
|
||||||
@ -47,32 +46,4 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
|
|||||||
androidTestRunner = super.getAndroidTestRunner();
|
androidTestRunner = super.getAndroidTestRunner();
|
||||||
return androidTestRunner;
|
return androidTestRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String ExportResource(int resourceId) {
|
|
||||||
String fullname = getContext().getResources().getString(resourceId);
|
|
||||||
String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
|
|
||||||
try {
|
|
||||||
InputStream is = getContext().getResources().openRawResource(
|
|
||||||
resourceId);
|
|
||||||
File resDir = getContext().getDir("testdata", Context.MODE_PRIVATE);
|
|
||||||
File resFile = new File(resDir, resName);
|
|
||||||
|
|
||||||
FileOutputStream os = new FileOutputStream(resFile);
|
|
||||||
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
int bytesRead;
|
|
||||||
while ((bytesRead = is.read(buffer)) != -1) {
|
|
||||||
os.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
is.close();
|
|
||||||
os.close();
|
|
||||||
|
|
||||||
return resFile.getAbsolutePath();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log("Failed to export resource " + resName + ". Exception thrown: "
|
|
||||||
+ e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,5 @@ package org.opencv.test.features2d;
|
|||||||
|
|
||||||
import org.opencv.test.OpenCVTestCase;
|
import org.opencv.test.OpenCVTestCase;
|
||||||
|
|
||||||
|
|
||||||
public class features2dTest extends OpenCVTestCase {
|
public class features2dTest extends OpenCVTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,14 @@ class JavadocGenerator(object):
|
|||||||
assert args_start * args_end > 0
|
assert args_start * args_end > 0
|
||||||
if args_start >= 0:
|
if args_start >= 0:
|
||||||
assert args_start < args_end
|
assert args_start < args_end
|
||||||
return (line[:args_start].strip(), offset, filter(None, list(arg.strip() for arg in line[args_start+1:args_end].split(","))))
|
name = line[:args_start].strip()
|
||||||
return (line, offset, [])
|
if name.startswith("java"):
|
||||||
|
name = name[4:]
|
||||||
|
return (name, offset, filter(None, list(arg.strip() for arg in line[args_start+1:args_end].split(","))))
|
||||||
|
name = line.strip()
|
||||||
|
if name.startswith("java"):
|
||||||
|
name = name[4:]
|
||||||
|
return (name, offset, [])
|
||||||
|
|
||||||
def document(self, infile, outfile):
|
def document(self, infile, outfile):
|
||||||
inf = open(infile, "rt")
|
inf = open(infile, "rt")
|
||||||
|
@ -12,8 +12,6 @@ public:
|
|||||||
#if 0
|
#if 0
|
||||||
CV_WRAP void detect( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
CV_WRAP void detect( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
||||||
CV_WRAP void detect( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, const vector<Mat>& masks=vector<Mat>() ) const;
|
CV_WRAP void detect( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, const vector<Mat>& masks=vector<Mat>() ) const;
|
||||||
CV_WRAP virtual void read( const FileNode& );
|
|
||||||
CV_WRAP virtual void write( FileStorage& ) const;
|
|
||||||
CV_WRAP virtual bool empty() const;
|
CV_WRAP virtual bool empty() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -25,6 +23,20 @@ public:
|
|||||||
detector.addref();
|
detector.addref();
|
||||||
return (javaFeatureDetector*)((FeatureDetector*) detector);
|
return (javaFeatureDetector*)((FeatureDetector*) detector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CV_WRAP void write( const string& fileName ) const
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::WRITE);
|
||||||
|
((FeatureDetector*)this)->write(fs);
|
||||||
|
fs.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP void read( const string& fileName )
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::READ);
|
||||||
|
((FeatureDetector*)this)->read(fs.root());
|
||||||
|
fs.release();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CV_EXPORTS_AS(DescriptorMatcher) javaDescriptorMatcher : public DescriptorMatcher
|
class CV_EXPORTS_AS(DescriptorMatcher) javaDescriptorMatcher : public DescriptorMatcher
|
||||||
@ -51,9 +63,6 @@ public:
|
|||||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||||
CV_WRAP void radiusMatch( const Mat& queryDescriptors, vector<vector<DMatch> >& matches, float maxDistance,
|
CV_WRAP void radiusMatch( const Mat& queryDescriptors, vector<vector<DMatch> >& matches, float maxDistance,
|
||||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||||
CV_WRAP virtual void read( const FileNode& );
|
|
||||||
// Writes matcher object to a file storage
|
|
||||||
CV_WRAP virtual void write( FileStorage& ) const;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CV_WRAP_AS(clone) javaDescriptorMatcher* jclone( bool emptyTrainData=false ) const
|
CV_WRAP_AS(clone) javaDescriptorMatcher* jclone( bool emptyTrainData=false ) const
|
||||||
@ -70,6 +79,20 @@ public:
|
|||||||
matcher.addref();
|
matcher.addref();
|
||||||
return (javaDescriptorMatcher*)((DescriptorMatcher*) matcher);
|
return (javaDescriptorMatcher*)((DescriptorMatcher*) matcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CV_WRAP void write( const string& fileName ) const
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::WRITE);
|
||||||
|
((DescriptorMatcher*)this)->write(fs);
|
||||||
|
fs.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP void read( const string& fileName )
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::READ);
|
||||||
|
((DescriptorMatcher*)this)->read(fs.root());
|
||||||
|
fs.release();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CV_EXPORTS_AS(DescriptorExtractor) javaDescriptorExtractor : public DescriptorExtractor
|
class CV_EXPORTS_AS(DescriptorExtractor) javaDescriptorExtractor : public DescriptorExtractor
|
||||||
@ -78,8 +101,6 @@ public:
|
|||||||
#if 0
|
#if 0
|
||||||
CV_WRAP void compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
|
CV_WRAP void compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
|
||||||
CV_WRAP void compute( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, vector<Mat>& descriptors ) const;
|
CV_WRAP void compute( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, vector<Mat>& descriptors ) const;
|
||||||
CV_WRAP virtual void read( const FileNode& );
|
|
||||||
CV_WRAP virtual void write( FileStorage& ) const;
|
|
||||||
CV_WRAP virtual int descriptorSize() const = 0;
|
CV_WRAP virtual int descriptorSize() const = 0;
|
||||||
CV_WRAP virtual int descriptorType() const = 0;
|
CV_WRAP virtual int descriptorType() const = 0;
|
||||||
|
|
||||||
@ -94,6 +115,20 @@ public:
|
|||||||
extractor.addref();
|
extractor.addref();
|
||||||
return (javaDescriptorExtractor*)((DescriptorExtractor*) extractor);
|
return (javaDescriptorExtractor*)((DescriptorExtractor*) extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CV_WRAP void write( const string& fileName ) const
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::WRITE);
|
||||||
|
((DescriptorExtractor*)this)->write(fs);
|
||||||
|
fs.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP void read( const string& fileName )
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::READ);
|
||||||
|
((DescriptorExtractor*)this)->read(fs.root());
|
||||||
|
fs.release();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -1,10 +1,48 @@
|
|||||||
package org.opencv;
|
package org.opencv;
|
||||||
|
|
||||||
|
import org.opencv.core.CvException;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
public class Android {
|
public class Android {
|
||||||
|
|
||||||
|
public static String ExportResource(Context context, int resourceId) {
|
||||||
|
return ExportResource(context, resourceId, "OpenCV_data");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String ExportResource(Context context, int resourceId, String dirname) {
|
||||||
|
String fullname = context.getResources().getString(resourceId);
|
||||||
|
String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
|
||||||
|
try {
|
||||||
|
InputStream is = context.getResources().openRawResource(resourceId);
|
||||||
|
File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
|
||||||
|
File resFile = new File(resDir, resName);
|
||||||
|
|
||||||
|
FileOutputStream os = new FileOutputStream(resFile);
|
||||||
|
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = is.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
is.close();
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
return resFile.getAbsolutePath();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new CvException("Failed to export resource " + resName
|
||||||
|
+ ". 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));
|
||||||
}
|
}
|
||||||
@ -14,7 +52,11 @@ public class Android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// native stuff
|
// native stuff
|
||||||
static { System.loadLibrary("opencv_java"); }
|
static {
|
||||||
|
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,6 +1,6 @@
|
|||||||
package org.opencv.core;
|
package org.opencv.core;
|
||||||
|
|
||||||
public class CvException extends Exception {
|
public class CvException extends RuntimeException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user