### Getting Started with Qt in Java
Source: https://github.com/bytedeco/javacpp-presets/blob/master/qt/README.md
This Java code demonstrates a basic Qt application using JavaCPP Presets. It initializes the Qt environment, sets up command-line arguments, creates a `QApplication`, displays a `QTextEdit` widget, and starts the application event loop. Remember to run Java with '-XstartOnFirstThread' on macOS.
```java
import java.io.File;
import org.bytedeco.javacpp.*;
import org.bytedeco.qt.Qt5Core.*;
import org.bytedeco.qt.Qt5Gui.*;
import org.bytedeco.qt.Qt5Widgets.*;
import static org.bytedeco.qt.global.Qt5Core.*;
import static org.bytedeco.qt.global.Qt5Gui.*;
import static org.bytedeco.qt.global.Qt5Widgets.*;
public class GettingStarted {
private static IntPointer argc;
private static PointerPointer argv;
public static void main(String[] args) {
String path = Loader.load(org.bytedeco.qt.global.Qt5Core.class);
argc = new IntPointer(new int[]{3});
argv = new PointerPointer("gettingstarted", "-platformpluginpath", new File(path).getParent(), null);
QApplication app = new QApplication(argc, argv);
QTextEdit textEdit = new QTextEdit();
textEdit.show();
System.exit(app.exec());
}
}
```
--------------------------------
### Maven Build File for videoInput Example
Source: https://github.com/bytedeco/javacpp-presets/blob/master/videoinput/README.md
Configure your Maven project to include the videoinput-platform dependency. This setup allows for automatic downloading and installation of class files and native binaries.
```xml
4.0.0
org.bytedeco.videoinput
exampleusage
1.5.9
ExampleUsage
org.bytedeco
videoinput-platform
0.200-1.5.9
.
```
--------------------------------
### Initialize RealSense Context and Query Devices
Source: https://github.com/bytedeco/javacpp-presets/blob/master/librealsense2/README.md
This snippet demonstrates the initial setup for using the RealSense library in Java. It includes creating a context, querying connected devices, and printing basic device information. Ensure the RealSense SDK is properly installed and accessible.
```java
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.
/* Include the librealsense C header files */
import org.bytedeco.javacpp.*;
import org.bytedeco.librealsense2.*;
import static org.bytedeco.librealsense2.global.realsense2.*;
public class RsDistance {
/* Function calls to librealsense may raise errors of type rs_error*/
static void check_error(rs2_error e) {
if (!e.isNull()) {
System.out.printf("rs_error was raised when calling %s(%s):\n", rs2_get_failed_function(e), rs2_get_failed_args(e));
System.out.printf(" %s\n", rs2_get_error_message(e));
System.exit(1);
}
}
static void print_device_info(rs2_device dev) {
rs2_error e = new rs2_error();
System.out.printf("\nUsing device 0, an %s\n", rs2_get_device_info(dev, RS2_CAMERA_INFO_NAME, e));
check_error(e);
System.out.printf(" Serial number: %s\n", rs2_get_device_info(dev, RS2_CAMERA_INFO_SERIAL_NUMBER, e));
check_error(e);
System.out.printf(" Firmware version: %s\n\n", rs2_get_device_info(dev, RS2_CAMERA_INFO_FIRMWARE_VERSION, e));
check_error(e);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// These parameters are reconfigurable //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int STREAM = RS2_STREAM_DEPTH; // rs2_stream is a types of data provided by RealSense device //
static int FORMAT = RS2_FORMAT_Z16; // rs2_format is identifies how binary data is encoded within a frame //
static int WIDTH = 640; // Defines the number of columns for each frame or zero for auto resolve//
static int HEIGHT = 0; // Defines the number of lines for each frame or zero for auto resolve //
static int FPS = 30; // Defines the rate of frames per second //
static int STREAM_INDEX = 0; // Defines the stream index, used for multiple streams of the same type //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
rs2_error e = new rs2_error();
// Create a context object. This object owns the handles to all connected realsense devices.
// The returned object should be released with rs2_delete_context(...)
rs2_context ctx = rs2_create_context(RS2_API_VERSION, e);
check_error(e);
/* Get a list of all the connected devices. */
// The returned object should be released with rs2_delete_device_list(...)
rs2_device_list device_list = rs2_query_devices(ctx, e);
check_error(e);
int dev_count = rs2_get_device_count(device_list, e);
check_error(e);
System.out.printf("There are %d connected RealSense devices.\n", dev_count);
if (0 == dev_count)
System.exit(1);
// Get the first connected device
// The returned object should be released with rs2_delete_device(...)
rs2_device dev = rs2_create_device(device_list, 0, e);
check_error(e);
print_device_info(dev);
// Create a pipeline to configure, start and stop camera streaming
// The returned object should be released with rs2_delete_pipeline(...)
rs2_pipeline pipeline = rs2_create_pipeline(ctx, e);
check_error(e);
// Create a config instance, used to specify hardware configuration
// The retunred object should be released with rs2_delete_config(...)
rs2_config config = rs2_create_config(e);
check_error(e);
// Request a specific configuration
rs2_config_enable_stream(config, STREAM, STREAM_INDEX, WIDTH, HEIGHT, FORMAT, FPS, e);
check_error(e);
// Start the pipeline streaming
// The retunred object should be released with rs2_delete_pipeline_profile(...)
rs2_pipeline_profile pipeline_profile = rs2_pipeline_start_with_config(pipeline, config, e);
if (!e.isNull()) {
System.out.printf("The connected device doesn't support depth streaming!\n");
System.exit(1);
}
while (e.isNull()) {
// This call waits until a new composite_frame is available
// composite_frame holds a set of frames. It is used to prevent frame drops
// The returned object should be released with rs2_release_frame(...)
rs2_frame frames = rs2_pipeline_wait_for_frames(pipeline, RS2_DEFAULT_TIMEOUT, e);
check_error(e);
```
--------------------------------
### Clone Repositories and Install JavaCPP
Source: https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets
Clone the JavaCPP and JavaCPP Presets repositories, then build and install JavaCPP locally. Ensure all required software is installed as per README files and the Build Environments page.
```bash
$ git clone https://github.com/bytedeco/javacpp.git
$ git clone https://github.com/bytedeco/javacpp-presets.git
$ cd javacpp
$ mvn clean install
```
--------------------------------
### Install Specific JavaCPP Presets
Source: https://github.com/bytedeco/javacpp-presets/wiki/Building-on-Windows
Install a specific preset, such as OpenBLAS, using the cppbuild.sh script and then build it with Maven, skipping the C++ build step.
```bash
bash cppbuild.sh -platform windows-x86_64 install openblas
mvn install -Djavacpp.platform=windows-x86_64 -Djavacpp.cppbuild.skip=true --projects openblas
```
--------------------------------
### Install Maven Projects
Source: https://github.com/bytedeco/javacpp-presets/blob/master/README.md
Use this command to install specific Maven projects, such as OpenCV and FFmpeg platforms, with a custom JavaCPP platform host.
```bash
$ cd platform
$ mvn install --projects ../opencv/platform,../ffmpeg/platform,etc. -Djavacpp.platform.host
```
--------------------------------
### Install Docker on Fedora/Ubuntu
Source: https://github.com/bytedeco/javacpp-presets/wiki/Build-Environments
Installs Docker on Fedora using `yum` or Ubuntu using `apt-get`. Ensure Docker is running and firewall is managed if using SELinux.
```bash
$ sudo yum install docker
$ sudo apt-get install docker.io
```
```bash
$ sudo systemctl stop firewalld
$ sudo systemctl start docker
```
--------------------------------
### Install Presets with Maven
Source: https://github.com/bytedeco/javacpp-presets/wiki/Upgrade-of-presets-to-1.5
After making the necessary changes, use this Maven command to clean and install your upgraded presets. The '-pl .,' flag ensures that only your presets and their dependencies are built.
```shell
mvn clean install -pl .,
```
--------------------------------
### Basic Video Input Example
Source: https://github.com/bytedeco/javacpp-presets/blob/master/videoinput/README.md
Demonstrates the fundamental workflow of initializing video input, listing devices, setting up a device, capturing frames, and stopping the device. Ensure necessary imports are included.
```java
import org.bytedeco.javacpp.*;
import org.bytedeco.videoinput.*;
import static org.bytedeco.videoinput.global.videoInputLib.*;
public class ExampleUsage {
public static void main(String[] args) {
//create a videoInput object
videoInput VI = new videoInput();
//Prints out a list of available devices and returns num of devices found
int numDevices = VI.listDevices();
int device1 = 0; //this could be any deviceID that shows up in listDevices
int device2 = 1; //this could be any deviceID that shows up in listDevices
//if you want to capture at a different frame rate (default is 30)
//specify it here, you are not guaranteed to get this fps though.
//VI.setIdealFramerate(dev, 60);
//setup the first device - there are a number of options:
VI.setupDevice(device1); //setup the first device with the default settings
//VI.setupDevice(device1, VI_COMPOSITE); //or setup device with specific connection type
//VI.setupDevice(device1, 320, 240); //or setup device with specified video size
//VI.setupDevice(device1, 320, 240, VI_COMPOSITE); //or setup device with video size and connection type
//VI.setFormat(device1, VI_NTSC_M); //if your card doesn't remember what format it should be
//call this with the appropriate format listed above
//NOTE: must be called after setupDevice!
//optionally setup a second (or third, fourth ...) device - same options as above
VI.setupDevice(device2);
//As requested width and height can not always be accomodated
//make sure to check the size once the device is setup
int width = VI.getWidth(device1);
int height = VI.getHeight(device1);
int size = VI.getSize(device1);
BytePointer yourBuffer1 = new BytePointer(size);
BytePointer yourBuffer2 = new BytePointer(size);
//to get the data from the device first check if the data is new
if (VI.isFrameNew(device1)){
VI.getPixels(device1, yourBuffer1, false, false); //fills pixels as a BGR (for openCV) unsigned char array - no flipping
VI.getPixels(device1, yourBuffer2, true, true); //fills pixels as a RGB (for openGL) unsigned char array - flipping!
}
//same applies to device2 etc
//to get a settings dialog for the device
VI.showSettingsWindow(device1);
//Shut down devices properly
VI.stopDevice(device1);
VI.stopDevice(device2);
}
}
```
--------------------------------
### Start Triton Inference Server Docker Container and Install Dependencies
Source: https://github.com/bytedeco/javacpp-presets/blob/master/tritonserver/README.md
Start an NGC Docker container with GPU support, install necessary Java and build tools (Maven, CMake), and clone the javacpp-presets repository. Ensure you are in the 'models' directory before running the container.
```bash
$ docker run -it --gpus=all -v $(pwd):/workspace nvcr.io/nvidia/tritonserver:26.04-py3 bash
$ apt update
$ apt install -y openjdk-11-jdk
$ wget https://archive.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz
$ tar zxvf apache-maven-3.8.4-bin.tar.gz
$ export PATH=/opt/tritonserver/apache-maven-3.8.4/bin:$PATH
# The CAPI Bindings will also need some additional dependencies
$ apt update && apt install -y gpg \
$ wget \
$ rapidjson-dev \
$ software-properties-common && \
$ wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
$ gpg --dearmor - | \
$ tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null && \
$ . /etc/os-release && \
$ echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ $UBUNTU_CODENAME main" | \
$ tee /etc/apt/sources.list.d/kitware.list >/dev/null && \
$ apt-get update && \
$ apt-get install -y --no-install-recommends cmake cmake-data
$ git clone https://github.com/bytedeco/javacpp-presets.git
$ cd javacpp-presets
```
--------------------------------
### Main Entry Point for Camera Acquisition Example
Source: https://github.com/bytedeco/javacpp-presets/blob/master/spinnaker/README.md
The main entry point for the camera acquisition example. It handles system initialization, camera discovery, and initiates the acquisition process for detected cameras. It also checks for write permissions in the current directory.
```java
/**
* Example entry point; please see Enumeration_C example for more in-depth
* comments on preparing and cleaning up the system.
*/
public static void main(String[] args) {
spinError err;
// Since this application saves images in the current folder
// we must ensure that we have permission to write to this folder.
// If we do not have permission, fail right away.
if (!new File(".").canWrite()) {
System.out.println("Failed to create file in current folder. Please check permissions.");
return;
}
// Retrieve singleton reference to system object
spinSystem hSystem = new spinSystem();
err = spinSystemGetInstance(hSystem);
exitOnError(err, "Unable to retrieve system instance.");
// Retrieve list of cameras from the system
spinCameraList hCameraList = new spinCameraList();
err = spinCameraListCreateEmpty(hCameraList);
exitOnError(err, "Unable to create camera list.");
err = spinSystemGetCameras(hSystem, hCameraList);
exitOnError(err, "Unable to retrieve camera list.");
// Retrieve number of cameras
SizeTPointer numCameras = new SizeTPointer(1);
err = spinCameraListGetSize(hCameraList, numCameras);
exitOnError(err, "Unable to retrieve number of cameras.");
System.out.println("Number of cameras detected: " + numCameras.get() + "\n");
// Finish if there are no cameras
if (numCameras.get() == 0) {
// Clear and destroy camera list before releasing system
err = spinCameraListClear(hCameraList);
```
--------------------------------
### Example UnsatisfiedLinkError on Linux
Source: https://github.com/bytedeco/javacpp-presets/wiki/Debugging-UnsatisfiedLinkError-on-Windows
This exception occurs when the operating system cannot load a required library, such as when a dependent library is not installed.
```java
java.lang.UnsatisfiedLinkError: no jniFlyCapture2 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1864)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:636)
at org.bytedeco.javacpp.Loader.load(Loader.java:474)
at org.bytedeco.javacpp.Loader.load(Loader.java:411)
at org.bytedeco.javacpp.FlyCapture2.(FlyCapture2.java:10)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.bytedeco.javacpp.Loader.load(Loader.java:446)
at org.bytedeco.javacpp.Loader.load(Loader.java:411)
at org.bytedeco.javacpp.FlyCapture2$FC2Version.(FlyCapture2.java:709)
at FlyCapture2Test.PrintBuildInfo(FlyCapture2Test.java:28)
at FlyCapture2Test.main(FlyCapture2Test.java:135)
... 6 more
Caused by: java.lang.UnsatisfiedLinkError: /tmp/javacpp3216546462129/libjniFlyCapture2.so: libflycapture.so.2: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:619)
... 16 more
```
--------------------------------
### Set up JavaCPP and JavaCPP Presets Repositories
Source: https://github.com/bytedeco/javacpp-presets/wiki/Build-Environments
Clone the JavaCPP and JavaCPP Presets repositories and install the JavaCPP module. Replace `` with the desired version tag.
```bash
$ git clone https://github.com/bytedeco/javacpp.git --branch
$ git clone https://github.com/bytedeco/javacpp-presets.git --branch
$ cd javacpp
$ mvn clean install -Djavacpp.platform=...
```
--------------------------------
### Maven POM Configuration for Skia Example
Source: https://github.com/bytedeco/javacpp-presets/blob/master/skia/README.md
This XML configuration is used with Maven to download and install Skia class files and native binaries. It specifies the necessary dependency for the skia-platform artifact.
```xml
4.0.0
org.bytedeco.skia
skiacexample
1.5.8
SkiaCExample
org.bytedeco
skia-platform
2.88.3-1.5.8
.
```
--------------------------------
### Initialize libfreenect2 and Open Device
Source: https://github.com/bytedeco/javacpp-presets/blob/master/libfreenect2/README.md
Loads the libfreenect2 library and initializes the context. It then opens the default device using a CPU packet pipeline.
```java
import org.bytedeco.javacpp.*;
import org.bytedeco.libfreenect2.*;
import static org.bytedeco.libfreenect2.global.freenect2.*;
/**
* @author Jeremy Laviole
*/
public class freenect2Example {
public static void main(String[] args) {
Freenect2 freenect2Context;
try {
Loader.load(org.bytedeco.libfreenect2.global.freenect2.class);
// Context is shared accross cameras.
freenect2Context = new Freenect2();
} catch (Exception e) {
System.out.println("Exception in the TryLoad !" + e);
e.printStackTrace();
return;
}
Freenect2Device device = null;
PacketPipeline pipeline = null;
String serial = "";
// Only CPU pipeline tested.
pipeline = new CpuPacketPipeline();
// pipeline = new libfreenect2::OpenGLPacketPipeline();
// pipeline = new libfreenect2::OpenCLPacketPipeline(deviceId);
// pipeline = new libfreenect2::CudaPacketPipeline(deviceId);
if (serial == "") {
serial = freenect2Context.getDefaultDeviceSerialNumber().getString();
System.out.println("Serial:" + serial);
}
device = freenect2Context.openDevice(serial, pipeline);
// [listeners]
int types = 0;
types |= Frame.Color;
types |= Frame.Ir | Frame.Depth;
SyncMultiFrameListener listener = new SyncMultiFrameListener(types);
device.setColorFrameListener(listener);
device.setIrAndDepthFrameListener(listener);
device.start();
System.out.println("Serial: " + device.getSerialNumber().getString());
System.out.println("Firmware: " + device.getFirmwareVersion().getString());
/// [start]
FrameMap frames = new FrameMap();
// Fetch 100 frames.
int frameCount = 0;
for (int i = 0; i < 100; i++) {
System.out.println("getting frame " + frameCount);
if (!listener.waitForNewFrame(frames, 10 * 1000)) // 10 sconds
{
System.out.println("timeout!");
return;
}
Frame rgb = frames.get(Frame.Color);
Frame ir = frames.get(Frame.Ir);
Frame depth = frames.get(Frame.Depth);
/// [loop start]
System.out.println("RGB image, w:" + rgb.width() + " " + rgb.height());
byte[] imgData = new byte[1000];
rgb.data().get(imgData);
for (int pix = 0; pix < 10; pix++) {
System.out.print(imgData[pix] + " ");
}
System.out.println();
frameCount++;
listener.release(frames);
continue;
}
device.stop();
device.close();
}
}
```
--------------------------------
### Maven Build File for DepthAI Examples
Source: https://github.com/bytedeco/javacpp-presets/blob/master/depthai/README.md
This pom.xml file configures a Maven project to use DepthAI and OpenCV platform dependencies. Ensure Maven 3 is installed to run the sample code.
```xml
4.0.0
org.bytedeco.depthai
examples
1.5.11
CameraPreviewExample
org.bytedeco
depthai-platform
2.24.0-1.5.11
org.bytedeco
opencv-platform
4.9.0-1.5.11
.
```
--------------------------------
### MultiMarker Example in Java
Source: https://github.com/bytedeco/javacpp-presets/blob/master/artoolkitplus/README.md
This Java code snippet demonstrates how to process and display marker positions in a multi-marker augmented reality setup using ARToolKitPlus. It iterates through detected markers and prints their transformed coordinates.
```java
System.out.printf("%.2f ", marker.position(multiMarkerCounter).trans(row, column)));
}
System.out.println();
}
}
}
}
}
```
--------------------------------
### Compile and Run Sample with Maven
Source: https://github.com/bytedeco/javacpp-presets/blob/master/bullet/samples/README.md
Use this command to compile and run any of the provided samples. Replace `` with the actual class name of the sample you wish to execute.
```bash
$ mvn compile exec:java -Dexec.mainClass=
```
--------------------------------
### Maven Project Setup for Tesseract OCR
Source: https://github.com/bytedeco/javacpp-presets/blob/master/tesseract/README.md
Configure your Maven project to include the Tesseract OCR JavaCPP Presets by adding the tesseract-platform dependency. This allows automatic download and installation of necessary class files and native binaries.
```xml
4.0.0
org.bytedeco.tesseract
BasicExample
1.5.13
BasicExample
org.bytedeco
tesseract-platform
5.5.2-1.5.13
.
```
--------------------------------
### FlyCapture2 Main Function Example
Source: https://github.com/bytedeco/javacpp-presets/blob/master/flycapture/README.md
This is the main entry point for the FlyCapture2 test application. It handles camera detection and initialization. Ensure write permissions for the current directory before running.
```java
public static void main(String[] args) throws IOException {
PrintBuildInfo();
Error error;
// Since this application saves images in the current folder
// we must ensure that we have permission to write to this folder.
// If we do not have permission, fail right away.
File tempFile = new File("test.txt");
try {
new FileOutputStream(tempFile).close();
} catch (IOException e) {
System.out.println("Failed to create file in current folder. "
+ "Please check permissions.");
System.exit(-1);
}
tempFile.delete();
BusManager busMgr = new BusManager();
int[] numCameras = new int[1];
error = busMgr.GetNumOfCameras(numCameras);
if (error.notEquals(PGRERROR_OK)) {
PrintError(error);
System.exit(-1);
}
System.out.println("Number of cameras detected: " + numCameras[0]);
for (int i = 0; i < numCameras[0]; i++) {
PGRGuid guid = new PGRGuid();
error = busMgr.GetCameraFromIndex(i, guid);
if (error.notEquals(PGRERROR_OK)) {
PrintError(error);
System.exit(-1);
}
RunSingleCamera(guid);
}
System.out.println("Done! Press Enter to exit...");
System.in.read();
}
}
```
--------------------------------
### Maven POM File for TensorFlow Example
Source: https://github.com/bytedeco/javacpp-presets/blob/master/tensorflow/README.md
This pom.xml file configures Maven to download and install TensorFlow JavaCPP Presets and native binaries. It includes dependencies for the core TensorFlow platform, GPU support, and optional Python integration.
```xml
4.0.0
org.bytedeco.tensorflow
exampletrainer
1.5.8
ExampleTrainer
org.bytedeco
tensorflow-platform
1.15.5-1.5.8
org.bytedeco
tensorflow-platform-gpu
1.15.5-1.5.8
org.bytedeco
cuda-platform-redist
11.8-8.6-1.5.8
.
```
--------------------------------
### Setup libdc1394 Camera for Image Capture in Java
Source: https://github.com/bytedeco/javacpp-presets/blob/master/libdc1394/README.md
Configures the camera's ISO speed, video mode, and framerate, then sets up the capture mechanism. Includes error handling and cleanup.
```java
err = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
if (err != 0) {
dc1394_log_error("Could not set iso speed: " + err);
cleanup_and_exit(camera);
}
err = dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_640x480_RGB8);
if (err != 0) {
dc1394_log_error("Could not set video mode: " + err);
cleanup_and_exit(camera);
}
err = dc1394_video_set_framerate(camera, DC1394_FRAMERATE_7_5);
if (err != 0) {
dc1394_log_error("Could not set framerate: " + err);
cleanup_and_exit(camera);
}
err = dc1394_capture_setup(camera,4, DC1394_CAPTURE_FLAGS_DEFAULT);
if (err != 0) {
dc1394_log_error("Could not setup camera-\n" +
"make sure that the video mode and framerate are\n" +
"supported by your camera: " + err);
cleanup_and_exit(camera);
}
```
--------------------------------
### Main Application Entry Point
Source: https://github.com/bytedeco/javacpp-presets/blob/master/libfreenect/README.md
Initializes the JavaCV environment, sets up the OpenGL canvas, configures event listeners for rendering and user input, and starts the animation loop.
```java
public static void main(String[] args) {
Loader.load(org.bytedeco.libfreenect.global.freenect.class);
canvas = new GLCanvas();
canvas.addGLEventListener(new GLEventListener() {
@Override public void init(GLAutoDrawable glautodrawable) {
InitGL(glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight());
}
@Override public void display(GLAutoDrawable glautodrawable) {
DrawGLScene(glautodrawable.getGL().getGL2());
}
@Override public void dispose(GLAutoDrawable glautodrawable) {
}
@Override public void reshape(GLAutoDrawable glautodrawable, int x, int y, int width, int height) {
ReSizeGLScene(glautodrawable.getGL().getGL2(), width, height);
}
});
canvas.addKeyListener(new KeyAdapter() {
@Override public void keyPressed(KeyEvent e) {
GLPCLView.keyPressed(e.getKeyCode());
}
});
canvas.addMouseMotionListener(new MouseMotionAdapter() {
@Override public void mouseDragged(MouseEvent e) {
GLPCLView.mouseMoved(e.getX(), e.getY());
}
});
canvas.addMouseListener(new MouseAdapter() {
@Override public void mousePressed(MouseEvent e) {
mousePress(e.getButton(), MouseEvent.MOUSE_PRESSED, e.getX(), e.getY());
}
@Override public void mouseReleased(MouseEvent e) {
mousePress(e.getButton(), MouseEvent.MOUSE_RELEASED, e.getX(), e.getY());
}
});
frame = new JFrame("LibFreenect");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setPreferredSize(new Dimension(640, 480));
frame.getContentPane().add(canvas);
frame.pack();
frame.setVisible(true);
animator = new FPSAnimator(canvas, 60, true);
animator.start();
}
```
--------------------------------
### Install MinGW-w64 Toolchains
Source: https://github.com/bytedeco/javacpp-presets/wiki/Building-on-Windows
Install the MinGW-w64 toolchains for both 64-bit and 32-bit architectures, including CMake and GCC with Fortran support. Also installs libwinpthread for cross-platform compatibility.
```bash
pacman -Su mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc mingw-w64-i686-gcc mingw-w64-x86_64-gcc-fortran mingw-w64-i686-gcc-fortran mingw-w64-x86_64-libwinpthread-git mingw-w64-i686-libwinpthread-git
```
--------------------------------
### Install Essential MSYS2 Packages
Source: https://github.com/bytedeco/javacpp-presets/wiki/Building-on-Windows
Install development tools and utilities required for building packages within the MSYS2 environment. Press Enter to confirm the installation of all modules.
```bash
pacman -S base-devel tar patch make git unzip zip nasm yasm pkg-config
```
--------------------------------
### Initialize OpenGL Scene
Source: https://github.com/bytedeco/javacpp-presets/blob/master/libfreenect/README.md
Sets up the OpenGL environment, including background color, depth testing, and texture generation. It also resizes the scene to fit the window dimensions.
```java
static void InitGL(GL2 gl2, int Width, int Height) {
gl2.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl2.glEnable(GL2.GL_DEPTH_TEST);
gl2.glGenTextures(1, gl_rgb_tex, 0);
gl2.glBindTexture(GL2.GL_TEXTURE_2D, gl_rgb_tex[0]);
gl2.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
gl2.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
ReSizeGLScene(gl2, Width, Height);
}
```
--------------------------------
### Compile and Run OpenVINO Sample
Source: https://github.com/bytedeco/javacpp-presets/blob/master/openvino/README.md
Use this command to compile and run a minimal OpenVINO sample. Ensure you have Maven installed.
```bash
mvn -f openvino/samples/pom.xml compile exec:java
```
--------------------------------
### Install MSYS2 Packages
Source: https://github.com/bytedeco/javacpp-presets/wiki/Build-Environments
Run this command within an MSYS2 shell to install essential development tools and libraries required for building.
```bash
$ pacman -S base-devel tar patch autoconf autoconf-archive automake libtool make git unzip zip p7zip pkg-config gnupg mingw-w64-x86_64-nasm mingw-w64-x86_64-toolchain mingw-w64-x86_64-libtool mingw-w64-x86_64-gcc mingw-w64-i686-gcc mingw-w64-x86_64-gcc-fortran mingw-w64-i686-gcc-fortran mingw-w64-x86_64-libwinpthread-git mingw-w64-i686-libwinpthread-git mingw-w64-x86_64-SDL2 mingw-w64-i686-SDL2 mingw-w64-x86_64-ragel
```
--------------------------------
### Navigate to Build Directory
Source: https://github.com/bytedeco/javacpp-presets/wiki/Building-on-Windows
Change the current directory to where you want to clone the JavaCPP and JavaCPP-presets repositories. Example uses C:\Lang\Java\javacpp\.
```bash
cd /c/Lang/Java/javacpp/
```