在OpenCV C ++中掩盖图像和视频

时间:2018-11-01 19:14:28

标签: c++ opencv image-processing masking roi

我是图像处理的初学者,尤其是在openCV C ++中。我的工作有问题。在带有EmguCV的C#中,可以基于ROI对图像和视频文件进行屏蔽。我的问题是,是否可以在OpenCV C ++中以相同的方式制作遮罩? 。我试图在OpenCV C ++中使用ROI,但是结果仅裁剪图像,而不像我附加的示例Here。我还用EmguCV附加了C#中掩盖的伪代码,但尚未在C ++版本中找到。我期待任何答案。谢谢

pixelSize, out long processingTime)
    {


        int x = imageInput.Width / pixelSize;
        int y = imageInput.Height / pixelSize;

        Mat imageBlock = new Mat();
        Point darkestBlockPoint = new Point();

        int darkestBlockValue = 100000;
        //AppendLogTxt("", "y,x,value", "masking");
        for (int i = marginV; i < y - marginV; i++)
        {
            for (int j = marginH; j < x - marginH; j++)
            {
                imageBlock = new Mat(imageInput, new Rectangle(j * pixelSize, i * pixelSize, pixelSize, pixelSize));
                MCvScalar avg = CvInvoke.Mean(imageBlock);

                //AppendLogTxt("", i.ToString() + "," + j.ToString() + "," + avg.V0.ToString(), "masking");

                if ((int)avg.V0 < darkestBlockValue)
                {
                    darkestBlockValue = (int)avg.V0;
                    darkestBlockPoint.X = j;
                    darkestBlockPoint.Y = i;
                }

            }
        }

        darkestBlockPoint.X = darkestBlockPoint.X * pixelSize + pixelSize / 2;
        darkestBlockPoint.Y = darkestBlockPoint.Y * pixelSize + pixelSize / 2;

        return darkestBlockPoint;
    }

0 个答案:

没有答案