v4lvj在网络摄像头图像上绘制线条

时间:2012-09-05 01:36:53

标签: java webcam v4l

我正在关注v4lvj库的教程,该库允许访问Linux上的网络摄像头。 link to source我编写的示例程序基本上显示了您的webcamera的视频源。一切都像程序描述的那样起作用。当我尝试通过在视频源上添加绿线来改变程序时出现问题。我只是以相同的方式抓取图形,设置线条颜色然后绘制线条。

@Override
        public void nextFrame(VideoFrame frame) {
                // This method is called when a new frame is ready.
                // Don't forget to recycle it when done dealing with the frame.

                // draw the new frame onto the JLabel
                label.getGraphics().drawImage(frame.getBufferedImage(), 0, 0, width, height, null);
                label.getGraphics().setColor(Color.GREEN); //this line causes exceptions
                label.getGraphics().drawLine(0, 0, 640, 480); //this line causes exceptions 

                // recycle the frame
                frame.recycle();
        }

当我这样做时,我得到一些例外,前面是“看起来你的JVM无法解码这个图像。支持的图像类型:BMP bmp jpg JPG ...”然后

javax.imageio.IIOException: Unsupported marker type 0x5a
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1176)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:984)
    at javax.imageio.ImageIO.read(ImageIO.java:1438)
    at javax.imageio.ImageIO.read(ImageIO.java:1342)
    at au.edu.jcu.v4l4j.JPEGVideoFrame.refreshBufferedImage(Unknown Source)
    at au.edu.jcu.v4l4j.BaseVideoFrame.getBufferedImage(Unknown Source)
    at SimpleViewer.nextFrame(SimpleViewer.java:143)
    at au.edu.jcu.v4l4j.PushSource.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:679)
au.edu.jcu.v4l4j.exceptions.V4L4JException: Exception received while grabbing next frame
    at au.edu.jcu.v4l4j.PushSource.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:679)
Caused by: au.edu.jcu.v4l4j.exceptions.UnsupportedMethod: Unable to decode the image
    at au.edu.jcu.v4l4j.JPEGVideoFrame.refreshBufferedImage(Unknown Source)
    at au.edu.jcu.v4l4j.BaseVideoFrame.getBufferedImage(Unknown Source)
    at SimpleViewer.nextFrame(SimpleViewer.java:143)
    ... 2 more
Caused by: javax.imageio.IIOException: Unsupported marker type 0x5a
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1176)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:984)
    at javax.imageio.ImageIO.read(ImageIO.java:1438)
    at javax.imageio.ImageIO.read(ImageIO.java:1342)
    ... 5 more

有人可以告诉我为什么,并帮助我在视频输入上画一条线。谢谢。

1 个答案:

答案 0 :(得分:0)

你应该通过覆盖paint(Graphics g) JLabel方法进行绘画, 然后进行演员Graphics2D g2d = (Graphics2D) g;并使用Graphics2D进行绘画。

在代码中使用JLabel是不正确的。

您也可以使用从框架中收到的BufferedImage,获取他们的Graphics并在其上绘图