Saving ORB feature vectors using OpenCV4Android (java API)

后端 未结 3 1377
日久生厌
日久生厌 2021-01-02 14:37

I have a training set of images, for each of which I\'ve detected and computed their feature vectors (using ORB feature descriptors and extractors. The questions is<

3条回答
  •  滥情空心
    2021-01-02 14:51

    I see that you have considered using the Android SQLite database:

    My current choice is to opt for a sqlLite database, having a table with two cols; id and feature (as frequently suggested online); to tabulate all the 16k features in sqlLite. That seems rather phone-storage intensive, but it's the most reasonable solution I can find.

    There is a way to save and retrieve MatOfKeyPoint to SQLite database with reasonable efficiency.

    Using the database has the advantage of not needing to request write external storage permission from the user (although that permission might be needed for some other of your apps functions).

    There is a complete Android solution, with Java code which can be found in this StackOverflow Answer.

    The following is a description of what's going on in the code from that answer...

    MatOfKeyPoint to byte[] and some attributes

    To save to the database, you need to save to a byte[] object. Using the MatOfKeyPoint.get() method, you can get a populated float[]. Then using ByteBuffer.putFloat(), you can loop through all of your floats, finally getting a populated byte[] by using ByteBuffer.array().

    You also need to save some attirbutes MatOfKeyPoint.rows(), MatOfKeyPoint.cols(), and MatOfKeyPoint.type() to your database, along with the blob of byte[].

    Database blob (byte[]) to MatOfKeyPoint

    To reconstitute your MatOfKeyPoint object from the database, first you make a float[] out of your blob. Use ByteBuffer.wrap(blob), then run ByteBuffer.asFloatBuffer(), and finally FloatBuffer.get() with a properly sized new float[].

    Now that you have yourFloatArray you run MatOfKeyPoint.create(rows, cols, type), those three things coming from the database record. Finally you run MatOfKeyPoint.put(0, 0, yourFloatArray).

提交回复
热议问题