简体   繁体   English

使用JMF,Java将24位RGB快速转换为灰度

[英]Fast 24-bit RGB to Grayscale conversion with JMF, Java

I'm developing a simple (or at least thought so) desktop application in Java for real-time image processing. 我正在用Java开发一个简单的(或至少是这样认为的)桌面应用程序来进行实时图像处理。 I've chosen to access video frames using the Java Media Framework (JMF). 我选择使用Java Media Framework(JMF)访问视频帧。 I have a PAL camera and use EasyCAP video converter for digitizing. 我有一个PAL相机,并使用EasyCAP视频转换器进行数字化。 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). 该设备在Windows机器上作为VFW设备可见,允许进行YUV和24位RGB格式的采集(不提供32位)。

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. 我正在使用javax.media.Processor进行媒体数据控制,并且从一开始就想添加灰度编解码器(实现javax.media.Codec )以进行进一步渲染。 In the codec I can access individual frames as javax.media.Buffer objects. 在编解码器中,我可以将单个帧作为javax.media.Buffer对象进行访问。

What is the fastest way to do the grayscale conversion in Java? 用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. 我想坚持使用诸如JAI之类的标准,因为我希望能够使用相同的框架/方法轻松地进行进一步的转换。

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. 在编解码器链的开头添加编解码器,以将24位RGB转换为32位RGB。 Than using java.nio.ByteBuffer to cast byte[] to int[] pixel-array for further processing with javax.awt.image filters. 比起使用java.nio.ByteBuffer将byte []转换为int []像素数组进行进一步的处理,使用javax.awt.image过滤器。 I've already tried to use com.sun.media.codec.video.colorspace.RGBConverter to achieve that, without success, though. 我已经尝试使用com.sun.media.codec.video.colorspace.RGBConverter实现此目标,但没有成功。

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. 我的总体目标是在Java中实现“光流”算法,以便仅使用视觉输入即可实时估算相机姿态。

Have a look at this library at JH Labs ( http://www.jhlabs.com/ip/filters/index.html ). 看看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. 您可以在此处检查实施情况...特别是GrayscaleFilter ..另外,在使用前请检查许可证。 If you like it then please give credit to the original author.. :) 如果喜欢的话,请感谢原始作者.. :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM