【问题标题】:Emgu CV Image sharpening and controur detectionEmgu CV 图像锐化和轮廓检测
【发布时间】:2019-04-28 20:01:09
【问题描述】:

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

也可以有几个点。所以我尝试从网络摄像头锐化这张图像,然后使用 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。我该怎么做才能让它表现得更好?

【问题讨论】:

    标签: c# .net opencv emgucv


    【解决方案1】:

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

    这是一个使用 ARCore 库代替 EmguCV 的 sn-p

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 2016-12-03
      • 2016-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      相关资源
      最近更新 更多