public async Task<Mat> GetMatArea(Mat TargetMat, OpenCvSharp.Point[][] points)
{
int StepVision = 0;
Mat matResult = new Mat();
Mat mask = new Mat(TargetMat.Height, TargetMat.Width, MatType.CV_8UC3, Scalar.Black);
Cv2.FillPoly(mask, points, Scalar.White);
Cv2.BitwiseAnd(TargetMat, mask, matResult);
return matResult;
}
private OpenCvSharp.Point[][] GetMatAreaPoints()
{
OpenCvSharp.Point ptA = new OpenCvSharp.Point(visionModel.PointAX, visionModel.PointAY);
OpenCvSharp.Point ptB = new OpenCvSharp.Point(visionModel.PointBX, visionModel.PointBY);
OpenCvSharp.Point ptC = new OpenCvSharp.Point(visionModel.PointCX, visionModel.PointCY);
OpenCvSharp.Point ptD = new OpenCvSharp.Point(visionModel.PointDX, visionModel.PointDY);
OpenCvSharp.Point ptE = new OpenCvSharp.Point(visionModel.PointEX, visionModel.PointEY);
OpenCvSharp.Point ptF = new OpenCvSharp.Point(visionModel.PointFX, visionModel.PointFY);
OpenCvSharp.Point[][] points = {
new OpenCvSharp.Point[] { ptA, ptB, ptC, ptD, ptE, ptF }
};
return points;
}
用法
OpenCvSharp.Point[][] points = GetMatAreaPoints();
SrcRoiImg = await GetMatArea(SrcImgRGB, points);