如何从IP摄像机获取更高Fps的JPEG格式的图像
||
大家好!
从JPEG格式的Panasonic IP摄像机中抓取图像时遇到问题,实际上是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 个回复
绊伦欧
械怒等
姬第柔炒
唤副埂侧壬