Can ARToolKit load a pattern file dinamically from outside? - android

Can ARToolKit load a pattern file (source) dinamically from outside after when i builded from the studio and not added exactly source?
Is there any example for this?

Not tried, but seems possible. Try passing the absolute path of .patt file in the config for the addTrackable() method.
String config = "single;" + pattFileAbsolutePath + trackableWidth;
trackableUIDs[i] = getInstance().addTrackable(config);
It's worth giving a try.

Related

OpenCV for Android: How to use YOLOV4 DNN models in an app

I have been creating an app in Android Studio which uses OpenCV. I have my YOLOV4 models which I can use to detect humans. When I was using the Dnn class of org.opencv.dnn.Dnn, I need to provide the absolute path of the config and weights. Initially, I tried to put the files in my assets. But I was not able to get the path of the assets file.
I have tried putting the config and weights file in the external storage of my AVD. But it is showing -
Error: Parsing error (Failed to open NetParameter file: /storage/emulated/0/dnns/yolov4-tiny.cfg) in readNetFromDarknet
This is my code -
String yoloCfg = Environment.getExternalStorageDirectory().getAbsolutePath() + "/dnns/yolov4-tiny.cfg";
String yoloWeights = Environment.getExternalStorageDirectory().getAbsolutePath() + "/dnns/yolov4-tiny.weights";
yoloModel = Dnn.readNetFromDarknet(yoloCfg, yoloWeights);
Am I doing anything wrong or is it an issue?

How can I load my glTF file on SceneViewer with ARCore Android SDK

I'm following the document at Google (https://developers.google.com/ar/develop/java/scene-viewer#ar-only).
I put glTF file in assets/models directory (as same location with Andy.obj)
and I tried to load glTF 2.0 file (from KhronosGroup Sample) but failed:
Intent sceneViewerIntent = new Intent(Intent.ACTION_VIEW);
Uri intentUri =
Uri.parse("https://arvr.google.com/scene-viewer/1.0").buildUpon()
.appendQueryParameter("file", "models/BoxTextured.glb")
.appendQueryParameter("mode", "ar_preferred")
.appendQueryParameter("title", "Untitled")
.build();
sceneViewerIntent.setData(intentUri);
sceneViewerIntent.setPackage("com.google.ar.core");
startActivity(sceneViewerIntent);
In document (which linked above), there is no clue how to write the code to load glTF from local.
what can I do for resolved this problem in android?
Thanks.
edit: The source is based on https://github.com/google-ar/arcore-android-sdk/tree/master/samples/hello_ar_java, and I worked HelloArActivity.java, ARCore Android SDK version is 1.17.0
I solved it by myself.
Set path for glTF to absolute path (like "/sdcard/BoxTextured.glb", not "models/BoxTextured.glb")
I think it can not find (also no convert) relative path from that function.
You have to get a path by //assets/~ or something if you want to use relative path.
EDIT:
also, there is Environment class which has method getExternalStorageDirectory().getAbsolutePath(). i might be solved above problem.

Get some asset file path in APK

I use some class. That's constructor needs some file path that contains some files.
ex)
Komoran komoran = new Komoran("D:\program_project\lib");
Now I'm making android app. so I can't use absolute path (Because other people who download my app don't have that folder and files)
so I decide to use 'assets' folder that is maybe in APK file. So, final code is like below.
Komoran komoran = new Komoran("file:///android_asset");
but It seems like folder path is wrong(this class doesn't work). What I did wrong ?
This "file:///android_asset" path is used for applications which uses webview ex. cordova/phonegap. As it is part of resources because when Apk is created you can not use this path to access your assets folder. You have to work with context.getResources().getAssets().open("fileName")this code only.
Maybe u can add this code:
context.getResources().getAssets().open("fileName").
u will get a inputstream, and u can do something u want.
No need to use getResources.
You can use directly
context.getAssets().open("fileName").

Java, OpenCV: How to read/write ORB FeatureDetection parameters

In OpenCV I am using ORB FeatureDetection in an Android app. It has parameters but these cannot be set directly in Java. The recommended way to set them is to write out a XML or YML file with the params and then read it back in.
However, there seems to be no way to be sure that in fact I have written the file correctly and that the parameters are applied. I thought I could use the write() method to verify that my new settings have taken. But this doesn't seem to work. It does indeed write a proper YML or XML file, but the files have no params.
Here is code to write the files:
_detector = FeatureDetector.create(FeatureDetector.ORB);
// write initial params.
String fileName = myDir.getPath() + "/orb_params.yml";
_detector.write(fileName);
fileName = myDir.getPath() + "/orb_params.xml";
_detector.write(fileName);
// try setting some params.
String tempFileName = writeToFile("tempFile", "%YAML:1.0\nscaleFactor: 1.1\nnLevels: 5\nfirstLevel: 0\nedgeThreshold: 31\npatchSize: 31\n");
_detector.read(tempFileName);
// write params again.
String fileName = myDir.getPath() + "/orb_params2.yml";
_detector.write(fileName);
fileName = myDir.getPath() + "/orb_params2.xml";
_detector.write(fileName);
The xml files look like this:
<?xml version="1.0"?>
<opencv_storage>
</opencv_storage>
The yml files look like this:
%YAML:1.0
Is the write method not implemented in Java? I see that it is implemented in Algorithm.cpp and I assume the ORB Feature Detector just uses that implementation, I see no code to indicate otherwise.
I don't know if this problem is limited to ORB Feature Detection or if other algos suffer these problems when trying to write parameters from Java.
addendum: I see that the write method appears to be implemented in the JNI code: https://github.com/Itseez/opencv/blob/ddf82d0b154873510802ef75c53e628cd7b2cb13/modules/features2d/misc/java/src/cpp/features2d_manual.hpp
Got a response on answers.opencv.org and am posting it here for those stumbling across this in the future:
According to this answer the read/write function is not implemented in C++ and thus won't work in Android either.

Is there a way to compare two song(Audio/Video) file?

How to compare two song stored in two files and see, if they are same or not?
Assuming you're not just looking to compare the files, but the actual music encoded within, you need to come up with a way to generate a fingerprint. For music, check out the MusicBrainz.org - they have open source libraries for getting from a song to it's metadata. Not sure if such a project exists for video though.
Use a open source Library for it. like musicg . Only down side is using that library is you can only compare wave files.
Yes this is possible by using the Follow this article
Download the Apache Commons IO 2.5 API from Here
Add jar file in tools which you are following. (netbeans,eclips,android studio)
Import libarary "import org.apache.commons.io.FileUtils";
you then have to use only this function.
File file1 = new File("1st_File_Path");
File file2 = new File("2nd_File_Path");
boolean compareResult = FileUtils.contentEquals(file1, file2);
System.out.println("Are the files are same? " + compareResult);
must remember to vote :)

Categories

Resources