Small 'fatjar' using OpenCV (javacv) and Gradle

227 views
Skip to first unread message

Carlos Solorio

unread,
Jun 21, 2017, 6:25:38 PM6/21/17
to javacv
Hi, everyone

I've been trying to build a JAR using Gradle of an application to use the local camera (webcam), and so some basic face detection/tracking with all necessary OpenCV dependencies (a fatjar is usually called).
The final JAR is approximately 200MB if javacv-platform is added in the build.gradle file:
compile group: 'org.bytedeco', name: 'javacv-platform', version: '1.3.2'

If I use instead:
compile (group: 'org.bytedeco', name: 'javacv-platform', version: '1.3.2'){
        exclude
module:'librealsense'
        exclude
module:'artoolkitplus'
        exclude
module:'ffmpeg'
        exclude
module:'flandmark'
        exclude
module:'flycapture'
        exclude
module:'libdc1394'
        exclude
module:'libfreenect'
        exclude
module:'libfreenect2'
        exclude
module:'videoinput'
   
}
The JAR file gets reduced to 105MB

Is there any way to reduce the size of the jar file even more? Like excluding specifically the linux, arm and macos (only need windows) versions of the opencv dependencies? I've tried using, for example:
exclude module:'opencv:android-arm'

In my project, I'm using the following packages/classes:
import org.bytedeco.javacpp.opencv_core;
import org.bytedeco.javacpp.opencv_videoio;
import org.bytedeco.javacpp.opencv_core;
import org.bytedeco.javacv.CanvasFrame;
import org.bytedeco.javacv.OpenCVFrameConverter;
import org.bytedeco.javacpp.opencv_objdetect;
import static org.bytedeco.javacpp.opencv_imgcodecs.imread;
import static org.bytedeco.javacpp.opencv_imgproc.CV_FONT_HERSHEY_PLAIN;
import static org.bytedeco.javacpp.opencv_imgproc.putText;
import static org.bytedeco.javacpp.opencv_imgproc.rectangle;

Is there some way to instruct gradle to include JUST the absolute necessary dependencies?

Regards!
 

Shirisha Reddy

unread,
Oct 1, 2019, 6:58:07 AM10/1/19
to javacv
Are you able to build the project by excluding the modules. I am getting build errors that required modules by javacv are not found. I am using jlink to build my JavaFx application

Samuel Audet

unread,
Oct 1, 2019, 9:44:37 AM10/1/19
to jav...@googlegroups.com
jlink doesn't support "optional" modules. The only way that I know of to
work around that is by creating a new module for your application via,
for example, an uber JAR.
Reply all
Reply to author
Forward
0 new messages