gpt4 book ai didi

c# - Emgu CV图像锐化和控制检测

转载 作者:行者123 更新时间:2023-12-02 16:37:33 26 4
gpt4 key购买 nike

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

enter image description here

enter image description here

也可以有几个点。因此,我尝试从网络摄像头中锐化此图像,然后使用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;
}
}

结果图像示例:

enter image description here

因此,几乎所有时间都可以像我期望的那样工作,但是帧率非常低。我得到10-15 fps,分辨率为640x480。我需要能够以至少30 fps的速度执行1920x1080的相同操作。这是我第一次使用OpenCV和Emgu.CV。我该怎么做才能使其表现更好?

最佳答案

我解决了这个问题,只是设置了阈值,因此图像仅变为黑白。通过调整阈值,即使在清晰度方面没有改善,我也能够获得相同的结果,但是由于没有进行繁重的处理,因此性能也得到了显着改善。

这是EmCoreCV上的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();

关于c# - Emgu CV图像锐化和控制检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52554704/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com