1

大家好!

我在从松下 IP 摄像机以 JPEG 格式抓取图像时遇到问题,实际上问题出在 fps,因为 fps 始终保持 1 或 2 不超过它,但事实上摄像机最多支持 30 凸轮型号是 Panasonic WV-SP302E我正在使用以下 C# 代码来获取图像并将其显示在我的 winforms 应用程序中

public partial class Form1 : Form
{
    // indicates wether to prevent caching in case of a proxy server or not
    private bool preventCaching = false;                

    public Form1()
    {
        InitializeComponent();
    }

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        while (true)
        {
            this.pictureBox1.Image = this.GetSingleFrame(@"http://ipaddress/SnapshotJPEG?Resolution=320x240&Quality=Standard");                
        }
    }

    /// <summary>
    /// Get a single JPEG frame from the camera
    /// </summary>
    /// <param name="source">JPEG Stream source</param>
    /// <exception cref="WebException">If the IP camera is not receable or an error is occured</exception>
    /// <exception cref="Exception">If an unknown error occured</exception>
    public Bitmap GetSingleFrame(string source)
    {
        byte[] buffer = new byte[512 * 1024];   // buffer to read stream
        HttpWebRequest req = null;
        WebResponse resp = null;
        Stream stream = null;
        Random rnd = new Random((int)DateTime.Now.Ticks);

        try
        {
            int read, total = 0;

            // create request
            if (!preventCaching)
            {
                req = (HttpWebRequest)WebRequest.Create(source);
            }
            else
            {
                req = (HttpWebRequest)WebRequest.Create(source + ((source.IndexOf('?') == -1) ? '?' : '&') + "fake=" + rnd.Next().ToString());
            }
            // set login and password                
            req.Credentials = new NetworkCredential("root", "a");                

            req.Timeout = -1;

            resp = req.GetResponse();

            // get response stream
            stream = resp.GetResponseStream();

            // loop
            do
            {
                read = stream.Read(buffer, total, 1024);

                total += read;
            }
            while (read != 0);

            Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, total));

            return bmp;
        }
        catch (WebException ex)
        {
            string s = ex.ToString();
            return null;
        }
        catch (Exception ex)
        {
            string s = ex.ToString();
            return null;
        }
        finally
        {
            // abort request
            if (req != null)
            {
                req.Abort();
                req = null;
            }
            // close response stream
            if (stream != null)
            {
                stream.Close();
                stream = null;
            }
            // close response
            if (resp != null)
            {
                resp.Close();
                resp = null;
            }
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.backgroundWorker1.RunWorkerAsync();
    }
}

我什至使用 backgrounworker 组件在另一个线程中抓取图像,但仍然是 2 fps。知道如何提高fps

4

4 回答 4

1

自从提出问题以来已经有一段时间了,但从那时起它仍然是一样的。

相机在流模式下提供高达每秒 30 帧,但这并不一定适用于 JPEG 快照帧速率。与全速流相比,有效的 JPEG 速率可能或多或少慢,具体取决于相机型号。

对此您实际上无能为力(MPEG-4/H.264 相机通常以较低的速率发送 JPEG),您的选择是:

  • 通过接收视频源(可能是 RTSP 等标准协议,或通过 SDK 或相机供应商提供的某种 ActiveX 控件的专有协议)从相机获取图像
  • 用更合适的型号替换相机,每秒可以获得更多的 JPEG 快照
于 2011-10-04T18:26:24.093 回答
1

通常,您不能从 IP 摄像机查询超过几张 jpeg 图像/秒。如果您想要 30fps 的视频流,则需要查询运动 jpeg 之类的“视频”流,而不是快照流。

于 2018-10-27T15:04:23.833 回答
0

看起来你有相当多的设置来让这个流继续下去。将分配从那里取出,这样您就不会不断地分配和释放将有所帮助。

一旦你得到了流,读取多个帧可能会有所帮助(即从你的数据采集循环中产生位图)。仅供参考,您不应该从非 gui 线程调用 GUI 操作。使用 ReportProgress 发回数据。

你确定是捕获而不是显示它需要时间吗?您是否尝试过删除绘图代码进行测试?

于 2011-04-12T15:35:59.937 回答
-1

确保您对场景进行了充分的照明。简单且有些不准确的解释是,自动曝光模式下的数码相机会等到它们捕捉到足够的光线,而在传感器效率低下的黑暗场景(如夜晚的黑暗房间)中,这需要一段时间。在明亮的房间或户外白天尝试使用相机,看看您的帧速率是否有所提高。

于 2011-04-12T19:29:18.667 回答