OpenCV - 创建"拥有" canny过滤器

时间:2014-09-14 15:53:37

标签: opencv filter

我想通过创建内核并将其应用于我的图像来创建我自己的canny过滤器(以进行边缘检测),如下所示:

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;
int main()
{
    Mat img = imread("../Pictures/img.jpg");
    Mat img_cpy = img.clone();
    Mat kern = (Mat_<float>(5,5) << 2,4,5,4,2,
                                    4,9,12,9,4,
                                    5,12,15,12,5,
                                    4,9,12,9,4,
                                    2,4,5,4,2
                ) / 159;
    Point anchor = Point(-1,-1);


    filter2D(img_cpy, img, -1, kern, anchor, 0, BORDER_DEFAULT);  //apply the filter  


    imshow("orig", img_cpy);
    imshow("res", img);
    waitKey(0);

    return 0;

}

问题是我没有得到我想要的结果(黑色背景上带有白边的二进制图像)

我做错了什么/我需要在代码示例中添加什么?

提前多多谢谢你

0 个答案:

没有答案
相关问题