[1/3] 背景
最近用到 JavaCV做直播项目,在从github上下载了一个叫 RtmpRecoder的项目时,发现RtmpRecoder用到了通过JavaCV运用到ffmpeg,于是下载了JavaCV-bin (javacv-1.2-src.zip),解压后发现里面只有jar包,却没有发现任何底层库----没有底层库怎么调到ffmpeg那?
带着这个疑问, 按照《【Java CV与Android】在Android工程里配置JavaCV》里介绍的,解压了其中一个jar文件ffmpeg-android-arm.jar,在目录javacv-bin/ffmpeg-android-arm/lib/armeabi下果然发现有一堆动态库。
第一次见到JAR包中也可以包含底层库,很惊奇,就想知道是怎么做到的。就google搜索了下,发现可以运用Jar2Lib和jace技术生成。此外,JavaCPP技术能便捷的实现把底层库打包进JAR,能部分代替JNI技术(但是不能代替底层回调Java层)。
在此,贴出具体方法,以备查阅。
[2/3] [转] Jace and Jar2Lib
Jar2Lib
Jar2Lib is a command line tool for generating C++ wrapper libraries around Java JAR files. It exposes the entire public Java API of the JAR in the corresponding C++ shared library, delegating to Java via JNI. The wrapping is performed using Jace.
We use Jar2Lib to generate the BF-CPP bindings for Bio-Formats, which we use in our WiscScan acquisition software.
Historical note: Jar2Lib was originally developed to integrate Bio-Formats with the Insight Toolkit, for use with the FARSIGHT project. However, we now have an dedicated inter-process solution for ITK integration instead which is easier to build from source, since it has no compile-time dependencies. Nonetheless, BF-CPP is still the recommended in-process solution for Bio-Formats native code integration.
We recommend using Jar2Lib via the cppwrap-maven-plugin; see "Installation and usage" below.
If you prefer to use Jar2Lib directly from the command line outside Maven:
- Download the JARs linked above, as well as Apache Velocity 1.7 and its dependencies.
- With all necessary JARs in your current working directory, you can run Jar2Lib on the command line as follows:
$ java -cp '*' loci.jar2lib.Jar2Lib
Usage: java loci.jar2lib.Jar2Lib projectId projectName
library.jar [library2.jar ...]
[-conflicts conflicts.txt] [-header header.txt]
[-extras cmake_extras.txt] [-output /path/to/output-project]
[-core java_core_classes.txt
The easiest way to use Jar2Lib is via our cppwrap Maven plugin, which takes advantage of the Maven plug-in infrastructure to easily convert a Java library to C++ using Jar2Lib, without requiring any knowledge of Jar2Lib's workings or syntax. For example, it circumvents any need to download transitive dependencies.
更详细信息,请参考网址 https://loci.wisc.edu/software/jar2lib
[3/3] JavaCPP技术
3.1 JavaCPP Presets -- Prebuilt Java Bindings to C/C++ Libraries
- OpenCV – [sample usage] – More than 2500 optimized computer vision and machine learning algorithms
- FFmpeg – [sample usage] – A complete, cross-platform solution to record, convert and stream audio and video
- FlyCapture – [sample usage] – Image acquisition and camera control software
- libdc1394 – [sample usage] – A high-level API for DCAM/IIDC cameras
- OpenKinect – [sample usage] – Open source library to use the Xbox Kinect
- videoInput – [sample usage] – A free Windows video capture library
- ARToolKitPlus – [sample usage] – Marker-based augmented reality tracking library
- Chilitags – [sample usage] – Robust fiducial markers for augmented reality and robotics
- flandmark – [sample usage] – Open-source implementation of facial landmark detector
- FFTW – [sample usage] – Fast computing of the discrete Fourier transform (DFT) in one or more dimensions
- GSL – [sample usage] – The GNU Scientific Library, a numerical library for C and C++ programmers
- LLVM – [sample usage] – A collection of modular and reusable compiler and toolchain technologies
- Leptonica – [sample usage] – Software useful for image processing and image analysis applications
- Tesseract – [sample usage] – Probably the most accurate open source OCR engine available
- Caffe – [sample usage] – A fast open framework for deep learning
- CUDA – [sample usage] – Arguably the most popular parallel computing platform for GPUs
- MXNet – [sample usage] – Flexible and efficient library for deep learning
- TensorFlow – [sample usage] – Computation using data flow graphs for scalable machine learning
- Add here your favorite C/C++ library, for example: OpenNI, OpenMesh, PCL, etc. Read about how to do that.
We will add more to this list as they are made, including those from outside the bytedeco/javacpp-presets repository.