问题
I'm working on a machine vision project where I would like to use Java despite the benefits of working in a native environment due to the long term goal of developing a plugin to a pre-existing framework which is written in Java.
Currently, I'm using a machine vision camera which streams 12MP images over a USB 3.0 bus at approximately 7 FPS, and may in the future go to higher resolution cameras (>29 MP).
The native libraries I'm are using are in c which I have already successfully been able to "wrap" using JNA + JNAerator.
I am working exclusively in a Windows 64 bit environment.
I've already proven that we can successfully capture raw BGR byte[]'s from the native library, dump them into a BufferedImage and display in an AWT Frame at an update rate very near the speed of a strictly c implementation. Here's an example of how I am currently converting to a BufferedImage which should give some sense as to the low level data I currently have access too:
byte[] pixels = new byte[rawImageSize * 3]; // *3 for B,G,R
rawImage.getData().get(pixels);
// Turn into buffered image
BufferedImage image = new BufferedImage(rawImageWidth, rawImageHeight,
BufferedImage.TYPE_3BYTE_BGR);
byte[] imageData = ( (DataBufferByte) image.getRaster().getDataBuffer() ).getData();
System.arraycopy(pixels, 0, imageData, 0, pixels.length);
Now the trick is that since these are 12MP images, they cannot be conveniently viewed on screen because they need to be scaled down. I attempted to scale the BufferedImage using examples found elsewhere, but obviously there is a huge performance hit when scaling images using the CPU. Further, I'd like for the user to be able to dynamically zoom in and out of the images as they are updating without noticing a significant performance hit.
My thought is that the best option for going forward would be to use an OpenGL implementation for Java and hand off the work of scaling and zooming the images to the GPU.
I unfortunately have very limited experience working with OpenGL, let alone leveraging it in Java. I'm specifically seeking guidance/answers for:
- Given that I have access to the raw byte[]'s of the images, is OpenGL the right step forward?
- In looking at OpenGL implementations for Java I'm considering LWJGL. Is this the lowest barrier to entry option?
- Are there meaningful examples of something similar somewhere?
Thanks!
来源:https://stackoverflow.com/questions/32641831/implementation-paradigm-for-efficiently-streaming-zoomable-images-from-machine-v