Mat mat = new Mat(@"I:\OpenCvSharp学习\Temp\Test\1.bmp", ImreadModes.AnyColor);
int width = mat.Width;
int heigth = mat.Height;
Point point1 = new Point(width / 2, heigth / 2);
Window window1 = new Window("源图像", WindowMode.Normal, mat);
Cv2.Rectangle(mat,new Rect(20,20,60,40),Scalar.Red);
Window window2 = new Window("处理1", WindowMode.Normal, mat);
Cv2.WaitKey(0);
![image.png](/uploads/projects/xghboy@csharp/ec0aeed56e74ab181a0c38e5a09c46c0.png)
//参数说明:
//重载一:
public static void Rectangle(InputOutputArray img,
Rect rect,
Scalar color,
int thickness = 1,
LineTypes lineType = LineTypes.Link8,
int shift = 0);
//rect:需要绘制的矩形
//举例:
Cv2.Rectangle(mat,new Rect(20,20,60,40),Scalar.Red);
//thickness 为负数时,填充该矩形,默认为-1;
![image.png](/uploads/projects/xghboy@csharp/1cdd28d0f9bc708def61f6d60175e145.png)