简体   繁体   English

我需要修改Sobel内核以进行对角线边缘检测。 OpenCV和C ++

[英]I need to modify a Sobel kernel for diagonal edge detection. OpenCV and C++

I need to apply these two kernels on an image. 我需要在图像上应用这两个内核。

+1 0 0 0 0 0 0 0 -1 +1 0 0 0 0 0 0 0 -1

and 0 0 +1 0 0 0 -1 0 0 和0 0 +1 0 0 0 -1 0 0

And then combine the two output images. 然后合并两个输出图像。 But I have no idea how to write the loops/ apply filters to an image in general. 但我不知道如何编写循环/通常将过滤器应用于图像。

You can use function called filter2d . 您可以使用名为filter2d的函数。 It allows you to apply arbitrary kernel to image, so you don't need to perform any loops yourself. 它允许您将任意内核应用于映像,因此您无需自己执行任何循环。 Just store the kernel you mentioned in Mat and provide it as input to filter2d together with your image. 只需存储您在Mat中提到的内核,并将其作为输入与图像一起提供给filter2d。

Example of use: 使用示例:

float m[9] = {0,0,0,-1,0,1,0,0,0};
Mat kernel(Size(3,3), CV_32F, m);
filter2D(src, dst, -1, kernel);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM