Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade librealsense2 to 2.40.0 #978

Merged
merged 5 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Add display sample for librealsense2 ([pull #978](https://github.com/bytedeco/javacpp-presets/pull/978))
* Fix builds for libpostal on Mac and Windows ([issue #903](https://github.com/bytedeco/javacpp-presets/issues/903))
* Fix builds for NumPy and SciPy on Linux when using a cross compiler or not
* Update presets for Visual Studio 2019 on Windows
Expand All @@ -8,7 +9,7 @@
* Disable assembly optimizations for libx264 with FFmpeg on Mac to work around crashes ([issue bytedeco/javacv#1519](https://github.com/bytedeco/javacv/issues/1519))
* Add `linux-armhf` and `linux-arm64` builds for librealsense and librealsense2 ([pull #951](https://github.com/bytedeco/javacpp-presets/pull/951))
* License default builds of FFmpeg under LGPL v3 and move GPL-enabled builds to `-gpl` extension ([pull #950](https://github.com/bytedeco/javacpp-presets/pull/950))
* Upgrade presets for OpenCV 4.5.0, Arrow 2.0.0, MKL 2020.4, OpenBLAS 0.3.12, librealsense2 2.38.1 ([pull #946](https://github.com/bytedeco/javacpp-presets/pull/946)), DNNL 1.7, NumPy 1.19.4, SciPy 1.5.4, Gym 0.17.3, LLVM 11.0.0 ([pull #955](https://github.com/bytedeco/javacpp-presets/pull/955)), CUDA 11.1.1, cuDNN 8.0.4, TensorFlow 1.15.4, TensorRT 7.2.1.6, ONNX 1.8.0, ONNX Runtime 1.5.3, Qt 5.15.1, Skia 2.80.2, cpu_features 0.6.0, and their dependencies
* Upgrade presets for OpenCV 4.5.0, Arrow 2.0.0, MKL 2020.4, OpenBLAS 0.3.12, librealsense2 2.40.0 ([pull #946](https://github.com/bytedeco/javacpp-presets/pull/946)), DNNL 1.7, NumPy 1.19.4, SciPy 1.5.4, Gym 0.17.3, LLVM 11.0.0 ([pull #955](https://github.com/bytedeco/javacpp-presets/pull/955)), CUDA 11.1.1, cuDNN 8.0.4, TensorFlow 1.15.4, TensorRT 7.2.1.6, ONNX 1.8.0, ONNX Runtime 1.5.3, Qt 5.15.1, Skia 2.80.2, cpu_features 0.6.0, and their dependencies

### September 9, 2020 version 1.5.4
* Bundle `libpostal_data` program, executable via `Loader.load()` for convenience ([issue #939](https://github.com/bytedeco/javacpp-presets/issues/939))
Expand Down
6 changes: 3 additions & 3 deletions librealsense2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Introduction
------------
This directory contains the JavaCPP Presets module for:

* librealsense2 2.38.1 https://github.com/IntelRealSense/librealsense
* librealsense2 2.40.0 https://github.com/IntelRealSense/librealsense

Please refer to the parent README.md file for more detailed information about the JavaCPP Presets.

Expand All @@ -25,7 +25,7 @@ Here is a simple example of librealsense2 ported to Java from this C source file

* https://github.com/IntelRealSense/librealsense/blob/master/examples/C/distance/rs-distance.c

We can use [Maven 3](http://maven.apache.org/) to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the `pom.xml` and `TestConnection.java` source files below, simply execute on the command line:
We can use [Maven 3](http://maven.apache.org/) to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the `pom.xml` and `RsDistance.java` source files below, simply execute on the command line:
```bash
$ mvn compile exec:java
```
Expand All @@ -44,7 +44,7 @@ We can use [Maven 3](http://maven.apache.org/) to download and install automatic
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>librealsense2-platform</artifactId>
<version>2.38.1-1.5.5-SNAPSHOT</version>
<version>2.40.0-1.5.5-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down
2 changes: 1 addition & 1 deletion librealsense2/cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [[ -z "$PLATFORM" ]]; then
exit
fi

LIBREALSENSE2_VERSION=2.38.1
LIBREALSENSE2_VERSION=2.40.0
LIBUSB_VERSION=1.0.22
download https://github.com/IntelRealSense/librealsense/archive/v$LIBREALSENSE2_VERSION.tar.gz librealsense-$LIBREALSENSE2_VERSION.tar.gz
download http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-$LIBUSB_VERSION/libusb-$LIBUSB_VERSION.tar.bz2/download libusb-$LIBUSB_VERSION.tar.bz2
Expand Down
2 changes: 1 addition & 1 deletion librealsense2/platform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>org.bytedeco</groupId>
<artifactId>librealsense2-platform</artifactId>
<version>2.38.1-${project.parent.version}</version>
<version>2.40.0-${project.parent.version}</version>
<name>JavaCPP Presets Platform for librealsense2</name>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion librealsense2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>org.bytedeco</groupId>
<artifactId>librealsense2</artifactId>
<version>2.38.1-${project.parent.version}</version>
<version>2.40.0-${project.parent.version}</version>
<name>JavaCPP Presets for librealsense2</name>

<dependencies>
Expand Down
211 changes: 211 additions & 0 deletions librealsense2/samples/display/OpenCVFX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.WritableImage;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import java.nio.ByteBuffer;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.ArrayList;

import org.bytedeco.opencv.global.opencv_imgproc;
import org.bytedeco.opencv.opencv_core.Mat;


public class OpenCVFX {
private final static ArrayList<ImShowThread> list = new ArrayList<>();

public static void imshow(String name, Mat mat) {
if (mat.channels() == 1) opencv_imgproc.cvtColor(mat, mat, opencv_imgproc.COLOR_GRAY2BGR);
opencv_imgproc.cvtColor(mat, mat, opencv_imgproc.COLOR_BGR2RGB);
byte[] data = new byte[mat.cols() * mat.rows() * mat.channels()];
mat.data().get(data, 0, data.length);
imshow(name, data, mat.cols(), mat.rows());
}

public static void imshow(String name, byte[] data, int width, int height) {
if (data.length != width * height * 3) {
System.err.println("error: imshow() data length must be [width * height * 3]");
return;
}
synchronized (list) {
for (ImShowThread im : list) {
if (im.getName().equals(name)) {
im.addImage(data, 0, data.length, width, height);
return;
}
}
ImShowThread im = new ImShowThread(name);
im.start();
list.add(im);
im.addImage(data, 0, data.length, width, height);
}
}

public static int waitKey() {
synchronized (list) {
for (ImShowThread im : list) {
int key = im.getKey();
if (key != -1) {
return key;
}
}
return -1;
}
}

public static void destroyAllWindows() {
synchronized (list) {
for (int i = 0; i < list.size(); ++i) {
list.get(i).setDestroyAllWindows((i+1)==list.size());
list.get(i).stop();
}
list.clear();
}
}


static class ImShowThread implements Runnable {
private final String window_name;
private boolean loopFlag = true;
private final Thread thread = new Thread(this);
private static final int maxQueueSize = 3;
private final ArrayBlockingQueue<Cls> queue = new ArrayBlockingQueue<>(maxQueueSize);
private boolean isLaunch = false;
private boolean destroyAllWindows = true;
private Stage tmpStage = null;
private int keyCode;

public ImShowThread(String name) {
this.window_name = name;
}

public void start() {
this.thread.start();
}

public void stop() {
this.loopFlag = false;
try {
this.thread.interrupt();
this.thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

public String getName() {
return this.window_name;
}

public void setDestroyAllWindows(boolean flag) {
this.destroyAllWindows = flag;
}

public void addImage(byte[] data, int offset, int length, int width, int height) {
Cls cls = new Cls();
cls.data = new byte[length - offset];
ByteBuffer.wrap(data, offset, length).get(cls.data, 0, cls.data.length);
cls.width = width;
cls.height = height;
while (this.queue.size() >= maxQueueSize) {
this.queue.poll();
}
try {
this.queue.offer(cls, 10, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
System.out.println(String.format("warn %s:%s", e.getClass().getSimpleName(), e.getMessage()));
}
}

public int getKey() {
int result = this.keyCode;
this.keyCode = -1;
return result;
}

@Override
public void run() {
ImageView imageView = new ImageView();
WritableImage writableImage = new WritableImage(1, 1);
int width = 1;
int height = 1;
PixelFormat<ByteBuffer> pf = PixelFormat.getByteRgbInstance();
while (this.loopFlag) {
Cls cls;
try {
cls = this.queue.poll(50, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
sleep(30);
continue;
}
if (cls == null) {
sleep(30);
continue;
}
if (!this.isLaunch || width != cls.width || height != cls.height) {
try {
Platform.startup(() -> launchFxWindow(imageView, cls.width, cls.height, this.window_name));
} catch (IllegalStateException ise) {
System.out.println(String.format("warn %s:%s", ise.getClass().getSimpleName(), ise.getMessage()));
launchFxWindow(imageView, cls.width, cls.height, this.window_name);
}
width = cls.width;
height = cls.height;
writableImage = new WritableImage(width, height);
}
while (!this.isLaunch) {
sleep(100);
}

writableImage.getPixelWriter().setPixels(0, 0, width, height, pf, cls.data, 0, width * 3);
imageView.setImage(writableImage);
}
if (this.destroyAllWindows) {
Platform.runLater(Platform::exit);
}
}

private void sleep(long ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException ignored) {
}
}

private void launchFxWindow(ImageView iv, int w, int h, String name) {
Platform.runLater(() -> {
Scene scene = new Scene(new StackPane(iv), w, h);
Stage stage = new Stage();
stage.setTitle(name);
stage.showingProperty().addListener((obs, ov, nv) -> {
if (ov && !nv) {
this.isLaunch = false;
this.tmpStage = new Stage();
this.tmpStage.setScene(new Scene(new StackPane(), 1, 1));
this.tmpStage.show();
}
});
scene.addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> this.keyCode = keyEvent.getCode().getCode());
stage.setScene(scene);
stage.show();
if (this.tmpStage != null && this.tmpStage.isShowing()) {
this.tmpStage.close();
}
this.isLaunch = true;
});
}

static class Cls {
byte[] data;
int width;
int height;
}

}

}
Loading