0

I use OpenImaj for a project and I need to display the video in 800*600 to a panel but I must capture images at 1920,1080 when I click a button.

My strategy was initially to capture from my webcam at 1920,1080 and to resize image in a icon of a label contained in my panelVideo.

My problem is that the performance is very low.

Is there an efficient method to resize video according to the size of panelVideo without changing the frame size (that I use for saving the image at 1920,1080)? Thank you for your answer. Regards.

final VideoCapture vc = new VideoCapture(1920,1080);
vc.setFPS(10);
final VideoDisplay<MBFImage> display = VideoDisplay.createVideoDisplay(vc, panelVideo);
display.addVideoListener(new VideoDisplayAdapter<MBFImage>()
                    {
                        @Override
                        public void beforeUpdate(final MBFImage frame)
                        {
                             //here I create a bufferedImage from the resized frame
                                BufferedImage img = new BufferedImage(800, 600, BufferedImage.TYPE_INT_ARGB);
                                Graphics2D g = (Graphics2D) img.getGraphics();
                                g.drawImage(ImageUtilities.createBufferedImageForDisplay(frame), 0, 0, 800, 600, null);

                             //here is the label that I use to display the video
                                labelVideo.setIcon(new ImageIcon(ImageUtilities.createBufferedImageForDisplay(frame)));

                        }
                    });

2 Answers2

0

You can at least remove fixed code like this out of the loop - that is create it only once

 //here I create a bufferedImage from the resized frame
 BufferedImage img = new BufferedImage(800, 600, BufferedImage.TYPE_INT_ARGB);
 Graphics2D g = (Graphics2D) img.getGraphics();

and also have the Icon created once and setImage() as needed. Beyond that I dont know how to convert MBF to BufferedImage thats the pain of using different libraries. g.drawImage() is a good way to draw the scaled image.

gpasch
  • 2,672
  • 3
  • 10
  • 12
0

See http://openimaj.org/apidocs/org/openimaj/image/processing/resize/package-frame.html for the OpenIMAJ classes that let you resize an MBFImage. You'll have to play and see what is fastest, but in my very quick experiments I found BilinearInterpolation to be better than ResizeProcessor with the default options, however using a different filter in ResizeProcessor might be faster.

Rather than creating a new BufferedImage each frame, you would probably be better off drawing the MBFImage into a Swing component that displays them directly: http://openimaj.org/apidocs/org/openimaj/image/DisplayUtilities.ScalingImageComponent.html or http://openimaj.org/apidocs/org/openimaj/image/DisplayUtilities.ImageComponent.html (note that technically these both convert to BufferedImage behind the scenes, but they only allocate the image once and just redraw into it saving a lot of time).

Jon
  • 841
  • 4
  • 5