Image Proccessing Optmization?processing optimization
I'm using Winforms C# .netNET 3.5.
I'm getting frames, and this is hiwo ihow I handle them:
AnyIs there any way to optimize? Improve Preformence or improve performance?
I'm getting low preformenceperformance when my image is 320x240 and i'mI'm stretching it to 1280x1024, But the same image on 640x480 and strechingstretching to 1280x1024 wont get much loseloss in preforemnce.performance.
I tried to use WPF and still same preformence lose.performance loss. thatThat is weird because WPF supposeis supposed to use DirectX and be fast in image proccessingprocessing.
Image Proccessing Optmization?
I'm using Winforms C# .net 3.5.
I'm getting frames and this is hiwo i handle them:
Any way to optimize? Improve Preformence?
I'm getting low preformence when my image is 320x240 and i'm stretching it to 1280x1024, But the same image on 640x480 and streching to 1280x1024 wont get much lose in preforemnce..
I tried to use WPF and still same preformence lose.. that is weird because WPF suppose to use DirectX and be fast in image proccessing.
Image processing optimization
I'm using Winforms C# .NET 3.5. I'm getting frames, and this is how I handle them:
Is there any way to optimize or improve performance?
I'm getting low performance when my image is 320x240 and I'm stretching it to 1280x1024, But the same image on 640x480 and stretching to 1280x1024 wont get much loss in performance.
I tried to use WPF and still same performance loss. That is weird because WPF is supposed to use DirectX and be fast in image processing.
Update:
I removed the HighQualitiy like Ed said and i get better preformence.
Here are some tests:
enter image description here
I must add that i use AForge to get the MJPEG Stream from a webcam and the event raises everytime i get a frame from the Stream.
Now i still get my problem, i get 320x240 frame from the webcam, when i drawing that in normal size i get 3300ms (per 100 frames) i get zero delay when i clap my hands infront of the camera. and when i'm drawing it Full Screen i get 4500ms thats ok, 4500ms it's still good for 100 frames but i get like 3 seconds delay when i clap my hands infront of the camera..
All these test results are according to my new code:
delegate void videoStream_NewFrameDelegate(object sender, NewFrameEventArgs eventArgs);
public void videoStream_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
if (ready)
{
if (this.InvokeRequired)
{
videoStream_NewFrameDelegate del = new videoStream_NewFrameDelegate(videoStream_NewFrame);
this.Invoke(del, new object[] {sender, eventArgs} );
}
else
{
if(!sw.IsRunning)
sw = Stopwatch.StartNew();
this.FPScount++;
Rectangle rc = ClientRectangle;
Bitmap bmp = new Bitmap(rc.Width, rc.Height);
Graphics g = Graphics.FromImage((Image)bmp);
g.DrawImage(eventArgs.Frame, rc.X+10, rc.Y+10, rc.Width-20, rc.Height-20);
g.Dispose();
this.Image = (Image)bmp;
}
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
{
base.OnPaint(pe);
this.calc = fps.TotalMilliseconds;
if (this.FPScount >= 100 && this.sw.IsRunning)
{
this.fps = TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
this.FPScount = 0;
this.sw.Reset();
}
}
Update:
I removed the HighQualitiy like Ed said and i get better preformence.
Here are some tests:
enter image description here
I must add that i use AForge to get the MJPEG Stream from a webcam and the event raises everytime i get a frame from the Stream.
Now i still get my problem, i get 320x240 frame from the webcam, when i drawing that in normal size i get 3300ms (per 100 frames) i get zero delay when i clap my hands infront of the camera. and when i'm drawing it Full Screen i get 4500ms thats ok, 4500ms it's still good for 100 frames but i get like 3 seconds delay when i clap my hands infront of the camera..
All these test results are according to my new code:
delegate void videoStream_NewFrameDelegate(object sender, NewFrameEventArgs eventArgs);
public void videoStream_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
if (ready)
{
if (this.InvokeRequired)
{
videoStream_NewFrameDelegate del = new videoStream_NewFrameDelegate(videoStream_NewFrame);
this.Invoke(del, new object[] {sender, eventArgs} );
}
else
{
if(!sw.IsRunning)
sw = Stopwatch.StartNew();
this.FPScount++;
Rectangle rc = ClientRectangle;
Bitmap bmp = new Bitmap(rc.Width, rc.Height);
Graphics g = Graphics.FromImage((Image)bmp);
g.DrawImage(eventArgs.Frame, rc.X+10, rc.Y+10, rc.Width-20, rc.Height-20);
g.Dispose();
this.Image = (Image)bmp;
}
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
{
base.OnPaint(pe);
this.calc = fps.TotalMilliseconds;
if (this.FPScount >= 100 && this.sw.IsRunning)
{
this.fps = TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
this.FPScount = 0;
this.sw.Reset();
}
}
delegate void videoStream_NewFrameDelegate(object sender, NewFrameEventArgs eventArgs);
public void videoStream_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
if (ready)
{
if (this.InvokeRequired)
{
videoStream_NewFrameDelegate del = new videoStream_NewFrameDelegate(videoStream_NewFrame);
this.Invoke(del, new object[] {sender, eventArgs} );
}
else
{
if(!sw.IsRunning)
sw = Stopwatch.StartNew();
this.FPScount++;
Rectangle rc = ClientRectangle;
Bitmap bmp = new Bitmap(rc.Width, rc.Height);
Graphics g = Graphics.FromImage((Image)bmp);
g.DrawImage(eventArgs.Frame, rc.X+10, rc.Y+10, rc.Width-20, rc.Height-20);
g.Dispose();
this.Image = (Image)bmp;
}
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
{
base.OnPaint(pe);
this.calc = fps.TotalMilliseconds;
if (this.FPScount >= 100 && this.sw.IsRunning)
{
this.fps = TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
this.FPScount = 0;
this.sw.Reset();
}
}
delegate void videoStream_NewFrameDelegate(object sender, NewFrameEventArgs eventArgs);
public void videoStream_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
if (ready)
{
if (this.InvokeRequired)
{
videoStream_NewFrameDelegate del = new videoStream_NewFrameDelegate(videoStream_NewFrame);
this.Invoke(del, new object[] {sender, eventArgs} );
}
else
{
if(!sw.IsRunning)
sw = Stopwatch.StartNew();
this.FPScount++;
Rectangle rc = ClientRectangle;
Bitmap bmp = new Bitmap(rc.Width, rc.Height);
Graphics g = Graphics.FromImage((Image)bmp);
g.DrawImage(eventArgs.Frame, rc.X+10, rc.Y+10, rc.Width-20, rc.Height-20);
g.Dispose();
this.Image = (Image)bmp;
}
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
{
this.calc = fps.TotalMilliseconds;
if (this.FPScount >= 100 && this.sw.IsRunning)
{
this.fps = TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
this.FPScount = 0;
this.sw.Reset();
}
}
delegate void videoStream_NewFrameDelegate(object sender, NewFrameEventArgs eventArgs);
public void videoStream_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
if (ready)
{
if (this.InvokeRequired)
{
videoStream_NewFrameDelegate del = new videoStream_NewFrameDelegate(videoStream_NewFrame);
this.Invoke(del, new object[] {sender, eventArgs} );
}
else
{
if(!sw.IsRunning)
sw = Stopwatch.StartNew();
this.FPScount++;
Rectangle rc = ClientRectangle;
Bitmap bmp = new Bitmap(rc.Width, rc.Height);
Graphics g = Graphics.FromImage((Image)bmp);
g.DrawImage(eventArgs.Frame, rc.X+10, rc.Y+10, rc.Width-20, rc.Height-20);
g.Dispose();
this.Image = (Image)bmp;
}
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
{
base.OnPaint(pe);
this.calc = fps.TotalMilliseconds;
if (this.FPScount >= 100 && this.sw.IsRunning)
{
this.fps = TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
this.FPScount = 0;
this.sw.Reset();
}
}