みなさん、こんにちは!
JPEG形式でパナソニックIPカメラから画像を取得する際に問題が発生しました。fpsは常に1または2以下であるため、問題はfpsにありますが、実際のカメラは最大30をサポートします。カムモデルはパナソニック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コンポーネントを使用して、別のスレッドで画像を取得していますが、それでも2fpsです。fpsを上げる方法についてのアイデア