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.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.opencv.Android;
|
||||
|
||||
/**
|
||||
* 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 CHESS_PATH;
|
||||
public static String LBPCASCADE_FRONTALFACE_PATH;
|
||||
public static Context context;
|
||||
|
||||
private AndroidTestRunner androidTestRunner;
|
||||
private static String TAG = "opencv_test_java";
|
||||
@ -32,9 +30,10 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
LENA_PATH = ExportResource(R.drawable.lena);
|
||||
CHESS_PATH = ExportResource(R.drawable.chessboard);
|
||||
LBPCASCADE_FRONTALFACE_PATH = ExportResource(R.raw.lbpcascade_frontalface);
|
||||
context = getContext();
|
||||
LENA_PATH = Android.ExportResource(context, R.drawable.lena);
|
||||
CHESS_PATH = Android.ExportResource(context, R.drawable.chessboard);
|
||||
LBPCASCADE_FRONTALFACE_PATH = Android.ExportResource(context, R.raw.lbpcascade_frontalface);
|
||||
|
||||
// List<TestCase> testCases = androidTestRunner.getTestCases();
|
||||
// Collections.shuffle(testCases); //shuffle the tests order
|
||||
@ -47,32 +46,4 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
|
||||
androidTestRunner = super.getAndroidTestRunner();
|
||||
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;
|
||||
|
||||
|
||||
public class features2dTest extends OpenCVTestCase {
|
||||
|
||||
}
|
||||
|
@ -22,8 +22,14 @@ class JavadocGenerator(object):
|
||||
assert args_start * args_end > 0
|
||||
if args_start >= 0:
|
||||
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(","))))
|
||||
return (line, offset, [])
|
||||
name = line[:args_start].strip()
|
||||
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):
|
||||
inf = open(infile, "rt")
|
||||
|
@ -12,19 +12,31 @@ public:
|
||||
#if 0
|
||||
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 virtual void read( const FileNode& );
|
||||
CV_WRAP virtual void write( FileStorage& ) const;
|
||||
CV_WRAP virtual bool empty() const;
|
||||
#endif
|
||||
|
||||
//supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX)
|
||||
//not supported: SimpleBlob, Dense
|
||||
CV_WRAP_AS(create) static javaFeatureDetector* jcreate( const string& detectorType )
|
||||
{
|
||||
Ptr<FeatureDetector> detector = FeatureDetector::create(detectorType);
|
||||
detector.addref();
|
||||
return (javaFeatureDetector*)((FeatureDetector*) detector);
|
||||
}
|
||||
//supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX)
|
||||
//not supported: SimpleBlob, Dense
|
||||
CV_WRAP_AS(create) static javaFeatureDetector* jcreate( const string& detectorType )
|
||||
{
|
||||
Ptr<FeatureDetector> detector = FeatureDetector::create(detectorType);
|
||||
detector.addref();
|
||||
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
|
||||
@ -32,14 +44,14 @@ class CV_EXPORTS_AS(DescriptorMatcher) javaDescriptorMatcher : public Descriptor
|
||||
public:
|
||||
#if 0
|
||||
CV_WRAP virtual bool isMaskSupported() const;
|
||||
CV_WRAP virtual void add( const vector<Mat>& descriptors );
|
||||
CV_WRAP const vector<Mat>& getTrainDescriptors() const;
|
||||
CV_WRAP virtual void clear();
|
||||
CV_WRAP virtual bool empty() const;
|
||||
CV_WRAP virtual void train();
|
||||
CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
CV_WRAP virtual void add( const vector<Mat>& descriptors );
|
||||
CV_WRAP const vector<Mat>& getTrainDescriptors() const;
|
||||
CV_WRAP virtual void clear();
|
||||
CV_WRAP virtual bool empty() const;
|
||||
CV_WRAP virtual void train();
|
||||
CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
vector<DMatch>& matches, const Mat& mask=Mat() ) const;
|
||||
CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
vector<vector<DMatch> >& matches, int k,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
@ -51,25 +63,36 @@ public:
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
CV_WRAP void radiusMatch( const Mat& queryDescriptors, vector<vector<DMatch> >& matches, float maxDistance,
|
||||
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
|
||||
|
||||
CV_WRAP_AS(clone) javaDescriptorMatcher* jclone( bool emptyTrainData=false ) const
|
||||
{
|
||||
Ptr<DescriptorMatcher> matcher = this->clone(emptyTrainData);
|
||||
matcher.addref();
|
||||
return (javaDescriptorMatcher*)((DescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
//supported: FlannBased, BruteForce, BruteForce-L1, BruteForce-Hamming, BruteForce-HammingLUT
|
||||
CV_WRAP_AS(create) static javaDescriptorMatcher* jcreate( const string& descriptorMatcherType )
|
||||
{
|
||||
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(descriptorMatcherType);
|
||||
matcher.addref();
|
||||
return (javaDescriptorMatcher*)((DescriptorMatcher*) matcher);
|
||||
}
|
||||
{
|
||||
Ptr<DescriptorMatcher> matcher = this->clone(emptyTrainData);
|
||||
matcher.addref();
|
||||
return (javaDescriptorMatcher*)((DescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
//supported: FlannBased, BruteForce, BruteForce-L1, BruteForce-Hamming, BruteForce-HammingLUT
|
||||
CV_WRAP_AS(create) static javaDescriptorMatcher* jcreate( const string& descriptorMatcherType )
|
||||
{
|
||||
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(descriptorMatcherType);
|
||||
matcher.addref();
|
||||
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
|
||||
@ -78,8 +101,6 @@ public:
|
||||
#if 0
|
||||
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 virtual void read( const FileNode& );
|
||||
CV_WRAP virtual void write( FileStorage& ) const;
|
||||
CV_WRAP virtual int descriptorSize() const = 0;
|
||||
CV_WRAP virtual int descriptorType() const = 0;
|
||||
|
||||
@ -87,13 +108,27 @@ public:
|
||||
#endif
|
||||
|
||||
//supported SIFT, SURF, ORB, BRIEF, Opponent(XXXX)
|
||||
//not supported: Calonder
|
||||
CV_WRAP_AS(create) static javaDescriptorExtractor* jcreate( const string& descriptorExtractorType )
|
||||
{
|
||||
Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create(descriptorExtractorType);
|
||||
extractor.addref();
|
||||
return (javaDescriptorExtractor*)((DescriptorExtractor*) extractor);
|
||||
}
|
||||
//not supported: Calonder
|
||||
CV_WRAP_AS(create) static javaDescriptorExtractor* jcreate( const string& descriptorExtractorType )
|
||||
{
|
||||
Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create(descriptorExtractorType);
|
||||
extractor.addref();
|
||||
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
|
||||
@ -122,9 +157,9 @@ CV_EXPORTS_W void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoint
|
||||
const vector<vector<DMatch> >& matches1to2, Mat& outImg,
|
||||
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
|
||||
const vector<vector<char> >& matchesMask=vector<vector<char> >(), int flags=0);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
} //cv
|
||||
|
||||
#endif // __OPENCV_FEATURES_2D_MANUAL_HPP__
|
||||
#endif // __OPENCV_FEATURES_2D_MANUAL_HPP__
|
||||
|
@ -1,20 +1,62 @@
|
||||
package org.opencv;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public class Android {
|
||||
|
||||
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);
|
||||
}
|
||||
package org.opencv;
|
||||
|
||||
import org.opencv.core.CvException;
|
||||
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;
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvException extends Exception {
|
||||
public class CvException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user