About this project
# JavaCV
JavaCV wraps popular computer vision and multimedia libraries—OpenCV, FFmpeg, libdc1394, FlyCapture, Spinnaker, OpenKinect, librealsense, ARToolKitPlus, flandmark, Leptonica, and Tesseract—through JavaCPP Presets, making them accessible from Java and Android.
## What it does
- Loads and processes images and video via OpenCV and FFmpeg bindings
- Captures frames from webcams, cameras, and video files
- Records video output to files
- Provides face detection with Haar cascades, contour finding, geometric transformation, and calibration utilities
- Hardware-accelerated full-screen image display through `CanvasFrame` / `GLCanvasFrame`
- Parallel execution helpers and direct native memory access via NIO buffers
## Key classes
- `FrameGrabber` / `FrameRecorder` — abstract interfaces for capture and recording; concrete implementations include `OpenCVFrameGrabber`, `FFmpegFrameGrabber`, `OpenCVFrameRecorder`, `FFmpegFrameRecorder`
- `OpenCVFrameConverter` / `Java2DFrameConverter` — convert between OpenCV `Mat`/`IplImage`, Java `BufferedImage`, Android `Bitmap`, and `Frame`
- `CascadeClassifier` — loaded from XML files for object/face detection
- `CanvasFrame` / `GLCanvasFrame` — display windows with optional full-screen mode
- `Parallel` — execute tasks across multiple cores
- `GeometricCalibrator` / `ProCamGeometricCalibrator` — camera and projector calibration
## Installation
Add the platform BOM to your build. Maven:
```xml
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.5.14</version>
</dependency>
```
Gradle:
```groovy
implementation 'org.bytedeco:javacv-platform:1.5.14'
```
For GPU-accelerated OpenCV or GPL-licensed FFmpeg builds, add `opencv-platform-gpu` or `ffmpeg-platform-gpl` respectively. Binaries cover Android, iOS, Linux, macOS, and Windows.
## Requirements
- Java SE 8 or newer
- C++ compiler (for building from source)
- Optional: Android SDK API 24+, JOCL/JOGL for OpenCL and OpenGL support
- Match 32-bit and 64-bit artifacts; they cannot be mixed
## Sample: face detection from a webcam
```java
import org.bytedeco.javacv.*;
import org.bytedeco.opencv.opencv_core.*;
import org.bytedeco.opencv.opencv_objdetect.*;
import static org.bytedeco.opencv.global.opencv_core.*;
import static org.bytedeco.opencv.global.opencv_imgproc.*;
import static org.bytedeco.opencv.global.opencv_objdetect.*;
public class FaceDetect {
public static void main(String[] args) throws Exception {
FrameGrabber grabber = FrameGrabber.createDefault(0);
grabber.start();
CascadeClassifier classifier = new CascadeClassifier(
"haarcascade_frontalface_alt.xml");
OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
CanvasFrame frame = new CanvasFrame("Face Detection");
Mat gray = new Mat();
while (frame.isVisible() &&
(grabbed = converter.convert(grabber.grab())) != null) {
cvtColor(grabbed, gray, COLOR_BGR2GRAY);
RectVector faces = new RectVector();
classifier.detectMultiScale(gray, faces);
for (int i = 0; i < faces.size(); i++) {
Rect r = faces.get(i);
rectangle(grabbed, new Point(r.x(), r.y()),
new Point(r.x() + r.width(), r.y() + r.height()),
new Scalar(0, 255, 0));
}
frame.showImage(grabbed);
}
frame.dispose();
grabber.stop();
}
}
```
## Build from source
Requires Maven 3.x and JavaCPP 1.5.14. Run `mvn install` in the JavaCPP, JavaCPP Presets, and JavaCV directories. Snapshot builds are also available at http://bytedeco.org/builds/.
## Links
- Repository: https://github.com/bytedeco/javacv
- Mailing list: http://groups.google.com/group/javacv
- Discussion: https://github.com/bytedeco/javacv/discussions
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.