Emgu CV 图像锐化和轮廓检测

Emgu CV Image sharpening and controur detection

我正在做一个项目,我需要从表面上的红外激光识别点。我为此使用带红外滤镜的相机 一些输入图像:

也可以有几个点。所以我尝试从网络摄像头锐化这张图像,然后使用 Emgu CV 的 FindContours 方法。 有我的代码:

public static Image<Gray, byte> Sharpen(Image<Gray, byte> image, int w, int h, double sigma1, double sigma2, int k)
{
    w = (w % 2 == 0) ? w - 1 : w;
    h = (h % 2 == 0) ? h - 1 : h;
    //apply gaussian smoothing using w, h and sigma 
    var gaussianSmooth = image.SmoothGaussian(w, h, sigma1, sigma2);
    //obtain the mask by subtracting the gaussian smoothed image from the original one 
    var mask = image - gaussianSmooth;
    //add a weighted value k to the obtained mask 
    mask *= k;
    //sum with the original image 
    image += mask;
    return image;
}

private void ProcessFrame(object sender, EventArgs arg)
{
    Mat frame = new Mat();
    if (_capture.Retrieve(frame, CameraDevice))
    {
        Image<Bgr, byte> original = frame.ToImage<Bgr, byte>();
        Image<Gray, byte> img = Sharpen(frame.ToImage<Gray, byte>(), 100, 100, 100, 100, 30);
        Image<Gray, byte> thresh = new Image<Gray, byte>(img.Size);
        CvInvoke.PyrDown(img, thresh);
        CvInvoke.PyrUp(thresh, thresh);
        Image<Gray, byte> mask = new Image<Gray, byte>(thresh.Size);
        Image<Gray, byte> cannyImg = thresh.Canny(10, 50);

        VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
        Mat hierarchy = new Mat();
        CvInvoke.FindContours(
            cannyImg,
            contours,
            hierarchy,
            RetrType.External,
            ChainApproxMethod.ChainApproxSimple
            );

        Image<Bgr, byte> resultImage = img.Copy().Convert<Bgr, byte>();

        int contCount = contours.Size;
        for (int i = 0; i < contCount; i++)
        {
            using (VectorOfPoint contour = contours[i])
            {
                resultImage.Draw(CvInvoke.BoundingRectangle(contour), new Bgr(255, 0, 0), 5);
            }
        }

        captureBox.Image = original.Bitmap;
        cvBox.Image = resultImage.Bitmap;
    }
}

结果图片示例:

所以它几乎一直都按我预期的那样工作,但帧率非常低。我得到 640x480 分辨率的 10-15 fps。我需要能够以至少 30 fps 的速度为 1920x1080 做同样的事情。这是我第一次使用 OpenCV 和 Emgu.CV。我该怎么做才能让它表现更好?

我解决了这个只是设置阈值,所以图像只变成黑白。通过调整阈值,即使在清晰度方面不是更好,我也能够获得相同的结果,而且由于没有进行繁重的处理,性能也得到了显着提高

这是 EmguCV 上使用 ARCore 库的片段

var bitmap = eventArgs.Frame;

            var filter = new Grayscale(0.2125, 0.7154, 0.0721);
            var grayImage = filter.Apply(bitmap);
            var thresholdFilter = new Threshold(CurrentThreshold);
            thresholdFilter.ApplyInPlace(grayImage);

            var blobCounter = new BlobCounter();
            blobCounter.ProcessImage(grayImage);
            var rectangles = blobCounter.GetObjectsRectangles();