I am having trouble with nonfree methdos usage in android. SIFT and SURF methods are not included in opencv-android-2.4.8. They are needed to be complied seperately.
https://sites.google.com/site/wghsite/technical-notes/sift_surf_opencv_android
This is the main tutorial about nonfree module compilation. However, the jni part for java users are not included. I have searched how to use compiled .so libraries but I could not achieve.
I wonder that someone can share the jni part for nonfree modules or detailed explanation for it, because I work on that issue over a week and I could not do it.
Thanks.
I am the author of the tutorial. I will be adding another tutorial showing the JNI part. Hope that will help. Please go back and check the tutorial in the next couple of days. I will post it soon.
I solved the problem. When you follow the tutorial(the link given in the question) you get the necessary libraries(.so files). In order to use them in java you do not need to implement jni part. When you load the libraries in your java code (System.load(libraryName)), then you can use sift and surf methods like the other detectors or descriptors. You can directly use the code pattern supplied by the opencv-2.4.8.
Assuming that you've already gotten OpenCV 4 Android to work on your Android device;
1) I placed libnonfree.so, libopencv_java.so and libgnustl_shared.so (not sure if the last one is needed) in the correct folder for your platform, in my case jniLibs/armeabi-v7a. Already compiled version can be find in the demo folder here; https://github.com/bkornel/opencv_android_nonfree
2) Make sure you load both libraries.
static {
System.loadLibrary("opencv_java");
System.loadLibrary("nonfree");
}
This was all that was required in order for it to work for me.
#fetifati, Do you mean to say that if I copy libnonfree.so and libopencv_java.so in say lib/armeabi folder and do System.load("nonfree"); System.load("opencv_java"), I can use code like:
private static final FeatureDetector detector = FeatureDetector
.create(FeatureDetector.SIFT);
private static final DescriptorExtractor extractor = DescriptorExtractor
.create(DescriptorExtractor.SIFT);
directly ? ... It doesn't seem to work for me. I am getting some errors.
Related
An external java library is treated as "package only containing non Java resources" (as indicated by the white icons as opposed to brown; the description in quotes is taken from here). When I try to import the library it cannot be resolved, so it seems it really isn't being recognised (in other words it's not just a case of eclipse showing wrong icon).
Two people have commented that my screenshots are not helping, so let me explain the intention behind them. The first one above is to show the difference between how my libraries are displayed. Htmlparser is a folder with .java files just like SPMF and works fine. Commons-lang and vecmath are .jars. SPMF cannot be resolved when I try to import it. The reason the screenshot is cropped this way is to highlight that all of the folders in SPMF are showing white which apparently means they are not recognized.
This is only the second time I'm using an external library, but I think I did everything the same as the first time.
This screenshot is intended to show how SPMF is added at the moment.
The library I am trying to add is SPMF - more specifically the Hierarchical Clustering algorithm. This is only a minor component of SPMF but it's the best Hierarchical Clustering solution I could find. It works fine if I just import it into a new project. So I could just bodge it by moving my code into that project if I can't get it going otherwise.
I presume that if a package can form a standalone project then it can also be used as an external library - or am I wrong?
I'm sure it's a stupid mistake I'm making but I've had no luck with google. This is the nearest I could find; Refresh seems the only applicable solution and it doesn't help.
Edit, SPMF is also available as a jar, it's missing some features but not the ones I need. I've been able to add the jar and the import the algorithm I need. It's enough of a workaround for me to move on and keep going. But it's not a solution and the question remains open.
I am using these two libraries in my project:
https://github.com/HemendraGangwar/VideoTrimmingLikeWhatsapp
https://github.com/fishwjy/VideoCompressor
Both libraries are imported locally to my project (i.e. copied them and added them to the project)
Both libraries work fine when used separately, but when I use them together I get some errors of type Program type already present which I solved by deleting the file isoparser-1.0.6.jar from the second library, because I noticed that the two libraries use the same library 'com.googlecode.mp4parser:isoparser' but with different versions: 1.1.21 for the first one and 1.0.6 for the second one.
When using only the old library, I get this code:
error: cannot find symbol class FileDataSourceViaHeapImpl
It is working now, but the problem the output video (after compression) does not have sound on it. How can I solve this?
Here is the code I am using for compressing the video (after trimming):
VideoController.getInstance().convertVideo(tmpFile.toString(), dstFile.toString(),
VideoController.COMPRESS_QUALITY_MEDIUM, null);
EDIT1
Summering the scenarios here with the same video:
VideoTrimmingLikeWhatsapp with verion 1.1.21 => works
VideoTrimmingLikeWhatsapp with verion 1.0.6 => does not works (compile error of missing classes)
VideoCompressor with 1.1.21 => does not work (no sound)
VideoCompressor with 1.0.6 => work
I tried a lot of things, and I am loosing tracks here. I also tried using SiliCompressor which seems also using version 1.0.6 of mp4isoparser, and the same problem is happening, output video has no sound. I posted an issue here a few days ago, but I don't think they will address this any time soon.
I also submitted here.
I tried downloading the mp4parser version 1.1.21 from here, and tried to import it locally so I can change the package names, but I couldn't because it using Maven not Gradle. The old version is a jar file, and I need to decompile it so I can mess with it. Can I do that?
I also tried using ffmpeg libraries, but all of them work very slowly compared to mp4isoparser
EDIT 2
The author of SiliCompressor has replied to the here I opened, he says that the problem should be solved by now. For the moment I am unable to verify it, as I no longer work on that project. If any one can confirm it, just tell me to add the answer to this topic.
This combination worked for me:
implementation 'com.iceteck.silicompressorr:silicompressor:2.2.3'
implementation ('com.googlecode.mp4parser:isoparser:1.0.6') {
exclude group: 'org.aspectj', module: 'aspectjrt'
}
Credit to: https://github.com/AndreyAsadchy
https://github.com/Tourenathan-G5organisation/SiliCompressor/issues/141#issuecomment-625308490
If the problem is really caused by the libraries version it is going to be tough to solve.
First I'd double check that. You said you tested the libs separately and that they worked, but, have you tried using the output of 'VideoTrimmingLikeWhatsapp' as input of 'VideoCompressor'?
I'm suspecting that 'VideoCompressor' does weird things with audio in some circumstances, somebody in this issues says there is no audio:
https://github.com/fishwjy/VideoCompressor/issues/1
If you get a video without sound using 'VideoCompressor' with his own version of 'isoparser' you can discard libraries version as the source of the problem.
Then, I think, you can: replace 'VideoCompressor': it seems to rely on Android libraries to perform the compression, you may implement that yourself, or you could find another library for doing the job. Or you can fix 'VideoCompressor': you could report the problem to the author or you could try to fix it yourself.
If you confirm the problem is the versions conflict: Then I can think several options, but none of them is easy:
You can try playing with classloaders and force each library to use their correct version of 'isoparser'. This alone can be difficult to do, besides that it can be very problematic in Android.
You can patch one version of isoparser, renaming package names (for example to com.googlecode.mp4parser_old ) so two versions of them can coexist, you should also patch the client library for using the new package names. This is very ugly but seems doable.
You can try to update 'VideoCompressor' to be compatible with isoparser-1.1.21. You could also ask the author to do it.
Again, you could replace 'VideoCompressor' (or may be 'VideoTrimmingLikeWhatsapp')
I'm aware this is not the definitive answer but I hope it helps you a little.
It's too late but i send this solution to be useful for others.
Yes, the problem is about version conflicts between the two libraries.
Solution:
Don't touch video compressor library at all.
Downgrade the "isoparser" dependency of video trimmer to the same version (1.0.6) with video compressor library dependency "isoparser".
Remove the following line from TrimVideoUtils.java file:
import com.googlecode.mp4parser.FileDataSourceViaHeapImpl;
Then change the following line:
Movie movie = MovieCreator.build(new FileDataSourceViaHeapImpl(src.getAbsolutePath()));
To
Movie movie = MovieCreator.build(src.getAbsolutePath());
It's done.
NOTE: Be careful about large files. Because this solution doesn't use memory mapping.
I am imported the zxing android library for use via gradle, however I want to modify the way things are drawn. From my understanding, that can only be changed by changing the draw function in one of the classes in the library. The problem is I cannot modify the classes in the library due to them being imported with gradle.
Is there any way I can edit that file or even supply another file to override that one? Thanks for your time.
Edit:
Here is a link to the zxing github and the class that I am trying to change the functions in. I want to be able to change what the onDraw function does.
https://github.com/zxing/zxing/blob/master/android/src/com/google/zxing/client/android/ViewfinderView.java
I wasn't able to find a way to override the file, but I did find a workaround. I ended up extending the zXingScannerView file and did an override for the function setAutoFocus(boolean state). I chose that one because it was always called after the overlay was set and allowed me to easily remove it straight away.
Inside that funtion I did:
int chidrenCount = getChildCount();
for(int i = 0; i < childrenCount; i++) {
if(getChildAt(i) instanceof ViewFinderView) {
getChildAt(i).setVisibility(View.INVISIBLE);
}
}
Thanks for the help #FlyingPumba
if you refer to the Zxing Android library for working with Barcodes, it's Open Source !
That means you can download the source code of this library, import it to your project and make the changes you need.
For reading more on importing libraries to Android projects, read this SO question.
Also, if you feel that other users of ZXing would benefit from this change, you can always contribute to the library on GitHub.
:) :) Okay so I am new to LaTeX and Android (So don't hate me please). I am currently working on a project that involves the MimeTeX library working in an android application. (MimeTeX is the LaTeX library ported for android.)
Seeing that MimeTeX is written in C you have to use the native development kit.
I have the following in my main activity:
public native subraster rasterize ( char expression, int size );
static
{
System.loadLibrary("mimetex");
}
Now Eclipse is telling me that 'subraster' cannot be resolved as a type. So can anyone maybe help me and tell me what do I have to add to my MainActivity (in Java) for the subraster type to be valid? I have already configured all the paths and included the ndk-build.cmd to the build path of the C/C++ compiler.
Thank you, and I am sorry, but I am new to this. :) Even links with relevant information would be helpful (If you can find any)
I've struggled a lot with Java but could not combine a working example of Java .wav to .mp3 converter. This converter will be used in a Java applet so it should depend only on libraries written in pure Java with no underlying C code calls.
Can anyone provide a fully working example?
Thank you
Read your wave file # http://java.sun.com/javase/technologies/desktop/media/jmf/
and encode to mp3 # http://openinnowhere.sourceforge.net/lameonj/
As pointed out, lameonj is not a pure java solution. For that the options don't seem so many, but see the other SO question: MP3 Encoding in Java
I use Jump3r to convert wav to mp3 on my project because the html5 player of IE11 can't play wav files.
Jump3r is the simpliest solution found to run inside a tomcat servlet. I wasn't able to integrate others solutions like jave certainly due to the security manager... Jump3r is a pure java program.
Jump3r is available on the maven repository (https://mvnrepository.com/artifact/de.sciss/jump3r/1.0.4) and the sources are available on github (https://github.com/Sciss/jump3r)
To convert a file, you should call the main method (in the following code, I use an inlined version of the main method to catch/throw an IOException if necessary)
private void convertWavFileToMp3File(File source, File target) throws IOException {
String[] mp3Args = { "--preset","standard",
"-q","0",
"-m","s",
source.getAbsolutePath(),
target.getAbsolutePath()
};
(new Main()).run(mp3Args);
}
If speed is not important for you, take any c implementation of MP3 (e. g. lame) and try to compile it with NestedVM to Java bytecode. It will be slow (like an emulator in an emulator), but it should work.
And it should be way less work than trying to port a MP3 library to pure Java.
See this link on SourceForge http://sourceforge.net/projects/jump3r/files/
Its JAR's only (no source code), but it does work on both PC and Android, but no necessarily as described in the authors posting http://pure-java-mp3-encoder.blogspot.com.au/
I got it to work by just using the jump3r-1.0.3.jar file, as a library, and instantiated
mp3.Main then used called mp3.run()
e.g. part of my Android code
String[] mp3Args = {"--preset","standard",
"-q","0",
"-m","s",
Environment.getExternalStorageDirectory().getPath()+"/myfile.wav",
Environment.getExternalStorageDirectory().getPath()+"/myfile.mp3"};
Main m = new mp3.Main();
try
{
m.run(mp3Args);
}
catch(Exception e)
{
System.out.println("ERROR processing MP3 " + e);// Some bug in Android seems to cause error BufferedOutputSteam is Closed. But it still seems to work OK.
}
I suspect it would be possible to directly call the lame encoder passing buffers of data etc, but as the exact API for this Java version is not documented, it would require some research
Another potentially relevant project is jffmpeg. This apparently aimed to an JMF support for a wide range of formats using both native and Java codecs. Judging from the 'formats' page, they made significant progress on the pure Java side. Unfortunately, the project has gone quiet.
This doesn't directly help the OP in the short term. But if he or others are keen to have pure Java codecs in the long term, consider getting involved.
Just check out the following source code.
http://jsidplay2.cvs.sourceforge.net/jsidplay2/jump3r
It is still work in progress, but a working example of the encoder part of a pure java based lame library.