Je dessine région ROI rectangulaire en assombrissant la zone à l'extérieur de celui-ci comme dans cette image http://www.codeproject.com/script/Membership/Uploads/4613314/roi.jpgOptimisation de la région du dessin d'intérêt (ROI) dans l'image
Mais image.MakeTransparent
prend trop de temps. Quel est le meilleur moyen d'augmenter la vitesse de dessin?
void DrawRoi(Bitmap Image, RectangleF rect)
{
Rectangle roi = new Rectangle();
roi.X = (int)((float)Image.Width * rect.X);
roi.Y = (int)((float)Image.Height * rect.Y);
roi.Width = (int)((float)Image.Width * rect.Width);
roi.Height = (int)((float)Image.Height * rect.Height);
Stopwatch timer = new Stopwatch();
timer.Start();
// graphics manipulation takes about 240ms on 1080p image
using (Bitmap roiMaskImage = CreateRoiMaskImage(ImageWithRoi.Width, ImageWithRoi.Height, roi))
{
using (Graphics g = Graphics.FromImage(ImageWithRoi))
{
g.DrawImage(Image, 0, 0);
g.DrawImage(roiMaskImage, 0, 0);
Pen borderPen = CreateRoiBorderPen(ImageWithRoi);
g.DrawRectangle(borderPen, roi);
}
}
Debug.WriteLine("roi graphics: {0}ms", timer.ElapsedMilliseconds);
this.imagePictureBox.Image = ImageWithRoi;
}
Bitmap CreateRoiMaskImage(int width, int height, Rectangle roi)
{
Bitmap image = new Bitmap(width, height, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(image))
{
SolidBrush dimBrush = new SolidBrush(Color.FromArgb(64, 0, 0, 0));
g.FillRectangle(dimBrush, 0, 0, width, height);
SolidBrush roiBrush = new SolidBrush(Color.Red);
g.FillRectangle(roiBrush, roi);
image.MakeTransparent(Color.Red);
return image;
}
}
Pen CreateRoiBorderPen(Bitmap image)
{
float width = ((float)(image.Width + image.Height) * 2.5f)/(float)(640 + 480);
if (width < 1.0f)
width = 1.0f;
Pen pen = new Pen(Color.FromArgb(255, 0, 255, 0), width);
return pen;
}
GPU? 1080p semble trop pour le traitement sur le processeur, esp. avec C#. –
non, je voulais dire opération sur les données d'image brutes, même sur 640x480, il faut environ 36ms sur i3 Intel –