Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

javacv

> 包管理
Open source

Java interface to OpenCV, FFmpeg, and more

8.3K stars0 likes4 views
WebsiteGitHub

About

Java interface to OpenCV, FFmpeg, and more

JavaCV

Commercial support:

Introduction

JavaCV uses wrappers from the JavaCPP Presets of commonly used libraries by researchers in the field of computer vision (OpenCV, FFmpeg, libdc1394, FlyCapture, Spinnaker, OpenKinect, librealsense, CL PS3 Eye Driver, videoInput, ARToolKitPlus, flandmark, Leptonica, and Tesseract) and provides utility classes to make their functionality easier to use on the Java platform, including Android.

JavaCV also comes with hardware accelerated full-screen image display (CanvasFrame and GLCanvasFrame), easy-to-use methods to execute code in parallel on multiple cores (Parallel), user-friendly geometric and color calibration of cameras and projectors (GeometricCalibrator, ProCamGeometricCalibrator, ProCamColorCalibrator), detection and matching of feature points (ObjectFinder), a set of classes that implement direct image alignment of projector-camera systems (mainly GNImageAligner, ProjectiveTransformer, ProjectiveColorTransformer, ProCamTransformer, and ReflectanceInitializer), a blob analysis package (Blobs), as well as miscellaneous functionality in the JavaCV class. Some of these classes also have an OpenCL and OpenGL counterpart, their names ending with CL or starting with GL, i.e.: JavaCVCL, GLCanvasFrame, etc.

To learn how to use the API, since documentation currently lacks, please refer to the Sample Usage section below as well as the sample programs, including two for Android (FacePreview.java and RecordActivity.java), also found in the samples directory. You may also find it useful to refer to the source code of ProCamCalib and ProCamTracker as well as examples ported from OpenCV2 Cookbook and the associated wiki pages.

Please keep me informed of any updates or fixes you make to the code so that I may integrate them into the next release. Thank you! And feel free to ask questions on the mailing list or the discussion forum if you encounter any problems with the software! I am sure it is far from perfect...

Downloads

Archives containing JAR files are available as releases. The binary archive contains builds for Android, iOS, Linux, Mac OS X, and Windows. The JAR files for specific child modules or platforms can also be obtained individually from the Maven Central Repository.

To install manually the JAR files, follow the instructions in the Manual Installation section below.

We can also have everything downloaded and installed automatically with:

  • Maven (inside the pom.xml file)
xml
  <dependency>
    <groupId>org.bytedeco</groupId>
    <artifactId>javacv-platform</artifactId>
    <version>1.5.14</version>
  </dependency>
  • Gradle (inside the build.gradle.kts or build.gradle file)
groovy
  dependencies {
    implementation("org.bytedeco:javacv-platform:1.5.14")
  }
  • Leiningen (inside the project.clj file)
clojure
  :dependencies [
    [org.bytedeco/javacv-platform "1.5.14"]
  ]
  • sbt (inside the build.sbt file)
scala
  libraryDependencies += "org.bytedeco" % "javacv-platform" % "1.5.14"

This downloads binaries for all platforms, but to get binaries for only one platform we can set the javacpp.platform system property (via the -D command line option) to something like android-arm, linux-x86_64, macosx-x86_64, windows-x86_64, etc. Please refer to the README.md file of the JavaCPP Presets for details. Another option available to Gradle users is Gradle JavaCPP, and similarly for Scala users there is SBT-JavaCV.

Required Software

To use JavaCV, you will first need to download and install the following software:

  • An implementation of Java SE 8 or newer:
    • OpenJDK http://openjdk.java.net/install/ or
    • Oracle JDK http://www.oracle.com/technetwork/java/javase/downloads/ or
    • IBM JDK http://www.ibm.com/developerworks/java/jdk/ or
    • Microsoft JDK https://www.microsoft.com/openjdk etc

Further, although not always required, some functionality of JavaCV also relies on:

  • CL Eye Platform SDK (Windows only) http://codelaboratories.com/downloads/
  • Android SDK API 24 or newer http://developer.android.com/sdk/
  • JOCL and JOGL from JogAmp http://jogamp.org/

Finally, please make sure everything has the same bitness: 32-bit and 64-bit modules do not mix under any circumstances.

Manual Installation

Simply put all the desired JAR files (opencv*.jar, ffmpeg*.jar, etc.), in addition to javacpp.jar and javacv.jar, somewhere in your class path. Here are some more specific instructions for common cases:

NetBeans (Java SE 8 or newer):

  1. In the Projects window, right-click the Libraries node of your project, and select "Add JAR/Folder...".
  2. Locate the JAR files, select them, and click OK.

Eclipse (Java SE 8 or newer):

  1. Navigate to Project > Properties > Java Build Path > Libraries and click "Add External JARs...".
  2. Locate the JAR files, select them, and click OK.

Visual Studio Code (Java SE 8 or newer):

  1. Navigate to Java Projects > Referenced Libraries, and click +.
  2. Locate the JAR files, select them, and click OK.

IntelliJ IDEA (Android 7.0 or newer):

  1. Follow the instructions on this page: http://developer.android.com/training/basics/firstapp/
  2. Copy all the JAR files into the app/libs subdirectory.
  3. Navigate to File > Project Structure > app > Dependencies, click +, and select "2 File dependency".
  4. Select all the JAR files from the libs subdirectory.
  5. In the AndroidManifest.xml add android:extractNativeLibs="true"

After that, the wrapper classes for OpenCV and FFmpeg, for example, can automatically access all of their C/C++ APIs:

  • OpenCV documentation
  • FFmpeg documentation

Sample Usage

The class definitions are basically ports to Java of the original header files in C/C++, and I deliberately decided to keep as much of the original syntax as possible. For example, here is a method that tries to load an image file, smooth it, and save it back to disk:

java
import org.bytedeco.opencv.opencv_core.*;
import org.bytedeco.opencv.opencv_imgproc.*;
import static org.bytedeco.opencv.global.opencv_core.*;
import static org.bytedeco.opencv.global.opencv_imgproc.*;
import static org.bytedeco.opencv.global.opencv_imgcodecs.*;

public class Smoother {
    public static void smooth(String filename) {
        Mat image = imread(filename);
        if (image != null) {
            GaussianBlur(image, image, new Size(3, 3), 0);
            imwrite(filename, image);
        }
    }
}

JavaCV also comes with helper classes and methods on top of OpenCV and FFmpeg to facilitate their integration to the Java platform. Here is a small demo program demonstrating the most frequently useful parts:

…

Furthermore, after creating a pom.xml file with the following content:

…

And by placing the source code above in Demo.java, or similarly for other classes found in the samples, we can use the following command to have everything first installed automatically and then executed by Maven:

bash
 $ mvn compile exec:java -Dexec.mainClass=Demo

Note: In case of errors, please make sure that the artifactId in the pom.xml file reads javacv-platform, not javacv only, for example. The artifact javacv-platform adds all the necessary binary dependencies.

Build Instructions

If the binary files available above are not enough for your needs, you might need to rebuild them from the source code. To this end, the project files were created for:

  • Maven 3.x http://maven.apache.org/download.html
  • JavaCPP 1.5.14 https://github.com/bytedeco/javacpp
  • JavaCPP Presets 1.5.14 https://github.com/bytedeco/javacpp-presets

Once installed, simply call the usual mvn install command for JavaCPP, its Presets, and JavaCV. By default, no other dependencies than a C++ compiler for JavaCPP are required. Please refer to the comments inside the pom.xml files for further details.

Instead of building the native libraries manually, we can run mvn install for JavaCV only and rely on the snapshot artifacts from the CI builds:

  • http://bytedeco.org/builds/

Project lead: Samuel Audet samuel.audet at gmail.com
Developer site: https://github.com/bytedeco/javacv
Discussion group: http://groups.google.com/group/javacv

Issues· 465 open

View all issuesOpen on GitHub
  • #2388

    include support for opencv 5

    enhancementhelp wantedUpdated Jun 9, 2026
  • #1344

    Add Inference Engine to build to support model optimizer

    enhancementhelp wantedUpdated Jun 4, 2026
  • #2012

    I can't gracefully close ports opened by ffmpeg

    help wantedquestionUpdated Mar 31, 2026
  • #2384

    h264_cuvid crashed when meets with dynamic resolution stream.

    enhancementhelp wantedUpdated Mar 30, 2026
  • #2356

    Memory leak found in FFmpegFrameRecorder

    bughelp wantedquestionUpdated Feb 22, 2026
  • #2382

    FFmpegFrameGrabber should throw an exception when attempting to access stream metadata before calling start()

    enhancementhelp wantedquestionUpdated Feb 20, 2026
  • #1395

    FrameGrabber with inputstream

    help wantedquestionUpdated Feb 11, 2026
  • #2379

    How to read/write SEI(User Data Unregister) from/to H264/HEVC stream?

    enhancementhelp wantedquestionUpdated Feb 9, 2026
  • #2377

    I use grabber and record for video processing vs directly using ffmpeg has different effects.

    help wantedquestionUpdated Feb 3, 2026
  • #2373

    avcodec_open2() error -542398533: Could not open video codec.

    help wantedquestionUpdated Jan 20, 2026

> Tags

Javacomputer-visionffmpegjavajavacv

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category包管理
PricingOpen source

> Related tools

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image