macos 如何使用 Java 访问 Kinect?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11575667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 09:21:32  来源:igfitidea点击:

How can I access the Kinect using Java?

javamacoskinectprocessing

提问by Alex

I am currently in a Computer Vision course and for my final project I am going to make a small game that interacts with the Kinect.

我目前正在学习计算机视觉课程,对于我的最终项目,我将制作一个与 Kinect 交互的小游戏。

Now I want to make this game in Java as I have never really ventured into making a game before and I am very comfortable with the Language. But I cannot seem to find a way to just access the Depth data (I just need to pack it into some Java Data structure) and the RGB data (same idea).

现在我想用 Java 制作这款游戏​​,因为我之前从未真正冒险制作过一款游戏,而且我对 Java 语言非常熟悉。但是我似乎找不到一种方法来访问深度数据(我只需要将它打包到一些 Java 数据结构中)和 RGB 数据(相同的想法)。

Right now, I have a way to 'talk' to the Kinect. I followed thistutorial and can detect the kinect using the command glviewin terminal.

现在,我有办法与 Kinect 进行“交谈”。我遵循了教程,可以使用glview终端中的命令检测 kinect 。

I have a thing called Processingwhich promised to be a Java library to let me use the Kinect but it is using it's own language which is 'built' using Java so it's not really Java which means I can't use all the GUI and normal Java features.

我有一个叫做Processing的东西,它承诺是一个 Java 库,让我可以使用 Kinect,但它使用的是自己的语言,它是用 Java“构建”的,所以它不是真正的 Java,这意味着我不能使用所有的 GUI 和正常的Java 特性。

What I want to do is somehow call some import random.Kinect.code;at the top of the Java program that lets me use the most basic Kinect features, like getDepth() or getRGB() and do everything else in Java.

我想要做的是import random.Kinect.code;在 Java 程序的顶部以某种方式调用一些让我使用最基本的 Kinect 功能,如 getDepth() 或 getRGB() 并在 Java 中完成其他所有事情。

Does anyone know a way I can do this? (BTW I'm running MAC OSX Lion)

有谁知道我可以这样做的方法吗?(顺便说一句,我正在运行 MAC OSX Lion)

采纳答案by George Profenza

If you're using Processing I recommend using one of the available wrappers:

如果您正在使用 Processing,我建议您使用其中一种可用的包装器:

Both are well documented and include plenty of helpful examples.

两者都有很好的文档记录,并包含大量有用的示例。

simpleOpenNI sample

简单的OpenNI示例

回答by Angelos B

I had exactly the same problem. I wanted to use Kinect in Java for my Computer Vision research, and I had a Mac OSX Lion like you. The solution that I found is to run a virtual copy of Windows 7 in my Mac (using VMWare or Parallels or Microsoft HyperV) and then use the open source J4K Java for Kinect library, which is a Java binding for the Kinect SDK using the Java Native Interface (JNI). Of course you can also use this open source library directly in computers that run Windows.

我遇到了完全相同的问题。我想在 Java 中使用 Kinect 进行我的计算机视觉研究,我有一个像你一样的 Mac OSX Lion。我找到的解决方案是在我的 Mac 中运行 Windows 7 的虚拟副本(使用 VMWare 或 Parallels 或 Microsoft HyperV),然后使用开源 J4K Java for Kinect 库,这是使用 Java 的 Kinect SDK 的 Java 绑定本机接口 (JNI)。当然你也可以直接在运行Windows的电脑上使用这个开源库。

The J4K Java library for Kinect also has a tutorial on how to write a kinect based application in just 10 lines of Java code.

Kinect 的 J4K Java 库也有一个教程,介绍如何仅用 10 行 Java 代码编写基于 kinect 的应用程序。

There are also several source code examples that shows you how to read depth, video, and skeleton data from the Kinect and use them in Java classes. You can also use multiple Kinects, animate avatars, and other examples. The link to the source code examples is here.

还有几个源代码示例向您展示了如何从 Kinect 读取深度、视频和骨架数据并在 Java 类中使用它们。您还可以使用多个 Kinect、动画化身和其他示例。源代码示例的链接在这里

A screenshot of the open source Kinect Viewer, which is useful for Computer Vision applications like yours is below:enter image description here

下面是开源 Kinect 查看器的屏幕截图,它对像您这样的计算机视觉应用程序很有用:在此处输入图片说明

I hope that this information helped.

我希望这些信息有帮助。

回答by Yair Zaslavsky

I will give you some ideas, but I admit - I did no try them with Kinect.
You question can be categorized under questions of "How to access some hardware via Java". The tutorial you presented us presents libraries for accessing Kinect, and even wrappers for Python.
What you can do is see how the Python code implemented the wrappers, and use either JNI/JNA to build your own wrappers.
In addition, I looked into the JNectproject, mentioned here in another answer, posted by @npinti.
The eclipse plugin has two parts of it -
the JNI code, which wraps theo riginal SDK code, and the Ecipse RCP code for the eclipse plugin itself.
I would recommend you to ignore the Eclipse RCP part, and focus on their JNI implementation as a reference to what you need to develop your own JNI wrapper.
Even if this is windows-based implementation (i.e - Kinect SDK works on windows, and you need to do run your code on mac, for example) - I think that by reading their code + some JNI tutorials + the python wrappers at the link you provided you will understand how to create a JNI wrapper to the library presented in the link you provided.
In addition, consider using JNAand not JNI as a way to communicate with hardware, I find it easier.
One last option is maybe to use the Java Script Engineand to invoke Python code (the python wrappers) from your java vode - not sure how much it will help you, but you can give it a shot.

我会给你一些想法,但我承认 - 我没有用 Kinect 尝试它们。
您的问题可以归类在“如何通过 Java 访问某些硬件”的问题下。您向我们展示的教程介绍了用于访问 Kinect 的库,甚至是 Python 的包装器。
您可以做的是查看 Python 代码如何实现包装器,并使用 JNI/JNA 构建您自己的包装器。
此外,我查看了JNect项目,该项目在@npinti发布的另一个答案中提到。
eclipse 插件有两部分 -
JNI 代码,它包装了原始 SDK 代码,以及 eclipse 插件本身的 Ecipse RCP 代码。
我建议您忽略 Eclipse RCP 部分,并将重点放在它们的 JNI 实现上,作为开发您自己的 JNI 包装器所需内容的参考。
即使这是基于 Windows 的实现(即 - Kinect SDK 可在 Windows 上运行,并且您需要在 mac 上运行您的代码,例如) - 我认为通过阅读他们的代码 + 一些 JNI 教程 + 链接中的 python 包装器您提供了您将了解如何为您提供的链接中提供的库创建 JNI 包装器。
另外,考虑使用JNA而不是 JNI 作为与硬件通信的一种方式,我发现它更容易。
最后一个选择可能是使用Java Script Engine并从您的 java vode 调用 Python 代码(python 包装器)-不确定它对您有多大帮助,但您可以试一试。