简体   繁体   English

如何从IP摄像机以更高的Fps捕获JPEG格式的图像

[英]How to grab images in JPEG format in higher Fps from IP Camera

Hy Everyone! 大家好!

I am having a problem in grabbing images from a Panasonic IP Camera in JPEG format infact the problem is with the fps because the fps is always remains 1 or 2 not more than it but infact camera supports upto 30 the cam model is Panasonic WV-SP302E i am using the following C# code to grab the image and display it in my winforms app 我在从Panasonic 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();
    }
}

I am even using the backgrounworker component to grab images in another thread but still 2 fps. 我什至使用backgrounworker组件在另一个线程中抓取图像,但仍为2 fps。 Any idea how to increase the fps 任何想法如何增加fps

Usually you can't query more than few jpeg images / second from an IP camera. 通常,您每秒从IP摄像机查询的jpeg图像不超过几个。 If you want a video stream with 30fps, you need to query a "video" stream like motion jpeg, not a snapshot stream. 如果您想要30fps的视频流,则需要查询运动jpeg之类的“视频”流,而不是快照流。

It has been quite some time since the question, but it is still all the same since then. 自问这个问题以来已经有一段时间了,但是从那以后仍然是一样的。

The camera offers up to 30 frames per second in streaming mode, however this does not necessarily apply to JPEG snapshot frame rate. 相机在流传输模式下每秒最多可提供30帧,但是这不一定适用于JPEG快照帧速率。 Depending on camera model effective JPEG rate might be more or less slower as compared to full speed streaming. 根据相机型号的不同,有效JPEG速率可能会比全速流更快或更慢。

There is little you can actually do about this (it is typical for MPEG-4/H.264 camera to send JPEGs at lower rate), your options are: 您实际上无能为力(对于MPEG-4 / H.264摄像机来说,以较低的速率发送JPEG通常是这样),您可以选择:

  • acquire images from camera through receiving a video feed (which may be a standard protocol like RTSP, or a proprietary protocol through SDK or sort of ActiveX control from camera vendor) 通过接收视频提要(可以是RTSP之类的标准协议,也可以是通过SDK的专有协议或相机供应商提供的ActiveX控件)从相机获取图像
  • replace the camera with a more appropriate model which gets you more JPEG snapshots per second 用更合适的型号替换相机,每秒可获得更多的JPEG快照

Looks like you have quite a bit of set up to get that stream going. 看起来您已经进行了很多设置,以使该流继续进行。 Taking the allocation out of there so you're not constantly allocating and freeing will help. 从那里取出分配,这样您就不会不断分配和释放资源会有所帮助。

Reading multiple frames once you've got the stream going will probably help (ie yielding bitmaps from within your data acquisition loop). 一旦流完成,读取多个帧可能会有所帮助(即从数据采集循环中生成位图)。 FYI, you shouldn't be calling GUI operations from a non-gui thread. 仅供参考,您不应该从非GUI线程调用GUI操作。 Use ReportProgress to send the data back. 使用ReportProgress将数据发送回去。

Are you certain it's the capture that's taking the time as opposed to displaynig it? 您确定是花些时间而不是displaynig来捕获它吗? Have you tried removing the drawing code to test? 您是否尝试过删除绘图代码进行测试?

Make sure you're lighting the scene adequately. 确保您充分照明了场景。 The simple and somewhat inaccurate explanation is that digital cameras in auto exposure mode will wait until they have captured enough light, which in a dark scene (like a dark room at night) with an inefficient sensor will take a while. 简单且有点不准确的解释是,处于自动曝光模式的数码相机将等待,直到它们捕获了足够的光线,而在黑暗的场景中(例如夜晚的黑暗房间),传感器效率低下将花费一段时间。 Try the camera in a lighter room, or outside in the daylight, and see if your frame rate improves. 在更明亮的房间或白天在室外尝试使用相机,看看帧频是否提高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM