Java 网络摄像头应用程序在后台保持运行

发布于 2025-01-08 04:39:19 字数 4401 浏览 1 评论 0原文

我有一个简单的应用程序,可以打开网络摄像头并将实时信息显示在屏幕上。如果用户单击图像,则该帧将以 .png 格式保存在硬盘中。但问题是应用程序第一次运行正常。但是当我重新启动它时,它失败了

Myron BETA 2.4

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x003744a0, pid=5688, tid=1328
#
# JRE version: 7.0_02-b13
# Java VM: Java HotSpot(TM) Client VM (22.0-b10 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [myron_ezcam.dll+0x44a0]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# F:\javacode\libraries\webcam\JMyron0025\JMyron_SimpleCamera_Eclipse\JMyron_SimpleCamera\hs_err_pid5688.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

我正在使用 myron,这是我的代码,

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Timer;
import javax.swing.JComponent;
import javax.swing.JFrame;
import JMyron.*;

public class SimpleCamera extends JFrame
{
    JMyron m;//a camera object
    int width = 320;
    int height = 240;
    VideoPane vp;
    int frameRate = 15; //fps

    public static void main(String[] args)
    {
        SimpleCamera sc = new SimpleCamera("0021");
        sc.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    public SimpleCamera(final String id)
    {
        setSize(width,height);
        m = new JMyron();//make a new instance of the object
        m.start(width,height);//start a capture at 320x240
        m.findGlobs(1);//disable the intelligence to speed up frame rate
        System.out.println("Myron " + m.version());

        final Timer videoTimer = new Timer(1000/frameRate, new ActionListener()
        {
            public void actionPerformed(ActionEvent evt)
            {
                vp.repaint();
            }

        });

        vp = new VideoPane();
        vp.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent arg0) {
                File file = new File("E:\\"+id+".png");

                BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                int[] img = m.image(); //get the normal image of the camera
                bi.setRGB(0,0,width,height,img,0,width);
                try {
                    ImageIO.write(bi, "png",file);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                System.out.println("Click");
                videoTimer.stop();
                setVisible(false);
                setEnabled(false);
                m.stop();


            }

            @Override
            public void mouseEntered(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mousePressed(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseReleased(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        });
        getContentPane().add(vp);       

        videoTimer.start();     
        setVisible(true);
        setEnabled(true);


    }

    class VideoPane extends JComponent
    {
        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        public void paint(Graphics g)
        {
            m.update();//update the camera view
            int[] img = m.image(); //get the normal image of the camera
            bi.setRGB(0,0,width,height,img,0,width);
            g.drawImage(bi, 0, 0, width, height, this);
        }
    }
}

我可以看到 javaw 进程在进程管理器中保持运行。这可能意味着我有一些进程正在运行,因为一旦我从 Windows 任务管理器终止该进程,我就可以正确运行该程序。请帮助我,我真的被截止日期困住了。

I have a simple application that opens up the webcam and puts the live feed on the screen. If a user clicks on the image then the frame is saved a .png in the hard drive. But the problem is the application runs properly for the first time. But when i restart it it fails

Myron BETA 2.4

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x003744a0, pid=5688, tid=1328
#
# JRE version: 7.0_02-b13
# Java VM: Java HotSpot(TM) Client VM (22.0-b10 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [myron_ezcam.dll+0x44a0]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# F:\javacode\libraries\webcam\JMyron0025\JMyron_SimpleCamera_Eclipse\JMyron_SimpleCamera\hs_err_pid5688.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

I am using myron and here is my code

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Timer;
import javax.swing.JComponent;
import javax.swing.JFrame;
import JMyron.*;

public class SimpleCamera extends JFrame
{
    JMyron m;//a camera object
    int width = 320;
    int height = 240;
    VideoPane vp;
    int frameRate = 15; //fps

    public static void main(String[] args)
    {
        SimpleCamera sc = new SimpleCamera("0021");
        sc.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    public SimpleCamera(final String id)
    {
        setSize(width,height);
        m = new JMyron();//make a new instance of the object
        m.start(width,height);//start a capture at 320x240
        m.findGlobs(1);//disable the intelligence to speed up frame rate
        System.out.println("Myron " + m.version());

        final Timer videoTimer = new Timer(1000/frameRate, new ActionListener()
        {
            public void actionPerformed(ActionEvent evt)
            {
                vp.repaint();
            }

        });

        vp = new VideoPane();
        vp.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent arg0) {
                File file = new File("E:\\"+id+".png");

                BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                int[] img = m.image(); //get the normal image of the camera
                bi.setRGB(0,0,width,height,img,0,width);
                try {
                    ImageIO.write(bi, "png",file);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                System.out.println("Click");
                videoTimer.stop();
                setVisible(false);
                setEnabled(false);
                m.stop();


            }

            @Override
            public void mouseEntered(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mousePressed(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseReleased(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        });
        getContentPane().add(vp);       

        videoTimer.start();     
        setVisible(true);
        setEnabled(true);


    }

    class VideoPane extends JComponent
    {
        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        public void paint(Graphics g)
        {
            m.update();//update the camera view
            int[] img = m.image(); //get the normal image of the camera
            bi.setRGB(0,0,width,height,img,0,width);
            g.drawImage(bi, 0, 0, width, height, this);
        }
    }
}

I can see that a javaw process keeps running in the process manager. That probably means i have some process running becaus once i terminate that process from windows task manager i can run the program properly. Please help i am real stuck on a deadline.

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

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

发布评论

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

评论(1

半夏半凉 2025-01-15 04:39:19
public SimpleCamera(final String id) {
  setSize(width,height);

  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  //add this line where above line present in your code
}
public SimpleCamera(final String id) {
  setSize(width,height);

  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  //add this line where above line present in your code
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文