OpenCV截取多边形区域图像

        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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值