Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rladstaetter/javacv-webcam

Display a videostream from your webcam with JavaFX and JavaCV
https://github.com/rladstaetter/javacv-webcam

java java11 javacv javafx maven opencv webcam webcamera

Last synced: 3 months ago
JSON representation

Display a videostream from your webcam with JavaFX and JavaCV

Awesome Lists containing this project

README

        

# javacv-webcam

A project which shows how to use JavaFX together with OpenCV / JavaCV bindings.

This project can be used as a starting point for experiments with OpenCV and Java. It showcases the usage of the PixelBuffer API which permits a fast display / rendering of a webcam image stream with JavaFX.

Furthermore it uses [javafx-maven-plugin](https://github.com/openjfx/javafx-maven-plugin) to generate a custom java image.

You will need at least [Java11](https://adoptopenjdk.net) and [Maven 3.6.2](https://maven.apache.org/) to build.

## Compile and run with javafx-maven-plugin

For a quick glimpse of what this project does just checkout the code and enter

mvn javafx:run -Djavacpp.platform.custom -Djavacpp.platform.host

Note: Providing javacpp properties is not mandatory, but it reduces download size for bytedeco significantly (only fetches
libs for your platform - remember to always provide those parameters though).

After downloading dependencies and compiling a window should appear with your webcam image stream.

If you want to create a custom jre distribution, enter

mvn javafx:jlink -Djavacpp.platform.custom -Djavacpp.platform.host

which creates a custom JDK11 based distribution. You can start the application by entering

./target/javacv-webcam/bin/jwebcam

If you peek into the ``javacv-webcam`` directory.

Attention: If you are using Windows or Linux you'll have to adapt module-info.java to include native libraries of suitable for those platforms. On MacOsX, you may have problems with permissions to access your webcam from a java application, make sure to allow access in your system preferences.

## Compile and run with client-maven-plugin

This project contains also a configuration for compiling it to a native image using [GraalVM](https://www.graalvm.org/). You have
to download and install GraalVM in a recent version (I tested it with 20.2.0) and then compile and run it with following command:

mvn clean client:build client:run -Djavacpp.platform.custom -Djavacpp.platform.host -Dgraalvm.home=/path/to/your/graalvm/distribution

After downloading necessary toolings, dependencies and compiling and linking (takes some time) a JavaFX application which uses
your webcam will start.

## Links

- Have a look at [https://openjfx.io](https://openjfx.io) where you can find more information and introductory examples for developing JavaFX applications.
- [https://github.com/bytedeco/javacv](https://github.com/bytedeco/javacv) is the home of JavaCV which enables Java Developers to use native libraries like [OpenCV](https://opencv.org).
- Some posts on [http://ladstatt.blogspot.com/](https://ladstatt.blogspot.com) may be of interest, too.