使用 JMF、Java 进行快速 24 位 RGB 到灰度转换

发布于 2024-09-26 00:55:04 字数 852 浏览 1 评论 0原文

我正在用 Java 开发一个简单的(或者至少是这么认为的)桌面应用程序,用于实时图像处理。我选择使用 Java Media Framework (JMF) 访问视频帧。我有一台 PAL 相机并使用 EasyCAP 视频转换器进行数字化。该设备在我的 Windows 计算机上作为 VFW 设备可见,允许 YUV 和 24 位 RGB 格式采集(32 位不可用)。

我已经弄清楚了框架的基础知识。我使用 javax.media.Processor 进行媒体数据控制,并且一开始想要添加灰度编解码器(实现 javax.media.Codec)用于进一步渲染。在编解码器中,我可以将各个帧作为 javax.media.Buffer 对象访问。

在 Java 中进行灰度转换的最快方法是什么? 我想坚持 JAI 等标准,因为我希望能够使用相同的标准轻松进行进一步的转换框架/方法。

到目前为止,我一直在考虑以下问题:

在编解码器链的开头添加一个编解码器,以将 24 位 RGB 转换为 32 位 RGB。而不是使用 java.nio.ByteBuffer 将 byte[] 转换为 int[] 像素数组,以便使用 javax.awt.image 过滤器进行进一步处理。我已经尝试使用 com.sun.media.codec.video.colorspace.RGBConverter 来实现这一目标,但没有成功。

我真的很感激任何帮助,希望有人已经这样做了。

对于有关整体应用程序架构的任何建议,我也将不胜感激。我的总体目标是在 Java 中实现光流算法,以便能够仅使用视觉输入实时估计相机姿态。

I'm developing a simple (or at least thought so) desktop application in Java for real-time image processing. I've chosen to access video frames using the Java Media Framework (JMF). I have a PAL camera and use EasyCAP video converter for digitizing. The device is visible on my Windows machine as a VFW device, allowing for YUV and 24-Bit RGB format acquisitions (32-Bit not available).

I already figured out the basics of the framework. I'm using a javax.media.Processor for media-data controlling and, for the beginning, wanted to add a grayscale-codec (implementing javax.media.Codec) for further rendering. In the codec I can access individual frames as javax.media.Buffer objects.

What is the fastest way to do the grayscale conversion in Java? I'd like to stick to some standard like JAI or so, as I'd like to be able to easily do further conversions using the same framework / methods.

I've been considering the following until now:

Adding a codec on the beginning of the codec chain to convert 24-Bit RGB to 32-Bit RGB. Than using java.nio.ByteBuffer to cast byte[] to int[] pixel-array for further processing with javax.awt.image filters. I've already tried to use com.sun.media.codec.video.colorspace.RGBConverter to achieve that, without success, though.

I'd be really grateful for any help, hope anyone has already done that.

I'd be grateful for any suggestions regarding overall application architecture as well. My general goal is to implement an Optical Flow algorithm in Java to be able to estimate camera attitude in real-time using visual input only.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橪书 2024-10-03 00:55:04

看看 JH Labs 的这个库 ( http://www.jhlabs.com/ip /filters/index.html )。
它可以通过源代码获得。您可以在那里检查实现...特别是 GrayscaleFilter.. 另外,在使用前检查许可证。如果您喜欢,请注明原作者。:)

Have a look at this library at JH Labs ( http://www.jhlabs.com/ip/filters/index.html ).
It is available with source code. You can check the implementation there... specifically GrayscaleFilter.. Also Check the license before use. If you like it then please give credit to the original author.. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文