我已经获得了能够检测到人脸的代码,然后在找到人脸的地方放了一个盒子,但是我正在寻找它所放盒子的位置。任何位置都将很不错,因为我可以为特定位置调整其他代码。
我如何能够从中获得职位?
非常感谢
private void Device_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
Image<Bgr, byte> grayImage = new Image<Bgr, byte>(bitmap);
Rectangle[] rectangles = cascadeClassifier1.DetectMultiScale(grayImage, 1.2, 1);
foreach (Rectangle rectangle in rectangles)
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
using (Pen pen = new Pen(Color.Red, 1))
{
graphics.DrawRectangle(pen, rectangle);
}
}
}
plc.Image = bitmap;
}
您可以获得矩形的左上角x和y坐标以及宽度和高度。
//Get the top left cord
int rectX = rectangle.X;
int rectY = rectangle.Y;
//Get the width and height of the rectangle
int rectWidth = rectangle.Width;
int rectHeight = rectangle.Height;
使用上面的那些值,您可以找到矩形的其他三个点的线。
//The top right cord
int topRightX = rectX + rectWidth;
int topRightY = rectY;
//The bottom left cord
int bottomX = rectX;
int bottomY = rectY + rectHeight;
//The bottom right cord
int bottomRightX = rectX + rectWidth;
int bottomRightY = rectY + rectHeight;