[英]Finding the position of a face using emgucv (c#)
我有我的代码能够检测到一张脸,然后在它找到一张脸的地方放一个盒子,但我想得到它放的盒子的 position。 任何 position 都很好,因为我可以为特定的 position 调整其他代码。
我怎样才能从中得到 position?
非常感谢
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.