Crop portions of an image that do not include Face

I found the Face in the image (only 1 person) and had the coordinates of the Face Rectangle.

enter image description here

Since the image can be of any size, I only need a part of the important image (head.shoulders). What is the intention of expanding the boundaries of the detected rectangle by a factor so that important parts are included. Is it correct?

Update:
I tried this, but did not give the correct result. Note that I changed from 1.7 to 2, as it only accepts integer arguments. And Top and Left are readonly properties.

foreach (Rectangle f in objects)
{
    int x, y;
    x = f.Top - (f.Height / 8);
    y = f.Left - (f.Width / 2);

    Rectangle myrect = new Rectangle(x, y, f.Width * 2, f.Height * 2);

    g.DrawRectangle(Pens.Gray, myrect);
}

Face Rectangle Detected

Top----->62
Right----->470
Left----->217
Bottom----->315

Extended rectangle according to answer

Top----->91
Right----->537
Left----->31
Bottom----->597

Extended rectangle

enter image description here

+4
2

, :


Emgu CV, :
  • Emgu CV , ..

( ):

  1. , :
    . , ( ).

:

. №1 true, , :

Bitmap
  | .Width == 100
  | .Height == 160

Face // type: System.Drawing.Rectangle
  | .Top == 20
  | .Left == 50
  | .Width == 60
  | .Height == 60

, , Rectangle :

f := Face // face rectangle

Face_and_Shoulder
  | .Top = f.Top - (f.Height / 8)
  | .Left = f.Left - (f.Width / 2)
  | .Width = f.Width * 2
  | .Height = f.Height * 1.7

:

Face_and_Shoulder
  | .Top == 12.5
  | .Left == 20
  | .Width == 120
  | .Height == 102

(Face_and_Shoulder) .. .

, , : , ( 5.10 °).


, (, , X Y ):

foreach (Rectangle f in objects)
{
    float x = f.Left - (f.Width / 2f);
    float y = f.Top - (f.Height / 8f);

    Rectangle myrect = new Rectangle((int)x, (int)y, f.Width * 2, (int)(f.Height * 1.3));

    g.DrawRectangle(Pens.Gray, myrect);
}

fig.  No. 1
. №1 (: http://www.idrawdigital.com/wp-content/uploads/2009/01/prop_var.gif)

+1

:

Bitmap source = Image.FromFile("/my/path/to/myimage.png") as Bitmap;

Rectangle facerectangle = /* your face detection logic */;
Bitmap target = new Bitmap(facerectangle.Width, facerectangle.Height);

using (Graphics g = Graphics.FromImage(target))
{
    g.DrawImage(source, new Rectangle(0, 0, target.Width, target.Height),
                facerectangle, GraphicsUnit.Pixel);
}

:)
source, target, , GDI + DrawImage.

0

Source: https://habr.com/ru/post/1621691/


All Articles