Ask Your Question

ORB model conversion from python to java

asked 2020-06-09 06:35:06 -0500

Miorii gravatar image

Hello, I've been working on a python software to classify pictures. The purpose is, we have a book of 180 pages, and we want to know, for a query picture, what page it is. To this end, I extract descriptors from reference pictures using ORB. For a query picture, I extract the descriptors, force match it with my reference descriptors, and assume that the reference picture with the highest number of matches is the same page as our query.

This gets very decent results, and I wanted to make an android application out of it, using therefore a java version of OpenCV. To avoid computation of reference descriptors every time the application starts, I want to compute them on python, using my first software, save them, and load them in java. The reference ORB descriptors database in python is a numpy array of approximately 90,000 descriptors, of length 32, and dtype uint8. I would like to be able to get it in java as a Mat of 90,000 rows, 32 cols and of type CV_8UC1, the uint8 equivalent.

However, I can't find any smooth way to do it. Is there any cross-language format I could use for easy save & load?

Please let me know if I'm unclear, or if you need further informations.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-06-12 06:51:33 -0500

Miorii gravatar image

Update, if anyone ever needs it, I chose to encode the descriptors as a picture using PIL, here it what it looks like on the python saving part:

from PIL import Image
im = Image.fromarray(featuresDB)"features.png")

featuresDB being the numpy array of ORB descriptors. On the java side, using android studio, put this picture in src/main/res/drawable/features.png, and load it as such:

Mat features = Utils.loadResource(MainActivity.this, R.drawable.features, Imgcodecs.IMREAD_GRAYSCALE);

Which requires those imports:

import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-06-09 06:35:06 -0500

Seen: 57 times

Last updated: Jun 12